/**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->status = User::STATUS_NOTACTIVATED;
         $b = $user->save();
         $activationToken = new UserTokens();
         $activationToken->user_id = $user->id;
         $activationToken->token_type = ETokenType::ACCOUNT_ACTIVATION;
         $activationToken->token = sha1(mt_rand(10000, 99999) . time() . $user->email);
         $activationToken->save();
         $auth = Yii::$app->authManager;
         $userRole = $auth->getRole('user');
         $auth->assign($userRole, $user->id);
         if ($b) {
             $x = new UserInfo();
             $x->user_id = $user->id;
             $x->save();
             EventService::createEvent(EEvent::ACCOUNT_CREATE(), new UserId($user->id));
             $this->sendActivationMail($user, $activationToken->token);
             return $user;
         }
     }
     return null;
 }
Example #2
0
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert === true) {
         (new History(['user_id' => $this->topic->user_id, 'action' => History::ACTION_ADD_TOPIC, 'action_time' => $this->topic->created_at, 'target' => $this->topic_id]))->save(false);
         Siteinfo::updateCounterInfo('addTopic');
         UserInfo::updateCounterInfo('addTopic', $this->topic->user_id);
         Node::updateCounterInfo('addTopic', $this->topic->node_id);
         Notice::afterTopicInsert($this);
         Tag::afterTopicInsert($this);
     }
     return parent::afterSave($insert, $changedAttributes);
 }
Example #3
0
 /**
  * Logs in a user using the provided username and password.
  *
  * @return boolean whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         if ($status = Yii::$app->getUser()->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 7 : 0)) {
             $userIP = sprintf("%u", ip2long(Yii::$app->getRequest()->getUserIP()));
             UserInfo::updateAll(['last_login_at' => time(), 'last_login_ip' => $userIP], ['user_id' => $this->getUser()->id]);
             (new History(['user_id' => $this->getUser()->id, 'action' => History::ACTION_LOGIN, 'target' => $userIP]))->save(false);
         }
         return $status;
     } else {
         return false;
     }
 }
Example #4
0
 public function storeUserRegister(Request $request)
 {
     DB::beginTransaction();
     try {
         $inputs = $request->all();
         if ($request->hasFile('photo')) {
             $photoFile = $request->file('photo');
             $inputs['photo'] = $this->__storeImageUser($photoFile);
         } else {
             unset($inputs['photo']);
         }
         $role = Role::where('slug', 'user')->first();
         $inputs['role_id'] = $role->id;
         $inputs['register_token'] = str_random(30);
         $inputs['password'] = bcrypt($inputs['password']);
         $user = User::create($inputs);
         $inputs['user_id'] = $user->id;
         UserInfo::create($inputs);
     } catch (Exception $e) {
         DB::rollback();
     }
     DB::commit();
     return $user;
 }
Example #5
0
 public function afterDelete()
 {
     (new History(['user_id' => $this->user_id, 'action' => History::ACTION_DELETE_TOPIC, 'target' => $this->id]))->save(false);
     TopicContent::deleteAll(['topic_id' => $this->id]);
     Node::updateCounterInfo('deleteTopic', $this->node_id);
     UserInfo::updateCounterInfo('deleteTopic', $this->user_id);
     $count = Comment::afterTopicDelete($this->id);
     Siteinfo::updateCountersInfo(['topics' => -1, 'comments' => -$count]);
     Favorite::afterTopicDelete($this->id);
     Notice::afterTopicDelete($this->id);
     return parent::afterDelete();
 }
Example #6
0
 public static function afterTopicDelete($topic_id)
 {
     $limit = 100;
     $offset = 0;
     while (1) {
         $comments = static::find()->select(['user_id'])->where(['topic_id' => $topic_id])->orderBy(['position' => SORT_ASC])->limit($limit)->offset($offset)->asArray()->all();
         if (empty($comments)) {
             break;
         }
         $uids = ArrayHelper::getColumn($comments, 'user_id');
         unset($comments);
         sort($uids);
         $uidCount = array_count_values($uids);
         unset($uids);
         $result = [];
         foreach ($uidCount as $key => $value) {
             $result[$value][] = $key;
         }
         foreach ($result as $key => $value) {
             UserInfo::updateAllCounters(['comment_count' => -$key], ['user_id' => $value]);
         }
         unset($result);
         $offset = $offset + 100;
     }
     return static::deleteAll(['topic_id' => $topic_id]);
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserInfos()
 {
     return $this->hasMany(UserInfo::className(), ['account_id' => 'id']);
 }
Example #8
0
 public function getUserInfo()
 {
     return $this->hasOne(UserInfo::className(), ['user_id' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserInfos()
 {
     return $this->hasMany(UserInfo::className(), ['short_url_id' => 'id']);
 }
 /**
  * @param IntouchUser $user
  *
  * @return bool
  */
 public static function saveUser(IntouchUser $user)
 {
     $id = $user->getId();
     $u = User::findIdentity($id);
     /* @var $u User */
     $u->email = $user->getEmail();
     $u->username = $user->getUsername();
     if (!$u->save()) {
         return false;
     }
     $uinfo = UserInfo::findOne($id);
     /* @var $uinfo UserInfo */
     $uinfo->user_about = $user->getAbout();
     $uinfo->user_birthdate = $user->getBirthDate();
     $uinfo->user_city = $user->getCity();
     $uinfo->user_education = $user->getEducation();
     $uinfo->user_name = $user->getName();
     $uinfo->user_surname = $user->getSurname();
     if (!$uinfo->save()) {
         return false;
     }
     return true;
 }
Example #11
0
 public static function afterTopicDelete($topic_id)
 {
     $limit = 100;
     $offset = 0;
     while (1) {
         $models = static::find()->select(['source_id'])->where(['type' => self::TYPE_TOPIC, 'target_id' => $topic_id])->orderBy(['id' => SORT_ASC])->limit($limit)->offset($offset)->asArray()->all();
         if (empty($models)) {
             break;
         }
         $uids = ArrayHelper::getColumn($models, 'source_id');
         sort($uids);
         UserInfo::updateAllCounters(['favorite_topic_count' => -1], ['user_id' => $uids]);
         $offset = $offset + 100;
     }
     return static::deleteAll(['type' => self::TYPE_TOPIC, 'target_id' => $topic_id]);
 }