示例#1
0
 /**
  * @param $equalAuth
  * @return Row
  * @throws Exception
  * @throws \Bluz\Db\Exception\DbException
  */
 public function generateToken($equalAuth)
 {
     // clear previous generated Auth record
     // works with change password
     $this->delete(['userId' => $equalAuth->userId, 'foreignKey' => $equalAuth->foreignKey, 'provider' => self::PROVIDER_TOKEN, 'tokenType' => self::TYPE_ACCESS]);
     // new auth row
     $row = new Row();
     $row->userId = $equalAuth->userId;
     $row->foreignKey = $equalAuth->foreignKey;
     $row->provider = self::PROVIDER_TOKEN;
     $row->tokenType = self::TYPE_ACCESS;
     $row->expired = gmdate('Y-m-d H:i:s', time() + self::TOKEN_EXPIRATION_TIME);
     // generate secret
     $row->tokenSecret = $this->generateSecret($equalAuth->userId);
     // encrypt password and save as token
     $row->token = $this->callHashFunction($equalAuth->token);
     $row->save();
     return $row;
 }
示例#2
0
 /**
  * @param \Hybrid_User_Profile $data
  * @param  \Application\Users\Row $user
  * @return void
  */
 public function registration($data, $user)
 {
     $row = new Auth\Row();
     $row->userId = $user->id;
     $row->provider = strtolower($this->providerName);
     $row->foreignKey = $data->identifier;
     $row->token = $this->authAdapter->getAccessToken()['access_token'];
     $row->tokenSecret = $this->authAdapter->getAccessToken()['access_token_secret'] ?: '';
     $row->tokenType = Auth\Table::TYPE_ACCESS;
     $row->save();
     Messages::addNotice(sprintf('Your account was linked to %s successfully !', $this->providerName));
     $this->response->redirectTo('users', 'profile', ['id' => $user->id]);
 }