/** * Create an API key for a user in a particular scope * @return \CMF\Model\User\Apikey */ public function getKey($user, $type, $scope) { $key = new \Model_User_Apikey(); $key->populate(array('user_id' => $user->id, 'user_type' => $type, 'expires_at' => new \DateTime('@' . (strtotime('now') + 25 * 60 * 60)), 'access_token' => \CMF\Auth::forge()->generate_token(), 'scope' => $scope)); \D::manager()->persist($key); \D::manager()->flush(); return $key; }
/** * Generates a new random token for unlocking, and stores the time * this token is being generated. * * @return bool */ public function generate_unlock_token() { if ($this->unlock_token === null) { $this->unlock_token = Auth::forge()->generate_token(); } return true; }