Пример #1
0
 /**
  * Validates user's password
  *
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     $this->user = null;
     if (!$this->hasErrors()) {
         $this->user = User::findByUsername($this->email);
         if (!$this->user instanceof User) {
             // user not found
             $this->addError($attribute, Yii::t('user', 'Wrong user name or password'));
             return;
         }
         /* @var $api UserModule */
         $api = Yii::$app->getModule('user');
         if (!$api->checkUserPassword($this->user, $this->{$attribute})) {
             $this->addError($attribute, Yii::t('user', 'Wrong user name or password'));
             return;
         }
         // switch user status
         if (!$this->user->canSignIn()) {
             switch ($this->user->status) {
                 case User::STATUS_BLOCKED:
                     $this->addError($attribute, Yii::t('user', 'An account is blocked'));
                     break;
                 default:
                     $this->addError($attribute, Yii::t('user', 'An account is unactive'));
                     break;
             }
         }
     }
 }
Пример #2
0
 /**
  * @param Post $post
  * @return boolean
  */
 public function mentionHandler($post)
 {
     $usernames = MentionHelper::find($post->message);
     if (!empty($usernames)) {
         foreach ($usernames as $username) {
             /** @var User $mentioned */
             $mentioned = User::findByUsername($username);
             if (!$mentioned instanceof User) {
                 continue;
             }
             $exist = UserMention::find()->where(['post_id' => $post->id, 'mention_user_id' => $mentioned->id, 'status' => UserMention::MENTION_SATUS_UNVIEWED])->exists();
             if ($exist) {
                 continue;
             }
             $currentUser = Yii::$app->getUser()->getIdentity();
             $model = new UserMention();
             $model->user_id = $currentUser->id;
             $model->mention_user_id = $mentioned->id;
             $model->post_id = $post->id;
             $model->topic_id = $post->topic->id;
             $model->status = UserMention::MENTION_SATUS_UNVIEWED;
             if ($mentioned->notify_mention_web == 1) {
                 $model->save();
             }
             if ($mentioned->notify_mention_email == 1) {
                 \Yii::$app->mailer->compose(['text' => 'mention'], ['model' => $model, 'topic' => $post->topic])->setFrom([Yii::$app->config->get('support_email') => Yii::$app->config->get('site_title')])->setTo([$model->mentionUser->email => $model->mentionUser->username])->setSubject('#' . $post->id . ' ' . $post->topic->subject)->send();
             }
         }
         return true;
     }
     return false;
 }
Пример #3
0
 protected function inlineUserMention($Excerpt)
 {
     if (preg_match('/\\B@([a-zA-Z][\\w-]+)/', $Excerpt['context'], $matches)) {
         /** @var User $user */
         $user = User::findByUsername($matches[1]);
         if ($user) {
             return ['extent' => strlen($matches[0]), 'element' => ['name' => 'a', 'text' => $matches[0], 'attributes' => ['href' => '/user/' . $user->id, 'class' => 'user-mention']]];
         } else {
             return ['markup' => $matches[0], 'extent' => strlen($matches[0])];
         }
     }
 }