Feature Request #4290

Automatically creating tokens only when a token isn't set

Added by Gabe Evans over 2 years ago. Updated over 2 years ago.

Status:NewStart date:09/30/2011
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Modules:ORM
Target version:-
Resolution: Points:1

Description

It would be great if token generation was optional. I recently began working on a Facebook application and wanted to store each user's access token in the same table and access them later through the user token model. The create() method currently overwrites the token column regardless of whether it has already been set. I ended up coding around it by changing:

public function create(Validation $validation = NULL)
{
    $this->token = $this->create_token();

    return parent::create($validation);
}

To:

public function create(Validation $validation = NULL)
{
    if ($this->token === NULL OR ORM::factory('user_token', array('token' => $token))->loaded())
    {
        $this->token = $this->create_token();
    }

    return parent::create($validation);
}

This way, a token is only generated when the one set is NULL or already exists. I found it to be a useful functionality that would allow for more flexibility. Any thoughts?

History

Also available in: Atom PDF