/**
  * Validates the password.
  * This method serves as the inline validation for password.
  *
  * @param string $attribute the attribute currently being validated
  * @param array $params the additional name-value pairs given in the rule
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $user = $this->getUser();
         if (!$user || empty($user->password_hash) || !$user->validatePassword($this->password)) {
             $this->addError($attribute, 'Incorrect username or password.');
         } elseif ($user->status == INACTIVE) {
             $this->addError($attribute, 'This user is blocked.');
         } elseif ($user->email_verified != VERIFIED) {
             $userRole = \vendor\codefire\cfusermgmt\views\helpers\Helper::findUserRole($user->id);
             if (!in_array($userRole, array(SUPERADMIN_ROLE_ALIAS, ADMIN_ROLE_ALIAS))) {
                 $this->addError($attribute, "Email is not verified yet. Please verify firstly");
             }
         }
     }
 }
 public function actionApprove($id = NULL)
 {
     $model = User::findOne($id);
     if (isset($model) && !empty($model)) {
         $model->approved = $model->approved == ACTIVE ? INACTIVE : ACTIVE;
         $result = $model->approved == ACTIVE ? 'approved' : 'disapproved';
         $model->scenario = 'approve';
         if ($model->update()) {
             /*                 * * SMS/MAIL EVENTS starts here *** */
             $eventDetail['role'] = ucwords(Helper::findUserRole($model->id));
             $eventDetail['receiver_id'] = $model->id;
             $eventDetail['receiver_email'] = $model->email;
             \frontend\models\Event::addEvent(EVENT_MAIL_TYPE, EVENT_ACCOUNT_APPROVAL, $eventDetail);
             /*                 * * SMS/MAIL EVENTS ends here *** */
             $message = str_replace('%OPERATION%', $result, FLASH_1034);
             Yii::$app->session->setFlash("success", $message, true);
         } else {
             $message = str_replace('%OPERATION%', $result, FLASH_1035);
             Yii::$app->session->setFlash("danger", $message, true);
         }
         return $this->redirect(Url::toRoute(['/usermgmt/user/'], true));
     }
 }