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)); }
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)); } }