예제 #1
0
파일: Signup.php 프로젝트: aversilov/prexr
 public function signup($post_data)
 {
     $user = new Users();
     $user->username = $post_data['username'];
     $user->username_rus = $post_data['runame'];
     $user->pasport_code = (int) $post_data['passport_code'];
     $user->ref_id = $post_data['user_ref_id'];
     $user->password = Yii::$app->getSecurity()->generatePasswordHash($post_data['password']);
     $user->social_role = 'N';
     $user->ip = $_SERVER['REMOTE_ADDR'];
     $this->photo = UploadedFile::getInstanceByName('userfile');
     if ($this->photo) {
         $user->avatar = $this->photo->baseName . '.' . $this->photo->extension;
     }
     if ($user->save()) {
         if ($this->photo) {
             mkdir('./images/users_photo/' . $user->id . '/avatar/', 0777, true);
             //            chmod('./images/users_photo/' . $user->id, 0777);
             //            chmod('./images/users_photo/' . $user->id . '/avatar/', 0777);
             $this->photo->saveAs('images/users_photo/' . $user->id . '/avatar/' . $this->photo->baseName . '.' . $this->photo->extension);
         }
         if (Yii::$app->session->has('guest')) {
             $guest = Yii::$app->session->get('guest');
             UsersParameters::syncFromGuestsParameters($user->id, $guest->id);
             UsersStats::syncFromGuestsStats($user->id, $guest->id);
             Yii::$app->session->remove('guest');
         }
         Yii::$app->user->login($user, 3600 * 24 * 30);
         return true;
     } else {
         return false;
     }
 }
예제 #2
0
 /**
  * Синхронизация параметров гостя из параметров юзера. Происходит при логауте пользователя 
  * @param int $user_id
  * @param int $guest_id
  * @return bool true if save was successfull
  */
 public static function syncFromUsersParameters($user_id, $guest_id)
 {
     $users_parameters_obj = UsersParameters::findOne($user_id);
     if (!$users_parameters_obj) {
         return false;
     }
     $guest_parameters_obj = self::findOne($guest_id);
     if (!$guest_parameters_obj) {
         $guest_parameters_obj = new self();
         $guest_parameters_obj->guest_id = $guest_id;
     }
     $attrs = $guest_parameters_obj->attributes();
     foreach ($attrs as $attr) {
         if ($attr == 'guest_id') {
             continue;
         }
         $guest_parameters_obj->{$attr} = $users_parameters_obj->{$attr};
     }
     return $guest_parameters_obj->save();
 }