Пример #1
0
 protected function createSocialService()
 {
     if ($this->scenario == 'social') {
         $service = new \UserSocialService();
         $service->service = $this->service;
         $service->service_id = $this->service_id;
         $service->user_id = $this->user->id;
         if (!$service->save()) {
             $this->addErrors(array('ServiceSavingFailed'));
         }
     }
 }
Пример #2
0
 public static function addSocialServicesToUser(&$user)
 {
     $services = \UserSocialService::model()->findAllByAttributes(array('user_id' => $user['id']));
     $user['social_services'] = array();
     if ($services) {
         foreach ($services as $service) {
             Formatter::formatCommon($service);
             $user['social_services'][] = $service->getAttributes();
         }
     }
 }
Пример #3
0
 /**
  * @param SocialServiceForm $service
  * @param \site\frontend\modules\api\modules\v2_1\components\social\SocialResult $result
  * @param \User $user
  * @throws ApiException
  */
 private function createSocialService($service, $result, $user)
 {
     $service->service_id = $result->getUserId();
     $service->setResult($result);
     if (\UserSocialService::model()->findByAttributes(array('service' => $service->service, 'service_id' => $service->service_id, 'user_id' => $user->id))) {
         $this->controller->toAuthArray($user);
         return;
     }
     if ($service->save()) {
         $this->controller->toAuthArray($user);
     } else {
         throw new ApiException($service->getErrors(), 500);
     }
 }
Пример #4
0
 public function rules()
 {
     return array(array('service, service_id, user_id', 'required'), array('user_id', 'exist', 'attributeName' => 'id', 'className' => get_class(\User::model())), array('service', 'unique', 'className' => get_class(\UserSocialService::model()), 'caseSensitive' => false, 'criteria' => array('condition' => 'service_id = :service_id', 'params' => array(':service_id' => $this->service_id))), array('service_id', 'unique', 'className' => get_class(\UserSocialService::model()), 'caseSensitive' => false, 'criteria' => array('condition' => 'user_id = :user_id', 'params' => array(':user_id' => $this->user_id))));
 }
Пример #5
0
 /**
  * Creates record based on social access token.
  * Make one time token validation for it.
  * Using now for refresh to.
  *
  * @param $token
  * @param $service
  * @param int $appId
  *
  * @return UserSocialToken
  */
 public function create($token, $service, $appId)
 {
     $model = new self();
     $model->service = $service;
     if ($this->makeValidationRequest($token, $model)) {
         $model->access_token = $token;
         $model->app_id = $appId;
         ApiLog::i("Service Id: {$model->service_user_id}, Service: {$model->service}");
         $userSocialService = \UserSocialService::model()->findByAttributes(array('service_id' => $model->service_user_id, 'service' => $model->service));
         if ($userSocialService != null) {
             $model->user_id = $userSocialService->user_id;
             $model->save();
             return $model;
         } else {
             $model->error = 'Unregistered';
         }
     }
     return $model;
 }