/** * The register action */ public function actionSignup() { $model = Yii::$app->getModule('accounts')->getModel('user', true, ['scenario' => 'signup']); if (Yii::$app->request->isAjax) { if ($model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } return false; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->setSignupUserConfig() && $model->save()) { $logInfo = ['info' => $model->username . ' has successfully registered.', 'username' => $model->username, 'email' => $model->email, 'role' => $model->role, 'status' => $model->status]; if (Yii::$app->getModule('accounts')->enableEmailSignupActivation) { $email = Yii::$app->mail->compose(Yii::$app->getModule('accounts')->emailViewsPath . 'signupActivation', ['user' => $model])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])->setTo($model->email)->setSubject(Yii::t('accounts', 'Account activation for {appname}', ['appname' => Yii::$app->name]))->send(); $logInfo['email_activation'] = ['auth_key' => $model->auth_key, 'send_from' => Yii::$app->params['supportEmail'], 'send_to' => $model->email]; if ($email) { $logInfo['email_activation']['send_status'] = 'success'; Yii::$app->session->setFlash('success-signup-email', Yii::t('accounts', 'Registration was successful. Please check your email inbox for further action to account activation.')); } else { $logInfo['email_activation']['send_status'] = 'error'; Yii::$app->session->setFlash('error-signup-email', Yii::t('accounts', 'Registration was successful, but the activation email could not be sent. Please contact us if you think this is a server error. Thank you.')); } $this->goLogin(['/site/index']); } else { $logInfo['email_activation'] = 'disabled'; if (Yii::$app->getUser()->login($model)) { $logInfo['auto_login'] = '******'; Yii::$app->session->setFlash('success-signup', Yii::t('accounts', 'Registration was successful.')); return $this->redirect(['profile', 'u' => $model->username]); } else { $logInfo['auto_login'] = '******'; Yii::$app->session->setFlash('error-signup', Yii::t('accounts', 'Registration failed. Please contact us if you think this is a server error. Thank you.')); return $this->goLogin(['/site/index']); } } ActionLog::add(ActionLog::LOG_STATUS_INFO, $logInfo, $model->id); } else { ActionLog::add(ActionLog::LOG_STATUS_ERROR, ['username' => $this->username, 'email' => $this->email, 'errors' => $user->errors]); } } return $this->render('signup', ['model' => $model]); }
public function afterFind($event) { ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); }
/** * @inheritdoc */ protected function afterLogin($identity) { ActionLog::add(ActionLog::LOG_STATUS_INFO, null, $identity->id); }