Пример #1
0
 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 boolean true if save was successfull
  */
 public static function syncFromUsersStats($user_id, $guest_id)
 {
     $users_stats_obj = UsersStats::findOne($user_id);
     if (!$users_stats_obj) {
         return false;
     }
     $guests_stats_obj = self::findOne($guest_id);
     if (!$guests_stats_obj) {
         $guests_stats_obj = new self();
         $guests_stats_obj->guest_id = $guest_id;
     }
     $attrs = $guests_stats_obj->attributes();
     foreach ($attrs as $attr) {
         if ($attr == 'guest_id') {
             continue;
         }
         $guests_stats_obj->{$attr} = $users_stats_obj->{$attr};
     }
     return $guests_stats_obj->save();
 }