/**
  * Check that there is no such confirmed E-mail in the system
  */
 public function validateEmailConfirmedUnique()
 {
     if ($this->email) {
         $exists = User::findOne(['email' => $this->email, 'email_confirmed' => 1]);
         if ($exists) {
             $this->addError('email', UserManagementModule::t('front', 'This E-mail already exists'));
         }
     }
 }
 /**
  * @param int $id User ID
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionChangePassword($id)
 {
     $model = User::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException('User not found');
     }
     $model->scenario = 'changePassword';
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->renderIsAjax('changePassword', compact('model'));
 }
 /**
  * @param int $id User ID
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionSet($id)
 {
     $user = User::findOne($id);
     if (!$user) {
         throw new NotFoundHttpException('User not found');
     }
     $permissionsByGroup = [];
     $permissions = Permission::find()->andWhere([Yii::$app->getModule('user-management')->auth_item_table . '.name' => array_keys(Permission::getUserPermissions($user->id))])->joinWith('group')->all();
     foreach ($permissions as $permission) {
         $permissionsByGroup[@$permission->group->name][] = $permission;
     }
     return $this->renderIsAjax('set', compact('user', 'permissionsByGroup'));
 }
 /**
  * @return bool
  */
 public function validateEmailConfirmedAndUserActive()
 {
     if (!Yii::$app->getModule('user-management')->checkAttempts()) {
         $this->addError('email', UserManagementModule::t('front', 'Too many attempts'));
         return false;
     }
     $user = User::findOne(['email' => $this->email, 'email_confirmed' => 1, 'status' => User::STATUS_ACTIVE]);
     if ($user) {
         $this->user = $user;
     } else {
         $this->addError('email', UserManagementModule::t('front', 'E-mail is invalid'));
     }
 }
 /**
  * Creates a default header view of an log entry
  *
  * @param $logModel
  *      the log entry
  * @param $behavior
  *      the LoggableBehavior instance of this log entry
  * @return string
  *      default header view of an log entry
  * @throws Exception
  *      if a param is null
  */
 public static function createLogEntryHeader($behavior, $logModel)
 {
     if (!is_null($behavior) && !is_null($logModel)) {
         $user = User::findOne(["id" => $logModel->created_by]);
         $action = $logModel->action;
         $date = $logModel->created_at;
         $action = $behavior->getActionType($action);
         $output = self::$icons[$action];
         switch ($action) {
             case self::ACTION_CREATE:
                 $output .= ' Erstellt';
                 break;
             case self::ACTION_UPDATE:
                 $output .= ' Bearbeitet';
                 break;
             case self::ACTION_VIEW:
                 $output .= ' Angesehen';
                 break;
             case self::ACTION_DELETE:
                 $output .= ' Gelöscht';
                 break;
         }
         $output .= ' von <b>' . $user->username . '</b><div class="pull-right">' . date('d.m.y, H:i', $date) . '</div>';
         return $output;
     }
     throw new Exception('Params are null!');
 }
 protected function changeRoleAction($model)
 {
     if (!($user = User::findOne(['username' => $model->profile_id]))) {
         return;
     }
     switch ($model->role) {
         case 'admin':
             User::assignRole($user->id, 'unicredQuestionListSystemAdmin');
             User::revokeRole($user->id, 'unicredQuestionListSystemCommercialDirector');
             User::revokeRole($user->id, 'unicredQuestionListSystemManager');
             break;
         case 'manager':
             User::assignRole($user->id, 'unicredQuestionListSystemManager');
             User::revokeRole($user->id, 'unicredQuestionListSystemCommercialDirector');
             User::revokeRole($user->id, 'unicredQuestionListSystemAdmin');
             break;
         case 'empl':
             User::assignRole($user->id, 'unicredQuestionListSystemManager');
             User::revokeRole($user->id, 'unicredQuestionListSystemCommercialDirector');
             User::revokeRole($user->id, 'unicredQuestionListSystemAdmin');
             break;
         case 'comdir':
             User::assignRole($user->id, 'unicredQuestionListSystemCommercialDirector');
             User::revokeRole($user->id, 'unicredQuestionListSystemManager');
             User::revokeRole($user->id, 'unicredQuestionListSystemAdmin');
             break;
     }
 }