public function testLoginForm() { $oForm = new LoginForm(); $this->assertFalse($oForm->validate()); $oForm->username = '******'; $oForm->password = '******'; $this->assertTrue($oForm->validate()); }
public function testValidate_OneTimeLogin() { // Create new login form model, use 'OneTimeLogin' scenario $model = new LoginForm('OneTimeLogin'); // Try to validate with incorrect access token - assume failure $model->oneTimeAccessToken = "abcdefghijklmnopqrstuvw314534"; $this->assertFalse($model->validate()); $model->clearErrors(); // Try to validate with correct access token - assume success $model->oneTimeAccessToken = "6c9016a509b565a0eb9a4d6c5fd7be0c"; $this->assertTrue($model->validate()); }
public function actionIndex() { /** * 测试连接数据库 * var_dump(Yii::app()->db); * $userInfo = User::model()->find("username=:name",array(':name'=>'zhuwanxiong')); * p($userInfo);die; */ $loginForm = new LoginForm(); if (isset($_POST['LoginForm'])) { //固定写法 $loginForm->attributes = $_POST['LoginForm']; if ($loginForm->validate() && $loginForm->login()) { Yii::app()->session['logintime'] = time(); $this->redirect(array('admin/index')); } } //手动加载布局 $this->layout = "/layouts/login"; $randkey = rand(1, 2); $this->render("login2", array('loginForm' => $loginForm)); /* switch ($randkey){ case 1: $this->render("login",array('loginForm'=>$loginForm)); break; case 2: $this->render("login2",array('loginForm'=>$loginForm)); } */ }
public function actionSignup() { $model = new User(); // uncomment the following code to enable ajax-based validation /* if(isset($_POST['ajax']) && $_POST['ajax']==='user-signup-form') { echo CActiveForm::validate($model); Yii::app()->end(); } */ if (isset($_POST['User'])) { $model->attributes = $_POST['User']; if ($model->validate()) { $login = new LoginForm(); $login->username = $model->email; $login->password = $model->password; $model->save(false); if ($login->validate(array('username', 'password')) && $login->login()) { $this->redirect(Yii::app()->user->returnUrl); } else { echo "Email:" . $model->email; echo "Password:" . $model->password; $this->render('login', array('model' => $login)); return; } // form inputs are valid, do something here } } $this->render('signup', array('model' => $model)); }
public function actionLoginHandler() { $model = new LoginForm(); if (isPostOrAjaxRequest()) { if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; if ($model->validate()) { if (!$model->isUserBanned()) { $model->login(); } else { $response['redirect'] = $this->createUrl('banned'); $this->successfulAjaxResponse($response); } } if (isAjax()) { if ($model->hasErrors()) { $this->validationErrorsAjaxResponse($model, FALSE); } else { $response['redirect'] = Yii::app()->getRequest()->getUrlReferrer(); $this->successfulAjaxResponse($response); } } } } }
public function run() { if (Yii::app()->user->isAuthenticated()) { $this->controller->redirect(Yii::app()->user->returnUrl); } /** * Если было совершено больше 3х попыток входа * в систему, используем сценарий с капчей: **/ $badLoginCount = Yii::app()->authenticationManager->getBadLoginCount(Yii::app()->user); //@TODO 3 вынести в настройки модуля $scenario = $badLoginCount > 3 ? 'loginLimit' : ''; $form = new LoginForm($scenario); $module = Yii::app()->getModule('user'); if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['LoginForm'])) { $form->setAttributes(Yii::app()->request->getPost('LoginForm')); if ($form->validate() && Yii::app()->authenticationManager->login($form, Yii::app()->user, Yii::app()->request)) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'You authorized successfully!')); $module->onSuccessLogin(new CModelEvent($this->controller, array('loginForm' => $form))); if (Yii::app()->user->isSuperUser() && $module->loginAdminSuccess) { $redirect = array($module->loginAdminSuccess); } else { $redirect = empty($module->loginSuccess) ? Yii::app()->baseUrl : $module->loginSuccess; } Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->user, 0); $this->controller->redirect($redirect); } else { $form->addError('hash', Yii::t('UserModule.user', 'Email or password was typed wrong!')); Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->user, $badLoginCount + 1); $module->onErrorLogin(new CModelEvent($this->controller, array('loginForm' => $form))); } } $this->controller->render($this->id, array('model' => $form)); }
public function actionLogin() { $formLogin = new LoginForm(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { var_dump($_POST); die; echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['LoginForm'])) { $formLogin->attributes = $_POST['LoginForm']; if ($formLogin->validate() && $formLogin->login()) { $idSesion = Yii::app()->user->id; $objusuario = new Usuarios(); $usuario = $objusuario->findByPk($idSesion); switch ($usuario->roles_id) { case '1': # Redirecciona al perfil del Usuario registrado break; case '2' or '3': $this->redirect(array('propuestas/listar')); break; default: $this->redirect(array('site/login')); break; } } } $this->render('login', array('model' => $formLogin)); }
/** * Logs in the user using the given username and password in the model. * @return boolean whether login is successful */ public function save() { $user = new Users(); $user->setAttributes($this->attributes); $user->setAttribute("password", BaseTool::ENPWD($this->password)); if ($user->validate() && $user->save()) { $accountarray = array('user_id' => Yii::app()->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0); $newAccount = new Account(); $newAccount->setAttributes($accountarray); $newAccount->save(); //发送邮件 $activecode = BaseTool::getActiveMailCode($this->username); $message = MailTemplet::getActiveEmail($this->username, $activecode); $mail = Yii::app()->Smtpmail; $mail->SetFrom(Yii::app()->params['adminEmail']); $mail->Subject = "好帮贷测试邮件"; $mail->MsgHTML($message); $mail->AddAddress($this->email); if ($mail->Send()) { $user->updateAll(array("regtaken" => $activecode, "regativetime" => time() + 60 * 60), "username=:username", array(":username" => $this->username)); } Yii::import("application.models.form.LoginForm", true); $loginform = new LoginForm(); $loginarray = array('rememberMe' => false, 'username' => $this->username, 'password' => $this->password); $loginform->setAttributes($loginarray); if ($loginform->validate() && $loginform->login()) { } return true; } else { $usererror = $user->errors; $this->addError("username", current(current($usererror))); return false; } }
/** * Visualiza la pagina de autenticacion de usuario */ public function actionAutenticar() { $this->showSeeker = true; $model = new LoginForm(); if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; if ($model->validate()) { if (Yii::app()->session[Yii::app()->params->sesion['redireccionAutenticacion']] == 'null') { $this->redirect(Yii::app()->homeUrl); } else { $redirect = Yii::app()->session[Yii::app()->params->sesion['redireccionAutenticacion']]; Yii::app()->session[Yii::app()->params->sesion['redireccionAutenticacion']] = 'null'; $this->redirect($redirect); } //echo "--URL: " . Yii::app()->request->urlReferrer; //$this->redirect(Yii::app()->request->urlReferrer); //$this->redirect(Yii::app()->user->returnUrl); } } else { if (!isset(Yii::app()->session[Yii::app()->params->sesion['redireccionAutenticacion']]) || Yii::app()->session[Yii::app()->params->sesion['redireccionAutenticacion']] == 'null') { Yii::app()->session[Yii::app()->params->sesion['redireccionAutenticacion']] = Yii::app()->request->urlReferrer == null ? 'null' : Yii::app()->request->urlReferrer; } } $this->render('autenticar', array('model' => $model)); }
public function testValidate() { $model = new LoginForm(); $model->username = '******'; $model->password = '******'; $this->assertTrue($model->validate()); }
public function actionLogin() { $baseUrl = Yii::app()->homeUrl; $baseUrl = Yii::app()->request->hostInfo . $baseUrl; if (Yii::app()->user->isGuest) { $model = new LoginForm(); if (Yii::app()->request->isPostRequest) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $this->redirect(Yii::app()->user->returnUrl); } else { $error = $model->getErrorCode(); //var_dump($error);exit; if ($error == 201) { echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; echo "<h2 style='text-align:center'>Tài khoản của bạn đã bị khóa. Liên hệ TrangPTK để kích hoạt lại.({$error})</h2>"; exit; } } } // display the login form $this->render('login', array('model' => $model)); } else { $this->redirect('/'); } }
public function run() { if (Yii::app()->user->isAuthenticated()) { $this->controller->redirect(Url::redirectUrl(Yii::app()->getUser()->getReturnUrl())); } /** * Если было совершено больше 3х попыток входа * в систему, используем сценарий с капчей: **/ $badLoginCount = Yii::app()->authenticationManager->getBadLoginCount(Yii::app()->getUser()); $module = Yii::app()->getModule('user'); $scenario = $badLoginCount > (int) $module->badLoginCount ? LoginForm::LOGIN_LIMIT_SCENARIO : ''; $form = new LoginForm($scenario); if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['LoginForm'])) { $form->setAttributes(Yii::app()->getRequest()->getPost('LoginForm')); if ($form->validate() && Yii::app()->authenticationManager->login($form, Yii::app()->getUser(), Yii::app()->getRequest())) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'You authorized successfully!')); if (Yii::app()->getUser()->isSuperUser() && $module->loginAdminSuccess) { $redirect = $module->loginAdminSuccess; } else { $redirect = empty($module->loginSuccess) ? Yii::app()->getBaseUrl() : $module->loginSuccess; } $redirect = Yii::app()->getUser()->getReturnUrl($redirect); Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), 0); $this->controller->redirect(Url::redirectUrl($redirect)); } else { $form->addError('email', Yii::t('UserModule.user', 'Email or password was typed wrong!')); Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), $badLoginCount + 1); } } $this->controller->render($this->id, array('model' => $form)); }
public function renderContent() { if (Yii::app()->user->isMember) { $this->render('bank'); } else { $model = new LoginForm(); // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid //if($model->validate() && $model->login()) if ($model->validate()) { switch (Yii::app()->user->role_id) { case ROLE_MEMBER: Yii::app()->controller->redirect(Yii::app()->createAbsoluteUrl('member')); break; case ROLE_ADMIN: Yii::app()->controller->redirect(Yii::app()->createAbsoluteUrl('admin/login')); break; default: Yii::app()->controller->redirect(Yii::app()->createAbsoluteUrl('member')); } Yii::app()->end(); } } // display the login form $this->render('form', array('model' => $model)); } }
/** * This is the action to handle external exceptions. */ public function actionLogin() { if (!Yii::app()->user->isGuest) { $this->redirect('/member/index.html'); } $this->pageTitle = "登录中心 - " . Yii::app()->name; if (isset($_POST['username'])) { $status = array(); if (!isset($_POST['username']) || !isset($_POST['password'])) { $status = array('status' => 0, "info" => '用户名或者密码错误!'); } else { Yii::import("application.models.form.LoginForm", true); $loginform = new LoginForm(); if (!isset($_POST['rememberMe'])) { $_POST['rememberMe'] = false; } $loginform->setAttributes(array('username' => $_POST['username'], 'password' => $_POST['password'], 'rememberMe' => $_POST['rememberMe'])); if ($loginform->validate() && $loginform->login()) { $status = array('status' => 1, "info" => '登录'); } else { $status = array('status' => 0, "info" => '用户名或者密码错误!'); } } echo json_encode($status); Yii::app()->end(); } $this->render('html5_login'); }
/** * Login action */ public function actionindex() { $model = new LoginForm(); if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; if ($model->validate()) { // Login $identity = new InternalIdentity($model->email, $model->password); if ($identity->authenticate()) { // Member authenticated, Login Yii::app()->user->setFlash('success', Yii::t('login', 'Thanks. You are now logged in.')); Yii::app()->user->login($identity, Yii::app()->params['loggedInDays'] * 60 * 60 * 24); } // Redirect $this->redirect('index/index'); } } // Load facebook Yii::import('ext.facebook.facebookLib'); $facebook = new facebookLib(array('appId' => Yii::app()->params['facebookappid'], 'secret' => Yii::app()->params['facebookapisecret'], 'cookie' => true, 'disableSSLCheck' => false)); facebookLib::$CURL_OPTS[CURLOPT_CAINFO] = Yii::getPathOfAlias('ext.facebook') . '/ca-bundle.crt'; // Facebook link $facebookLink = $facebook->getLoginUrl(array('req_perms' => 'read_stream,email,offline_access', 'next' => Yii::app()->createAbsoluteUrl('/login/facebooklogin', array('lang' => false)), 'display' => 'popup')); $this->render('index', array('model' => $model, 'facebookLink' => $facebookLink, 'facebook' => $facebook)); }
protected function proccessRequest() { if (Yii::app()->request->getPost('logout') !== null) { Yii::app()->user->logout(); Yii::app()->controller->refresh(); return true; } if (Yii::app()->request->getPost('LoginForm') !== null) { $model = new LoginForm(); $model->attributes = Yii::app()->request->getPost('LoginForm'); if ($model->validate() && $model->login()) { Yii::app()->controller->refresh(); return true; } } if (Yii::app()->request->getPost('RememberForm') !== null) { $model = new RememberForm(); $model->attributes = Yii::app()->request->getPost('RememberForm'); if ($model->validate()) { $user = User::model()->find('`login` = :username OR `email` = :username', array('username' => $model->username)); if ($user) { $user->saveAttributes(array('authcode' => User::hash($user->id . $user->email . time() . rand()))); $cfg = ContentUnit::loadConfig(); $viewFileDir = $cfg['UnitLogin'] . '.login.templates.mail.'; $tpldata['model'] = $user; $tpldata['settings'] = Yii::app()->settings->model->getAttributes(); $tpldata['page'] = $this->params['content']->getUnitPageArray(); // send 'to_user_confirm' mail Yii::app()->messenger->send('email', $user->email, Yii::t('UnitLogin.main', 'Password reset'), Yii::app()->controller->renderPartial($viewFileDir . 'password_reset', $tpldata, true)); return true; } } } return false; }
/** * Displays the login page */ public function actionLogin() { $model = new LoginForm(); // if it is ajax validation request /* if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } */ // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { /* Simpan theme ke cookies */ $user = User::model()->findByPk(Yii::app()->user->id); $theme = Theme::model()->findByPk($user->theme_id); $theme->toCookies(); $this->redirect(Yii::app()->user->returnUrl); } } // display the login form $this->render('login', array('model' => $model)); }
/** * Displays the login page */ public function actionLogin() { if (isset($_REQUEST['email'])) { $model = new LoginForm(); // echo $_REQUEST['email']."<br>"; // echo $_REQUEST['password']."<br>"; $model->username = $_REQUEST['email']; $model->password = $_REQUEST['password']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $user = User::model()->findByPk(Yii::app()->user->id); $user->last_login = date('Y-m-d h:i:s'); $user->scenario = 'login'; if ($user->save()) { echo $user->level; } else { print_r($user->getErrors()); } // echo "succesfull"; } else { echo "failed"; // print_r($model->getErrors()); } } else { echo "ga post ke login form"; } }
public function actionLogin() { //echo 'Yuan want to login system!'; //通过控制器来调用视图 //renderPartial()调用视图,不渲染布局,render可以 //$this->renderPartial('login'); if (!Yii::app()->user->isGuest) { $this->redirect(array('user/home', 'uid' => Yii::app()->user->id)); } //创建登录模型对象 $user_login = new LoginForm(); if (isset($_POST['LoginForm'])) { //收集登录表单信息 $user_login->attributes = $_POST['LoginForm']; //持久化用户信息 session,login()方法 //校验通过 validate()方法 if ($user_login->validate() && $user_login->login()) { //$this->redirect(Yii::app()->user->returnUrl);//session 储存,开始 //$this->redirect("./index.php?r=user/home&id=$id"); //$this->redirect(Yii::app()->request->urlReferrer); $this->redirect(array('user/home', 'uid' => Yii::app()->user->id)); } } $this->render('login', array('user_login' => $user_login)); }
public function actionLogin() { if (isset($_POST['token'])) { $this->networkLogin(); } $this->layout = null; $this->breadCrumbs = array('Управление сайтом' => array('/users/default/siteManagment')); $form = new LoginForm(); if (isset($_POST['LoginForm'])) { $form->attributes = $_POST['LoginForm']; if ($form->validate()) { $backUrl = $form->getBackUrl(); if (Yii::app()->getRequest()->getIsAjaxRequest()) { echo CHtml::script("document.location='" . $backUrl . "'"); return; } else { $this->redirect($backUrl); } } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('form/login', array('form' => $form, 'backUrl' => $backurl)); } else { $this->render('login', array('user' => $form, 'backUrl' => $backurl)); } }
/** * @dataProvider invalidDataProvider */ public function testInvalid($scenario, $attributes, $errors) { $form = new LoginForm($scenario); $form->userIdentityClass = 'UserIdentity'; $form->setAttributes($attributes); $this->assertFalse($form->validate()); $this->assertEquals($errors, $form->getErrors()); }
public function run() { if (Yii::app()->user->isAuthenticated()) { $this->controller->redirect(Yii::app()->user->returnUrl); } /** * Если было совершено больше 3х попыток входа * в систему, используем сценарий с капчей: **/ $badLoginCount = Yii::app()->authenticationManager->getBadLoginCount(Yii::app()->user); //@TODO 3 вынести в настройки модуля $scenario = $badLoginCount > 3 ? 'loginLimit' : ''; $form = new LoginForm('login'); $module = Yii::app()->getModule('user'); if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['LoginForm'])) { if (!empty($_POST['programId'])) { Yii::app()->user->setState('programId', (int) $_POST['programId']); } if (!empty($_POST['subscriptionType'])) { Yii::app()->user->setState('subscriptionType', $_POST['subscriptionType']); } $form->setAttributes(Yii::app()->request->getPost('LoginForm')); $form->remember_me = 1; if ($form->validate() && Yii::app()->authenticationManager->login($form, Yii::app()->user, Yii::app()->request)) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, 'Вы успешно авторизованы!'); if (Yii::app()->user->isSuperUser() && $module->loginAdminSuccess) { $redirect = array($module->loginAdminSuccess); } else { $redirect = empty($module->loginSuccess) ? Yii::app()->baseUrl : $module->loginSuccess; } Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->user, 0); // Переадресация на страницу подписки if (Yii::app()->user->getState('programId') !== null && Yii::app()->user->getState('subscriptionType') !== null) { Yii::import("application.modules.classroom.models.*"); $programm = CourseType::model()->published()->findByPK((int) Yii::app()->user->getState('programId')); $redirect = $programm->getSubscriptionUrl(Yii::app()->user->getState('subscriptionType')); Yii::app()->user->setState('programId', null); Yii::app()->user->setState('subscriptionType', null); } if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->ajax->success($redirect); } else { $this->controller->redirect($redirect); } } else { $form->addError('hash', 'Вы ввели неправильный E-mail или Пароль'); Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->user, $badLoginCount + 1); if (Yii::app()->getRequest()->getIsAjaxRequest()) { $errors = array(); foreach ($form->getErrors() as $error) { $errors[] = $error[0]; } Yii::app()->ajax->failure(implode('<br />', $errors)); } } } $this->controller->render($this->id, array('model' => $form)); }
public function actionLogin() { $data = CJSON::decode(file_get_contents('php://input')); if ($data) { $model = new LoginForm(); $model->attributes = $data; if (isset($data['ajax']) && $data['ajax'] === 'login-form') { if (!$model->validate()) { echo CJSON::encode($model->errors); } Yii::app()->end(); } if ($model->validate() && $model->login()) { $this->sendResponse(200, Yii::app()->user->toJSON()); } else { $this->sendResponse(401, CJSON::encode($model->errors)); } } }
protected function renderContent() { $form = new LoginForm(); if (isset($_POST['LoginForm'])) { $form->attributes = $_POST['LoginForm']; if ($form->validate() && $form->login()) { $this->controller->redirect(Yii::app()->user->returnUrl); } } $this->render('loginWidget', array('form' => $form)); }
public function actionLogin() { $loginForm = new LoginForm(); if (isset($_POST['LoginForm'])) { $loginForm->setAttributes($_POST['LoginForm']); if ($loginForm->validate() && $loginForm->login()) { $this->redirect(Yii::app()->createUrl('offer/create')); } } $this->render('login', array('loginForm' => $loginForm)); }
public function actionLogin() { $form = new LoginForm(); if ($this->request->isPostRequest) { $form->attributes = $_POST['LoginForm']; if ($form->validate()) { $this->redirect(array($this->module->returnUrl)); } } $this->render('login', array('model' => $form)); }
public function actionIndex() { $loginForm = new LoginForm(); if (isset($_POST['LoginForm'])) { $loginForm->attributes = $_POST['LoginForm']; if ($loginForm->validate() && $loginForm->login()) { $this->redirect(array('default/index')); } } $this->render('index', array('loginForm' => $loginForm)); }
protected function renderContent() { $form = new LoginForm(); if (isset($_POST['LoginForm'])) { $form->attributes = $_POST['LoginForm']; if ($form->validate() && $form->login()) { $this->controller->refresh(); } } $this->render('Userlogin', array('model' => $form)); }
protected function renderContent() { $form = new LoginForm(); if (isset($_POST['LoginForm']) && isset($_POST['loginWidget'])) { $form->attributes = $_POST['LoginForm']; if ($form->validate()) { $this->controller->refresh(); } } $this->render('userLogin', array('form' => $form)); }
public function actionIndex() { Yii::import('application.modules.backend.models.LoginForm'); $model = new LoginForm(); if (isset($_POST['LoginForm'])) { $model->setAttributes($_POST['LoginForm']); if ($model->validate() && $model->login()) { $this->redirect(array('/backend/default/index')); } } $this->render('//login/index', array('model' => $model)); }