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); }
public function behaviors() { return [Journal::className()]; }
* @link http://zenothing.com/ */ use app\behaviors\Journal; $config['components']['user'] = ['identityClass' => 'app\\models\\User', 'enableAutoLogin' => true, 'loginUrl' => ['user/login'], 'on afterLogin' => function ($event) { /* @var $user \app\models\User */ $user = Yii::$app->user->identity; $event->name = 'login'; $event->sender = $user; Journal::writeEvent($event); if ($user->timezone) { $_SESSION['timezone'] = $user->timezone; } }, 'on beforeLogout' => function ($event) { $event->name = 'logout'; $event->sender = Yii::$app->user->identity; Journal::writeEvent($event); }]; $config['components']['errorHandler'] = ['errorAction' => 'home/error']; $config['components']['formatter'] = ['class' => 'yii\\i18n\\Formatter', 'dateFormat' => 'php:d-m-Y', 'datetimeFormat' => 'php:d-m-Y H:i', 'timeFormat' => 'php:H:i:s']; $config['modules']['lang'] = 'app\\modules\\lang\\Module'; $config['modules']['invoice'] = 'app\\modules\\invoice\\Module'; $config['modules']['pyramid'] = 'app\\modules\\pyramid\\Module'; $config['modules']['feedback'] = 'app\\modules\\feedback\\Module'; $config['modules']['internal'] = 'app\\modules\\internal\\Module'; $config['modules']['faq'] = 'app\\modules\\faq\\Module'; $config['modules']['article'] = 'app\\modules\\article\\Module'; $config['bootstrap'][] = 'lang'; $config['bootstrap'][] = 'invoice'; $config['bootstrap'][] = 'pyramid'; $config['bootstrap'][] = 'feedback'; $config['bootstrap'][] = 'faq';
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]); }
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]); }