Ejemplo n.º 1
0
 public function __construct($type, $object_id, $event, $message = null, $previous = null)
 {
     parent::__construct($message, static::getHttpCode($event), $previous);
     $this->type = $type;
     $this->object_id = $object_id;
     $this->event = $event;
     Journal::write($type, $event, $object_id, $message);
 }
Ejemplo n.º 2
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->post())) {
         $user = $model->getUser();
         if ($user) {
             $can = $user->canLogin();
             if ($can && $user->validatePassword($model->password)) {
                 if ($user->status > 0) {
                     Yii::$app->user->login($user);
                     return $this->redirect(['view', 'name' => $user->name]);
                 } else {
                     Yii::$app->session->setFlash('error', Yii::t('app', 'Ваш аккаунт заблокирован'));
                 }
             } else {
                 Journal::write('user', 'login_fail', $user->id);
                 if ($can) {
                     Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
                 } else {
                     $record = Record::find()->where(['object_id' => $user->id, 'event' => 'login_fail'])->orderBy(['time' => SORT_DESC])->one();
                     Yii::$app->session->setFlash('error', "Вы превысили максимальное количество попыток входа, вы сможете войти после {$record->time}");
                 }
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
         }
     }
     return $this->render('login', ['model' => $model]);
 }
Ejemplo n.º 3
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->post())) {
         $user = $model->getUser();
         if ($user) {
             if (empty($user->hash)) {
                 Yii::$app->session->setFlash('error', Yii::t('app', Yii::t('app', 'Your account is not activated. Check your email')));
             } else {
                 $can = $user->canLogin();
                 if ($can && $user->validatePassword($model->password)) {
                     if ($user->status > 0) {
                         if (empty($user->auth)) {
                             $user->generateAuthKey();
                             $user->save();
                         }
                         if (Yii::$app->user->login($user, $model->remember ? $user->duration * 60 : 0)) {
                             $bundle = $user->getBundle();
                             if ($bundle && isset($bundle['node_id'])) {
                                 $node_id = (int) $bundle['node_id'];
                                 $user->setBundle(null);
                                 $user->save();
                                 if (Node::find()->where(['id' => $node_id])->count() > 0) {
                                     Yii::$app->session->addFlash('success', Yii::t('app', 'Congratulation! You receive a gift'));
                                     return $this->redirect(['/pyramid/node/index', 'id' => $node_id]);
                                 }
                             }
                             return $this->redirect(['view']);
                             //                                return $this->actionView($user->name);
                         } else {
                             Yii::$app->session->addFlash('error', Yii::t('app', 'Something wrong happened'));
                         }
                     } else {
                         Yii::$app->session->setFlash('error', Yii::t('app', Yii::t('app', 'Your account is blocked')));
                     }
                 } else {
                     Journal::write('user', 'login_fail', $user->id);
                     if ($can) {
                         Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
                     } else {
                         $record = Record::find()->where(['object_id' => $user->id, 'event' => 'login_fail'])->orderBy(['time' => SORT_DESC])->one();
                         Yii::$app->session->setFlash('error', Yii::t('app', 'You have exceeded the maximum number of login attempts, you will be able to enter after {time}', ['time' => $record->time]));
                     }
                 }
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
         }
     }
     return $this->render('login', ['model' => $model]);
 }