public function actionLogin() { $iUser_login = new UserLoginForm(); if (isset($_POST['UserLoginForm'])) { $iUser_login->attributes = $_POST['UserLoginForm']; if ($iUser_login->validate() && $iUser_login->login()) { $id = $this->_session['login_id']; $user = Member::model()->findByPk($id); $cur = $user->diligent_point; if (gmdate('M j, Y') != $user->date_login) { if (time() - $user->last_login <= 60 * 60 * 24) { Member::model()->updateByPk($id, array("diligent_point" => $cur + 1)); } else { if ($cur == 0) { $cur = 2; } $day = round((time() - $user->last_login) / (3600 * 24)); Member::model()->updateByPk($id, array("diligent_point" => $cur - 2 * $day < 0 ? 0 : $cur - 2 * $day)); } Member::model()->updateByPk($id, array("last_login" => time(), "date_login" => gmdate('M j, Y'))); $this->redirect($_SERVER['HTTP_REFERER']); } } else { Yii::app()->user->setFlash('error', 'Sai username hoặc password.'); } } $this->redirect(Yii::app()->getBaseUrl(true)); }
public function actionIndex() { if (O::app()->user->isGuest) { if (isset($this->actionParams['next'])) { $next = $this->getURL($this->actionParams['next']); } else { $next = $this->getURL('index', array('just_login' => 1)); } $regModel = new UserRegisterForm(); $regForm = $regModel->createForm(); $loginModel = new UserLoginForm(); $loginForm = $loginModel->createForm(); $regForm->action['nexturl'] = $loginForm->action['nexturl'] = $next; $this->render('index', array('regForm' => $regForm, 'loginForm' => $loginForm)); return; } elseif (isset($this->actionParams['just_login'])) { $div_count = O::app()->db->createCommand()->select('COUNT(dc.div_id)')->from(TableNames::DIVISION_CHOICE . ' dc')->join(TableNames::DIVISION . ' d', 'd.div_id = dc.div_id AND d.rec_id = :rec_id')->where('dc.user_id = :user_id')->limit(1)->queryScalar(array('rec_id' => $this->rec->id, 'user_id' => O::app()->user->id)); if ($div_count == 0) { $this->redirect($this->getURL('division', array('wiz' => 1))); return; } //$this->render('index'); } //else { $this->render('index'); //} }
public function run() { $this->skin = Yii::app()->user->isGuest ? 'user_auth' : 'user_info'; if (Yii::app()->user->isGuest) { Yii::import('mod.users.forms.UserLoginForm'); $model = new UserLoginForm(); if (isset($_POST['UserLoginForm'])) { $model->attributes = $_POST['UserLoginForm']; if ($model->validate()) { CIntegrationForums::instance()->check_user($model->login, $model->password); $duration = $model->rememberMe ? Yii::app()->settings->get('core', 'cookie_time') : 0; $model->authenticate(); if (Yii::app()->user->login($model->getIdentity(), $duration)) { Yii::app()->controller->refresh(); } else { Yii::app()->user->setFlash('login-error', 'Login error'); } } else { Yii::app()->user->setFlash('login-error', 'No validate'); } } } else { $model = false; } $this->render($this->skin, array('model' => $model, 'online' => Session::online())); }
/** * Display login page and authenticate user. */ public function actionLogin() { if (!Yii::app()->user->isGuest) { Yii::app()->request->redirect('/'); } Yii::import('application.modules.users.forms.UserLoginForm'); $model = new UserLoginForm(); if (Yii::app()->request->getIsPostRequest()) { $model->attributes = $_POST['UserLoginForm']; if ($model->validate()) { // Authenticate user and redirect to the dashboard if ($model->rememberMe) { $duration = Yii::app()->user->rememberTime; } else { $duration = 0; } // TODO: Use backtop param //if(Yii::app()->user->returnUrl && Yii::app()->user->returnUrl!=='/index.php') // $url=Yii::app()->user->returnUrl; //else $url = '/'; Yii::app()->user->login($model->getIdentity(), $duration); Yii::app()->request->redirect($url); } } $this->render('login', array('model' => $model)); }
public function actionLogin() { $this->pageName = Yii::t('app', 'AUTH'); $this->pageTitle = $this->pageName; $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = '/users/login'; $authIdentity->cancelUrl = $this->createAbsoluteUrl('login'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // $identity = new EAuthUserIdentity($authIdentity); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity, Yii::app()->user->rememberTime); // die(print_r($identity->authenticate())); // Специальный редирект с закрытием popup окна $authIdentity->redirect(); } else { die('error: cancel();'); // Закрываем popup окно и перенаправляем на cancelUrl $authIdentity->cancel(); } } die('err'); // Что-то пошло не так, перенаправляем на страницу входа $this->redirect(array('login')); } if (!Yii::app()->user->isGuest) { Yii::app()->request->redirect('/'); } Yii::import('mod.users.forms.UserLoginForm'); $model = new UserLoginForm(); $view = Yii::app()->request->isAjaxRequest ? '_form' : 'login'; if (Yii::app()->request->getIsPostRequest()) { $model->attributes = $_POST['UserLoginForm']; // integration forum // CIntegrationForums::instance()->check_user($model->login, $model->password); if ($model->validate()) { $duration = $model->rememberMe ? (int) Yii::app()->settings->get('core', 'cookie_time') : 0; if (Yii::app()->user->login($model->getIdentity(), $duration)) { if (Yii::app()->request->isAjaxRequest) { $view = 'ajax_success_login'; } else { $this->refresh(); } } else { // if (count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1) // $model->addError('login', Yii::t('default', 'INCORRECT_LOGIN_OR_PASS')); if (count(User::model()->findByAttributes(array('login' => $model->login))) < 1 || count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1) { $model->addError('login', Yii::t('app', 'INCORRECT_LOGIN_OR_PASS')); } } } } if (Yii::app()->request->isAjaxRequest) { Yii::app()->clientScript->scriptMap['jquery.js'] = false; } $this->render($view, array('model' => $model), false, true); }
protected function renderContent() { if (isset($this->block) && $this->block != null) { $model = new UserRegisterForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'userregister-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['UserRegisterForm'])) { $model->attributes = $_POST['UserRegisterForm']; // validate user input password if ($model->validate()) { $new_user = new User(); $new_user->scenario = 'create'; //$new_user->username=$model->username; $new_user->username = $new_user->email = $model->email; $new_user->display_name = $model->username; $old_password = $new_user->password = $model->password; //Create hash activation key $new_user->user_activation_key = md5(time() . $new_user->username . USER_SALT); if ($new_user->save()) { //We will send mail for the user $ses = new SimpleEmailService(ConstantDefine::AMAZON_SES_ACCESS_KEY, ConstantDefine::AMAZON_SES_SECRET_KEY); $ses->enableVerifyHost(false); $m = new SimpleEmailServiceMessage(); $m->addTo($new_user->email); $m->setFrom(ConstantDefine::AMAZON_SES_EMAIL); $m->setSubject('[' . SITE_NAME . '] Confirm your email at ' . SITE_NAME_URL); $m_content = 'Hi ' . $new_user->display_name . '<br /><br />'; $m_content .= 'Welcome to ' . SITE_NAME . '! Please take a second to confirm ' . $new_user->email . ' as your email address by clicking this link: <br /><br />'; $link_content = FRONT_SITE_URL . '/user-activation/?key=' . $new_user->user_activation_key . '&user_id=' . $new_user->user_id; $m_content .= '<a href="' . $link_content . '">' . $link_content . '</a><br /><br />'; $m_content .= 'Thank you for being with us!<br /><br />'; $m_content .= SITE_NAME . ' Team'; $m->setMessageFromString($m_content, $m_content); $ses->sendEmail($m); //Redirect to the Dashboard Page $login_form = new UserLoginForm(); $login_form->username = $new_user->username; $login_form->password = $old_password; if ($login_form->login()) { Yii::app()->controller->redirect(bu()); } else { throw new CHttpException(503, t('Error while setting up your Account. Please try again later')); } } } } $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model)); } else { echo ''; } }
/** * Function to Register user information * @return type */ public function doSignUp() { if (!$this->hasErrors()) { $newUser = new User(); $newUser->password = $this->password; if (!$newUser->save()) { $this->addError('email', t('Something is wrong with the Registration Process. Please try again later!')); return false; } else { //We can start to add Profile record here //We can start to add User Activity here //We can check to send Email or not //Create new UserLoginForm $login_form = new UserLoginForm(); $login_form->username = $newUser->username; $login_form->password = $this->password; return $login_form->login(); } } }
public function actionLogin() { if (isset($this->actionParams['nexturl'])) { $nexturl = $this->actionParams['nexturl']; } else { $nexturl = array('/user/profile'); } if (!O::app()->user->getIsGuest()) { $this->redirect($nexturl); } $model = new UserLoginForm(); $form = $model->createForm(); $form->action['nexturl'] = CHtml::normalizeUrl($nexturl); //var_dump($this->actionParams); //if ($form->submitted('login')) exit; if ($form->submitted('login') && $form->validate() && $model->login()) { $this->redirect($nexturl); } else { $this->render('login', array('form' => $form)); } }
public function initUser(User $user, $autocreate, $createTempUser = true) { $user = parent::initUser($user, $autocreate, false); if ($user instanceof User) { $user->confirmEmail(); $this->connectWithFacebook($user); $user->saveSettings(); // log me in $user->setCookies(); } return $user; }
/** * Initialize the user object * * @param User $user * @param bool $autocreate * @return User */ public function initUser(User &$user, $autocreate) { $ret = parent::initUser($user, $autocreate, $this->hasConfirmedEmail); if ($ret) { $this->connectWithFacebook($user); $this->saveUserGender($user); if ($this->hasConfirmedEmail) { $this->confirmUser($user); $user->setCookies(); $this->addNewUserToLog($user); } else { $this->sendConfirmationEmail($user); } } return $ret; }
/** * validate form * @requestParam string field [userloginext01/userloginext02/email/birthdate] * @requestParam string userloginext01 //CE-413 signup spam attack - changing username field to userloginext01 * @requestParam string email * @requestParam string userloginext02 //CE-413 signup spam attack - changing password field to userloginext02 * @requestParam string birthmonth * @requestParam string birthday * @requestParam string birthyear * @responseParam string result [ok/error] * @responseParam string msg - result message * @responseParam string errParam - error param */ public function formValidation() { $field = $this->request->getVal('field', ''); $signupForm = new UserLoginForm($this->wg->request); $signupForm->load(); switch ($field) { case 'userloginext01': $signupForm->initValidationUsername(); break; case 'email': $signupForm->initValidationEmail() && $signupForm->initValidationRegsPerEmail(); break; case 'birthdate': $signupForm->initValidationBirthdate(); break; default: throw new MWException("Unhandled case value"); } $this->result = $signupForm->msgType == 'error' ? $signupForm->msgType : 'ok'; $this->msg = $signupForm->msg; $this->errParam = $signupForm->errParam; }