public function init()
 {
     parent::init();
     if (is_null($this->model)) {
         throw new Exception("model darf nicht null sein");
     }
     $this->logs = $this->loadLogs();
     $this->type = is_null($this->type) ? self::VIEW_DEFAULT : $this->type;
     switch ($this->type) {
         case self::VIEW_NEW:
             $this->haveSeen = LogEntry::findOne(['model_id' => $this->model->id, 'model_type' => $this->model->className(), 'created_by' => User::getCurrentUser()->id, 'action' => 'view']);
             break;
         case self::VIEW_COUNT_SEEN:
             $model = $this->model;
             $modelClass = $model->className();
             if (!class_exists($modelClass)) {
                 throw new Exception("Klasse konnte nicht gefunden werden!");
             }
             $this->countSeen = $modelClass::find(['id' => $model->id])->count() - LogEntry::find(['model_id' => $model->id, 'model_type' => $model->className(), 'created_by' => User::getCurrentUser()->id, 'action' => 'view'])->count();
             break;
         case self::VIEW_DEFAULT:
             $this->behavior = $this->model->behaviors['LoggableBehavior'];
             break;
     }
 }
예제 #2
0
 /**
  * @return string|\yii\web\Response
  */
 public function actionConfirmEmail()
 {
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $user = User::getCurrentUser();
     if ($user->email_confirmed == 1) {
         return $this->renderIsAjax('confirmEmailSuccess', compact('user'));
     }
     $model = new ConfirmEmailForm(['email' => $user->email, 'user' => $user]);
     if (Yii::$app->request->isAjax and $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) and $model->validate()) {
         if ($this->triggerModuleEvent(UserAuthEvent::BEFORE_EMAIL_CONFIRMATION_REQUEST, ['model' => $model])) {
             if ($model->sendEmail(false)) {
                 if ($this->triggerModuleEvent(UserAuthEvent::AFTER_EMAIL_CONFIRMATION_REQUEST, ['model' => $model])) {
                     return $this->refresh();
                 }
             } else {
                 Yii::$app->session->setFlash('error', UserManagementModule::t('front', "Unable to send message for email provided"));
             }
         }
     }
     return $this->renderIsAjax('confirmEmail', compact('model'));
 }