/** * Generates a new token for the specified user * * @param Sprig User * @return Sprig User_Token */ public function new_token(Sprig $user, $expires = NULL) { if ($user->loaded()) { // Create a new token $token = Sprig::factory($this->token_model()); $expires = isset($expires) ? $expires : time() + $this->_config['lifetime']; // Set token data $token->user = $user->id; $token->expires = $expires; $token->create(); return $token; } }