Ejemplo n.º 1
0
 /**
  * Создание пользователя из соцсети
  */
 public static function createAuthUser($attributes)
 {
     $user = new User();
     $auth = new UserAuth();
     $user->attributes = $attributes;
     $auth->attributes = $attributes;
     $user->setAttributes(array('created' => date('Y-m-d H:i:s'), 'changed' => date('Y-m-d H:i:s'), 'last_visit' => time(), 'registration_ip' => Yii::app()->request->userHostAddress, 'status' => self::STATUS_ACTIVE, 'is_social_user' => self::SOCIAL_USER_YES));
     $auth->setAttributes(array('created' => date('Y-m-d H:i:s'), 'changed' => date('Y-m-d H:i:s')));
     if ($attributes['photo']) {
         $photo = new Photo();
         $photo->filename = String::randomString(12);
         $user->avatar = $photo->uploadImage($attributes['photo'], param('images/user'));
         $auth->service_user_pic = $attributes['photo'];
     }
     $user->auth = $auth;
     if ($user->withRelated->save(false, array('auth'))) {
         return $user;
     } else {
         throw new Exception('Пользователь не создался ... ');
     }
 }