/** * Registers a new user account. If registration was successful it will set flash message. * * @return bool */ public function register() { if (!$this->validate()) { return false; } /** @var User $user */ $user = Yii::createObject(User::className()); $user->setScenario('register'); $this->loadAttributes($user); if (!$user->register()) { return false; } UserLog::log("register", '', $user); Yii::$app->session->setFlash('info', Yii::t('user', 'Your account has been created and a message with further instructions has been sent to your email')); return true; }
/** * Logs the user out and then redirects to the homepage. * * @return Response */ public function actionLogout() { $event = $this->getUserEvent(Yii::$app->user->identity); $this->trigger(self::EVENT_BEFORE_LOGOUT, $event); UserLog::log("logout"); Yii::$app->getUser()->logout(); $this->trigger(self::EVENT_AFTER_LOGOUT, $event); return $this->goHome(); }
/** * Creates new confirmation token and sends it to the user. * * @return bool */ public function resend() { if (!$this->validate()) { return false; } /** @var Token $token */ $token = Yii::createObject(['class' => Token::className(), 'user_id' => $this->user->id, 'type' => Token::TYPE_CONFIRMATION]); $token->save(false); $this->mailer->sendConfirmationMessage($this->user, $token); UserLog::log("reconfirm", "", $this->user); Yii::$app->session->setFlash('info', Yii::t('user', 'A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.')); return true; }
public function log($action, $message = '') { UserLog::log($action, $message); }
/** * Validates form and logs the user in. * * @return bool whether the user is logged in successfully */ public function login() { if ($this->validate()) { if (Yii::$app->getUser()->login($this->user, $this->rememberMe ? $this->module->rememberFor : 0)) { UserLog::log("login-success"); $this->user->last_login = gmdate("Y-m-d H:i:s"); $this->user->save(); return true; } else { return false; } } else { $message = ''; foreach ($this->errors['login'] as $error) { $message .= $error . "\n"; } UserLog::log("login-failure", $message); return false; } }