Exemple #1
0
 public function authorizeUser($vkAuthData)
 {
     $vkUser = \Rm\models\User::model()->find('foreign_id = :vkId AND auth_provider_id = :authProviderId', array(':vkId' => $vkAuthData['user_id'], ':authProviderId' => static::getAuthProviderId()));
     if (!$vkUser) {
         $transaction = \Rm\models\User::model()->getDbConnection()->beginTransaction();
         try {
             // need to get base user info
             $details = self::getUserDetails($vkAuthData['user_id']);
             $user = new \Rm\models\User();
             $user->setAttributes(array('foreign_id' => $details['uid'], 'auth_provider_id' => static::getAuthProviderId(), 'username' => "{$details['first_name']} {$details['last_name']}", 'photo' => $details['photo']));
             $user->save();
             $transaction->commit();
             $commonDetails = self::filterDetails($details);
             \Rm\components\AuthUser::authorize($user->id, $commonDetails);
         } catch (Exception $e) {
             $transaction->rollback();
             throw $e;
         }
     } else {
         //$vkUser->token_expires = time() + $vkAuthData['expires_in'];
         //$vkUser->save();
         \Rm\components\AuthUser::authorize($vkUser->id, $vkUser->getAttributes());
     }
 }
Exemple #2
0
 public function authorizeUser($vkAuthData, \Rm\authPlugin\AbstractClass $authProvider)
 {
     $user = \Rm\models\User::model()->find('foreign_id = :vkId AND auth_provider_id = :authProviderId', array(':vkId' => $vkAuthData['user_id'], ':authProviderId' => static::getAuthProviderId()));
     if (!$user) {
         // need to get base user info
         $details = $authProvider->getUserDetails($vkAuthData['user_id']);
         $user = new \Rm\models\User();
         $user->setAttributes(array('foreign_id' => $details['user_id'], 'auth_provider_id' => $authProvider->getAuthProviderId(), 'username' => "{$details['username']}", 'photo' => $details['photo']));
         $user->save();
         $commonDetails = self::filterDetails($details);
         \Rm\components\AuthUser::authorize($user->id, $commonDetails);
     } else {
         $user->token_expires = time() + $vkAuthData['expires_in'];
         $user->save();
         $commonDetails = self::filterDetails(unserialize($user->user_data));
         \Rm\components\AuthUser::authorize($user->user->id, $commonDetails);
     }
 }