/** * Displays the login page */ public function actionLogin() { // If user is already logged in, redirect him to the dashboard if (!Yii::app()->user->isGuest) { $this->redirect(Yii::app()->user->returnUrl); } // Show/Allow Anonymous Registration $canRegister = HSetting::Get('anonymousRegistration', 'authentication_internal'); $ntlmAutoLogin = false; $model = new AccountLoginForm(); //TODO: Solve this via events! if (Yii::app()->getModule('zsso') != null) { ZSsoModule::beforeActionLogin(); } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'account-login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['AccountLoginForm'])) { #$_POST['AccountLoginForm'] = Yii::app()->input->stripClean($_POST['AccountLoginForm']); $model->attributes = $_POST['AccountLoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $this->redirect(Yii::app()->user->returnUrl); } } // Always clear password $model->password = ""; $registerModel = new AccountRegisterForm(); // Registration enabled? if ($canRegister) { // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'account-register-form') { echo CActiveForm::validate($registerModel); Yii::app()->end(); } if (isset($_POST['AccountRegisterForm'])) { $_POST['AccountRegisterForm'] = Yii::app()->input->stripClean($_POST['AccountRegisterForm']); $registerModel->attributes = $_POST['AccountRegisterForm']; if ($registerModel->validate()) { // Try Load an invite $userInvite = UserInvite::model()->findByAttributes(array('email' => $registerModel->email)); if (!$userInvite) { $userInvite = new UserInvite(); } $userInvite->email = $registerModel->email; $userInvite->source = UserInvite::SOURCE_SELF; $userInvite->save(); $userInvite->sendInviteMail(); $this->render('register_success', array('model' => $registerModel)); return; } } } // display the login form $this->render('login', array('model' => $model, 'registerModel' => $registerModel, 'canRegister' => $canRegister)); }
/** * Displays the login page */ public function actionLogin() { // If user is already logged in, redirect him to the dashboard if (!Yii::app()->user->isGuest) { $this->redirect(Yii::app()->user->returnUrl); } // Show/Allow Anonymous Registration $canRegister = HSetting::Get('anonymousRegistration', 'authentication_internal'); $model = new AccountLoginForm(); //TODO: Solve this via events! if (Yii::app()->getModule('zsso') != null) { ZSsoModule::beforeActionLogin(); } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'account-login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } //User::model()->findByAttributes(array('guid' => Yii::app()->request->getQuery('guid'))); // collect user input data if (isset($_POST['AccountLoginForm'])) { $model->attributes = $_POST['AccountLoginForm']; if ($model->validate() && $model->login()) { $check = UserInvite::model()->findByAttributes(array('email' => Yii::app()->user->email)); if ($check != "") { $now = new DateTime(date("Y-m-d")); $diff = 0; $token = $check->token; $timestamp = strtotime($check->created_at); $created_at = new DateTime(date("Y-m-d", $timestamp)); $diff = date_diff($created_at, $now); $diff = (int) $diff->format('%a'); //var_dump($diff); if ($diff > 2) { $this->redirect(array("//user/auth/timeout", 'token' => $token, 'email' => $check->email)); } } $user = User::model()->findByPk(Yii::app()->user->id); if (Yii::app()->request->isAjaxRequest) { $this->htmlRedirect(Yii::app()->user->returnUrl); } else { $this->redirect(Yii::app()->user->returnUrl); } } } // Always clear password $model->password = ""; $registerModel = new AccountRegisterForm(); // Registration enabled? if ($canRegister) { // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'account-register-form') { echo CActiveForm::validate($registerModel); Yii::app()->end(); } if (isset($_POST['AccountRegisterForm'])) { $registerModel->attributes = $_POST['AccountRegisterForm']; if ($registerModel->validate()) { // Try Load an invite $userInvite = UserInvite::model()->findByAttributes(array('email' => $registerModel->email)); if ($userInvite === null) { $userInvite = new UserInvite(); } else { error_log("not null"); } $userInvite->email = $registerModel->email; $userInvite->source = UserInvite::SOURCE_SELF; $userInvite->language = Yii::app()->language; $userInvite->save(); $userInvite->sendInviteMail(); //$this->render('register_success', array( // 'model' => $registerModel, // 'token' => $userInvite->token, //)); $this->redirect(array("//user/auth/createAccount", 'token' => $userInvite->token)); return; } } } //error_log(Yii::app()->request->isAjaxRequest); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('login_modal', array('model' => $model, 'registerModel' => $registerModel, 'canRegister' => $canRegister), false, true); } else { $this->render('login', array('model' => $model, 'registerModel' => $registerModel, 'canRegister' => $canRegister)); } }