authenticate() public method

The example implementation makes sure if the username and password are both 'demo'. In practical applications, this should be changed to authenticate against some persistent user identity storage (e.g. database).
public authenticate ( ) : boolean
return boolean whether authentication succeeds.
コード例 #1
0
 /**
  * Logs in the user using the given username and password in the model.
  * @return boolean whether login is successful
  */
 public function login()
 {
     if ($this->_identity === null) {
         $this->_identity = new UserIdentity($this->email, $this->password);
         $this->_identity->authenticate();
     }
     return $this->_identity->login();
 }
コード例 #2
0
ファイル: LoginForm.php プロジェクト: wuhailin/composer
 public function authenticate()
 {
     $this->_identity = new UserIdentity($this->username, $this->password);
     $this->_identity->modelName = 'common\\model\\Admin';
     if (!$this->_identity->authenticate()) {
         $this->addError('password', '用户或密码错误!');
     }
 }
コード例 #3
0
ファイル: LoginForm.php プロジェクト: DarkAiR/test
 /**
  * Logs in the user using the given username and password in the model.
  * @return boolean whether login is successful
  */
 public function login()
 {
     if ($this->_identity === null) {
         $this->_identity = new UserIdentity($this->email, $this->password);
         $this->_identity->authenticate();
     }
     if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
         $duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
         // 30 days
         Yii::app()->user->login($this->_identity, $duration);
         return true;
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: LoginForm.php プロジェクト: Greka163/Yii-blog-new
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
                 // 30 days
                 Yii::app()->user->login($identity, $duration);
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError('username', Yii::t('lan', 'Username is incorrect.'));
                 break;
             case UserIdentity::ERROR_BANNED:
                 $this->addError('username', Yii::t('lan', 'User is banned.'));
                 break;
             case UserIdentity::ERROR_CONFIRMREGISTRATION:
                 $this->addError('username', Yii::t('lan', 'Confirm user email.'));
                 break;
             default:
                 $this->addError('password', Yii::t('lan', 'Password is incorrect.'));
                 break;
         }
     }
 }
コード例 #5
0
ファイル: ExampleText.php プロジェクト: rawaludin/jenkins-yii
 public function testUserIdentity()
 {
     $oIden = new UserIdentity('', '');
     $this->assertFalse($oIden->authenticate());
     $oIden = new UserIdentity('admin', 'admin');
     $this->assertTrue($oIden->authenticate());
 }
コード例 #6
0
	/**
	 * Activation user account
	 */
	public function actionActivation () {
		$email = $_GET['email'];
		$activkey = $_GET['activkey'];
		if ($email&&$activkey) {
			$find = User::model()->notsafe()->findByAttributes(array('email'=>$email));
			if (isset($find)&&$find->status) {
			    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is active.")));
			} elseif(isset($find->activkey) && ($find->activkey==$activkey)) {
				$find->activkey = UserModule::encrypting(microtime());
				$find->status = 1;
				$find->save();
                if (!Yii::app()->controller->module->autoLogin) {
                    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is activated.")));
                } else {
                    $identity=new UserIdentity($find->username, '');
                    $identity->authenticate(true);
                    Yii::app()->user->login($identity,0);
                    Yii::app()->user->setFlash('userActivationSuccess', UserModule::t("You account is activated."));
                    $this->redirect(Yii::app()->controller->module->returnUrl);
                }
			} else {
			    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
			}
		} else {
			$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
		}
	}
コード例 #7
0
ファイル: UserLogin.php プロジェクト: nizsheanez/PolymorphCMS
	/**
	 * Authenticates the password.
	 * This is the 'authenticate' validator as declared in rules().
	 */
	public function authenticate($attribute,$params)
	{
		if(!$this->hasErrors())  // we only want to authenticate when no input errors
		{
			$identity=new UserIdentity($this->username,$this->password);
			$identity->authenticate();
			switch($identity->errorCode)
			{
				case UserIdentity::ERROR_NONE:
					$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
					Yii::app()->user->login($identity,$duration);
					break;
				case UserIdentity::ERROR_EMAIL_INVALID:
					$this->addError("username",Users::t("Email is incorrect."));
					break;
				case UserIdentity::ERROR_USERNAME_INVALID:
					$this->addError("username",Users::t("Username is incorrect."));
					break;
				case UserIdentity::ERROR_STATUS_NOTACTIV:
					$this->addError("status",Users::t("You account is not activated."));
					break;
				case UserIdentity::ERROR_STATUS_BAN:
					$this->addError("status",Users::t("You account is blocked."));
					break;
				case UserIdentity::ERROR_PASSWORD_INVALID:
					$this->addError("password",Users::t("Password is incorrect."));
					break;
			}
		}
	}
コード例 #8
0
 public function actionRegister()
 {
     $user = new User('register');
     $profile = new Profile('register');
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'register') {
         $user->scenario = 'registerPlusComparePassword';
         echo CActiveForm::validate(array($user, $profile));
         Yii::app()->end();
     }
     if (isset($_POST['User'])) {
         $user->attributes = $_POST['User'];
         $user->password = md5($user->password);
         $user->password_repeat = md5($user->password_repeat);
         $user->user_type_id = 2;
         if ($user->save()) {
             if (isset($_POST['Profile'])) {
                 $profile->attributes = $_POST['Profile'];
                 $profile->birthday = $profile->b_year . "-" . $profile->b_month . "-" . $profile->b_day;
                 $profile->user_id = $user->id;
                 $profile->save();
                 $identity = new UserIdentity($user->login, $user->password);
                 $identity->authenticate();
                 Yii::app()->user->login($identity, 86400 * 7);
             }
             $this->redirect(array('index/index'));
         }
     }
     $this->render("registration", array('user' => $user, 'profile' => $profile));
 }
コード例 #9
0
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $this->layout = '//layouts/login';
     $model = new RegistrationForm();
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'signup-form_id') {
         /* echo UActiveForm::validate($model);
            Yii::app()->end(); */
         $errors = CActiveForm::validate($model);
         echo $errors;
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect('/');
     } else {
         $this->redirect('/login');
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $model->verifyPassword = $model->password;
             if ($model->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UsersModule::encrypting(microtime() . $model->password);
                 $model->password = UsersModule::encrypting($model->password);
                 $model->verifyPassword = UsersModule::encrypting($model->verifyPassword);
                 $model->status = Yii::app()->getModule('users')->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     Yii::app()->queue->subscribe($model->id, null, "User.{$model->id}");
                     if (Yii::app()->getModule('users')->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         UsersModule::sendMail($model->email, UsersModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UsersModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     // wellcome email
                     $subject = Yii::t('email', 'Welcome');
                     $message = Yii::t('email', 'Welcome to <a href="{url}">{catalog}</a>.', array('{url}' => $this->createAbsoluteUrl('/'), '{catalog}' => Yii::app()->name));
                     SendMail::send($model->email, $subject, $message, true);
                     if ((Yii::app()->getModule('users')->loginNotActiv || Yii::app()->getModule('users')->activeAfterRegister && Yii::app()->getModule('users')->sendActivationMail == false) && Yii::app()->getModule('users')->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->getModule('users')->returnUrl);
                     } else {
                         if (!Yii::app()->getModule('users')->activeAfterRegister && !Yii::app()->getModule('users')->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Contact Admin to activate your account."));
                         } elseif (Yii::app()->getModule('users')->activeAfterRegister && Yii::app()->getModule('users')->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UsersModule::t('Login'), Yii::app()->getModule('users')->loginUrl))));
                         } elseif (Yii::app()->getModule('users')->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 // var_dump($model->errors);die();
             }
         }
         $this->render('/user/registration', array('model' => $model));
     }
 }
コード例 #10
0
 /**
  * Set default user states so the application won't crash
  * when trying to access these properies and they don't exist
  */
 public function init()
 {
     $cs = Yii::app()->clientScript;
     $baseUrl = $this->createFrontendUrl('/');
     $cs->registerCssFile($baseUrl . '/themes/boxomatic/admin/css/admin.css');
     $this->scriptLocations[Yii::app()->basePath . '/../public_html/themes/boxomatic/admin/'] = $this->createFrontendUrl('/') . '/themes/boxomatic/admin/';
     $this->nav_brand_label = CHtml::image('/themes/boxomatic/images/cog-leaf.png');
     if (!Yii::app()->user->hasState('user_id')) {
         Yii::app()->user->setState('user_id', false);
     }
     if (!Yii::app()->user->hasState('supplier_id')) {
         Yii::app()->user->setState('supplier_id', false);
     }
     if (!Yii::app()->user->hasState('shadow_id')) {
         Yii::app()->user->setState('shadow_id', false);
     }
     if (!Yii::app()->user->hasState('shadow_name')) {
         Yii::app()->user->setState('shadow_name', false);
     }
     //Test if the login key find the user and auto login.
     $key = Yii::app()->request->getParam('key');
     if ($key) {
         $User = User::model()->findByAttributes(array('auto_login_key' => $key), 'update_time > date_sub(NOW(), interval 7 day)');
         if ($User) {
             $identity = new UserIdentity($User->email, '');
             $identity->authenticate(false);
             Yii::app()->user->login($identity);
             $User->auto_login_key = '';
             $User->save(false);
         }
         //exit;
     }
 }
コード例 #11
0
ファイル: LoginForm.php プロジェクト: jessesiu/GigaDBV3
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         // we only want to authenticate when no input errors
         $identity = new UserIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
                 // 30 days
                 Yii::app()->user->login($identity, $duration);
                 break;
                 #				case UserIdentity::ERROR_USERNAME_INVALID:
                 #					$this->addError('username','Username is incorrect.');
                 #					break;
             #				case UserIdentity::ERROR_USERNAME_INVALID:
             #					$this->addError('username','Username is incorrect.');
             #					break;
             case UserIdentity::ERROR_USER_NOT_ACTIVATED:
                 $this->addError('username', 'User is not activated');
                 break;
             default:
                 // UserIdentity::ERROR_PASSWORD_INVALID
                 $this->addError('password', 'Either your Username or Password is incorrect.');
                 $this->addError('username', '');
                 break;
         }
     }
 }
コード例 #12
0
 /**
  * This is the action to handle login
  */
 public function actionLogin()
 {
     $data = $this->getInputAsJson();
     if (empty($data['username']) || empty($data['password'])) {
         $this->sendResponse(401, 'Please, fill up all username and password to login!');
     }
     // Authenticate user credentials
     $identity = new UserIdentity($data['username'], $data['password']);
     if ($identity->authenticate()) {
         Yii::app()->user->login($identity);
         $this->sendResponse(200, CJSON::encode(array('authenticated' => true)));
     } else {
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $error = 'Incorrect username';
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $error = 'Incorrect password';
                 break;
             case UserIdentity::ERROR_USER_IS_DELETED:
                 $error = 'This user is deleted';
                 break;
         }
         $this->sendResponse(401, $error);
     }
 }
コード例 #13
0
 function init()
 {
     // MFM CController
     parent::init();
     $app = Yii::app();
     if (isset($_POST['_lang'])) {
         $app->language = $_POST['_lang'];
         $app->session['_lang'] = $app->language;
     } else {
         if (isset($app->session['_lang'])) {
             $app->language = $app->session['_lang'];
         }
     }
     //-----------------------------
     if (!Yii::app()->user->isGuest) {
         $identity = new UserIdentity(Yii::app()->user->username, Yii::app()->user->password);
         $identity->authenticate(false);
         if ($identity->errorCode != ERROR_NONE) {
             Yii::app()->user->logout();
             Yii::app()->user->setState('status', User::STATUS_GUEST);
             $this->redirect(Yii::app()->homeUrl);
         }
     } else {
         Yii::app()->user->setState('status', User::STATUS_GUEST);
     }
 }
コード例 #14
0
ファイル: UserSettings.php プロジェクト: norayr/notabenoid
 public function change_pass($param, $options)
 {
     echo "<h3>change_pass</h3>";
     if (empty($this->{$param})) {
         return;
     }
     if ($this->hasErrors()) {
         return;
     }
     if (empty($this->new_pass)) {
         $this->addError("new_pass", "Введите новый пароль!");
         return;
     }
     if (!$this->validate(array("new_pass", "new_pass2"))) {
         return;
     }
     echo "<h3>check old pass</h3>";
     $ui = new UserIdentity(Yii::app()->user->login, $this->old_pass);
     if (!$ui->authenticate()) {
         $this->addError("old_pass", "Неверный пароль. Если вы не можете его вспомнить, вам <a href='/register/remind'>сюда</a>.");
     } else {
         echo "<p>check ok</p>";
         $this->pass = self::hashPass($this->new_pass);
     }
     echo "<h3>/change_pass</h3>";
 }
コード例 #15
0
ファイル: UserIdentityTest.php プロジェクト: dsyman2/X2CRM
 public function testAuthenticate()
 {
     // Test using user OR alias
     $tu = $this->users('testUser');
     $ui = new UserIdentity($tu->username, 'password');
     $this->assertEquals($tu->id, $ui->getUserModel()->id);
     $this->assertTrue($ui->authenticate());
     $ui = new UserIdentity($tu->userAlias, 'password');
     $this->assertEquals($tu->id, $ui->getUserModel()->id);
     $this->assertTrue($ui->authenticate());
     $tu->status = User::STATUS_INACTIVE;
     // Test incorrect password:
     $ui = new UserIdentity($tu->username, 'notthepassword');
     $this->assertFalse($ui->authenticate());
     $this->assertEquals(UserIdentity::ERROR_PASSWORD_INVALID, $ui->errorCode);
     // Test incorrect username:
     $ui = new UserIdentity('nousernamethatexistsoreverwillexistintheusersfixture', 'passwor');
     $this->assertFalse($ui->authenticate());
     $this->assertEquals(UserIdentity::ERROR_USERNAME_INVALID, $ui->errorCode);
     // Test lockout:
     $tu->update(array('status'));
     $ui = new UserIdentity($tu->username, 'password');
     $this->assertFalse($ui->authenticate());
     $this->assertEquals(UserIdentity::ERROR_DISABLED, $ui->errorCode);
 }
コード例 #16
0
ファイル: UserController.php プロジェクト: phainamikaze/miza
 public function actionLogin()
 {
     if (!empty($_POST) && $_POST['run'] === "login") {
         if ($identity === null) {
             $identity = new UserIdentity($_POST['username'], $_POST['password']);
             $identity->authenticate();
         }
         if ($identity->errorCode === UserIdentity::ERROR_NONE) {
             //$duration=$_POST['rememberme'] ? 3600*24*30 : 0; // 30 days
             $duration = 0;
             Yii::app()->user->login($identity);
             Yii::app()->user->login($identity, $duration);
             $this->redirect(Yii::app()->baseUrl . '/infrastructure/mylist');
         } else {
             if ($identity->errorCode === UserIdentity::ERROR_USERNAME_INVALID) {
                 $this->renderPartial('login', array('msgError' => "Invalid Username"));
             } else {
                 if ($identity->errorCode === UserIdentity::ERROR_PASSWORD_INVALID) {
                     $this->renderPartial('login', array('msgError' => "Invalid password", 'username' => $_POST['username']));
                 }
             }
         }
         //$this->renderPartial('login',array('msgError' => "none" ));
     } else {
         $this->renderPartial('login', array('msgError' => "none"));
     }
 }
コード例 #17
0
ファイル: UserLogin.php プロジェクト: alsvader/hackbanero
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0;
                 Yii::app()->user->login($identity, $duration);
                 break;
             case UserIdentity::ERROR_EMAIL_INVALID:
                 $this->addError("username", UserModule::t("Correo incorrecto"));
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError("username", UserModule::t("Nombre de usuario incorrecto"));
                 break;
             case UserIdentity::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", UserModule::t("Su cuenta no está activada"));
                 break;
             case UserIdentity::ERROR_STATUS_BAN:
                 $this->addError("status", UserModule::t("Su cuenta ha sido blockeada"));
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError("password", UserModule::t("Contraseña incorrecta"));
                 break;
         }
     }
 }
コード例 #18
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
                 // 30 days
                 Yii::app()->user->login($identity, $duration);
                 break;
             case UserIdentity::ERROR_EMAIL_INVALID:
                 $this->addError("username", UserModule::t("Email is incorrect."));
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError("username", UserModule::t("Username is incorrect. Please make sure you are using the secondary login details provided in your email"));
                 break;
             case UserIdentity::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", UserModule::t("You account is not activated."));
                 break;
             case UserIdentity::ERROR_STATUS_BAN:
                 $this->addError("status", UserModule::t("You account is blocked."));
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError("password", UserModule::t("Password is incorrect."));
                 break;
             case UserIdentity::ERROR_SERVER_ERROR:
                 $this->addError("status", UserModule::t("There is a server error. Please contact support"));
                 break;
             default:
                 $this->addError("status", UserModule::t("KUCH TO GADABAD HAI"));
                 break;
         }
     }
 }
コード例 #19
0
 public function handleBeginRequest($event)
 {
     if (Yii::app()->user->id == null) {
         $identity = new UserIdentity();
         if ($identity->authenticate()) {
             Yii::app()->user->login($identity);
         }
     }
     $app = Yii::app();
     if (isset($_POST['lang'])) {
         $app->language = $_POST['lang'];
         $app->user->setState('lang', $_POST['lang']);
         $cookie = new CHttpCookie('lang', $_POST['lang']);
         $cookie->expire = time() + 60 * 60 * 24 * 365;
         // (1 year)
         Yii::app()->request->cookies['lang'] = $cookie;
     } else {
         if ($app->user->hasState('lang')) {
             $app->language = $app->user->getState('lang');
         } else {
             if (isset(Yii::app()->request->cookies['lang'])) {
                 $app->language = Yii::app()->request->cookies['lang']->value;
             }
         }
     }
 }
コード例 #20
0
ファイル: AjaxLoginAction.php プロジェクト: CHILMEX/amocasion
 public function run()
 {
     // Parameters
     $username = $_REQUEST['popup_username'];
     $password = $_REQUEST['popup_password'];
     $rememberMe = $_REQUEST['popup_rememberMe'];
     if (isset($username)) {
         $identity = new UserIdentity($username, $password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $rememberMe ? 3600 * 24 * 30 : 0;
                 // 30 days
                 Yii::app()->user->login($identity, $duration);
                 $result["result"] = 0;
                 $result["message"] = Yii::t('amo', 'Login correct');
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $result["result"] = -1;
                 $result["message"] = Yii::t('amo', 'Username is not registered');
                 break;
             default:
                 // UserIdentity::ERROR_PASSWORD_INVALID
                 $result["result"] = -1;
                 $result["message"] = Yii::t('amo', 'Password is not valid');
                 break;
         }
     } else {
         $result["result"] = -1;
         $result["message"] = Yii::t('amo', 'No login info');
     }
     echo CJSON::encode($result);
     exit(0);
     // To avoid loggers append things to request
 }
コード例 #21
0
ファイル: CabinetController.php プロジェクト: Cranky4/npfs
 public function actionRegister()
 {
     $model = BaseActiveRecord::newModel('User', 'register');
     $modelClass = get_class($model);
     $this->performAjaxValidation($model, 'register-form');
     if (isset($_POST[$modelClass])) {
         $model->attributes = $_POST[$modelClass];
         //Создаем indentity раньше сохранения модели
         //т.к. после сохранения поле user_password измениться на хеш
         $identity = new UserIdentity($model->name, $model->user_password);
         $model->onAfterSave = array($this, 'sendRegisterMessage');
         if ($model->save()) {
             //если разрешено сразу авторизовать пользователя
             if (Yii::app()->getModule('user')->immediatelyAuthorization) {
                 //загружаем модель пользователя
                 $identity->authenticate();
                 //Сразу авторизуем пользователя
                 Yii::app()->user->login($identity);
                 Yii::app()->user->setFlash('registerSuccess', 'Регистрация успешно завершена.');
             } else {
                 Yii::app()->user->setFlash('registerSuccess', 'Регистрация успешно завершена. Теперь вы можете войти на сайт через форму авторизации.');
             }
             $this->redirect(Yii::app()->createUrl($this->getRedirectRouteAfterRegister()));
         }
     }
     $this->render('/register', array('model' => $model));
 }
コード例 #22
0
 public function actionLogin()
 {
     if (Yii::app()->user->isGuest) {
         $user = new CatalogUsersAuthConsole();
         if (!empty($_POST["CatalogUsersAuthConsole"])) {
             Yii::app()->page->title = "Авторизация";
             $user->setAttributes($_POST["CatalogUsersAuthConsole"]);
             if ($user->validate()) {
                 $identity = new UserIdentity($user->email, $user->password);
                 $identity->authenticate();
                 if (empty($identity->errorMessage)) {
                     Yii::app()->user->login($identity);
                     // Опрпделяем первый вход человека в личны кабинет
                     if (!empty(Yii::app()->session['redirect'])) {
                         $redirectUrl = Yii::app()->session['redirect'];
                         Yii::app()->session['redirect'] = "";
                         $this->redirect($redirectUrl);
                     }
                     $this->redirect($this->createUrl("/console"));
                 } else {
                     $user->addError("Ошибка авторизации", $identity->errorMessage);
                 }
             }
         }
         $this->render('login', array('form' => $user));
     } else {
         Yii::app()->page->title = "Административный кабинет";
         $this->render("room", array());
     }
 }
コード例 #23
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0;
                 Yii::app()->user->login($identity, $duration);
                 break;
             case UserIdentity::ERROR_EMAIL_INVALID:
                 $this->addError("username", AdminModule::t("Email anda salah."));
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError("username", AdminModule::t("Username anda salah."));
                 break;
             case UserIdentity::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", AdminModule::t("Akun anda belum aktif."));
                 break;
             case UserIdentity::ERROR_STATUS_BAN:
                 $this->addError("status", AdminModule::t("Akun anda sudah diblok."));
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError("password", AdminModule::t("Kata sandi anda salah."));
                 break;
         }
     }
 }
コード例 #24
0
ファイル: UserLogin.php プロジェクト: phiphi1992/fpthue
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0;
                 Yii::app()->user->login($identity, $duration);
                 break;
             case UserIdentity::ERROR_EMAIL_INVALID:
                 $this->addError("username", UserModule::t("Thông tin đăng nhập không chính xác."));
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError("username", UserModule::t("Thông tin đăng nhập không chính xác."));
                 break;
             case UserIdentity::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", UserModule::t("Thông tin đăng nhập không chính xác."));
                 break;
             case UserIdentity::ERROR_STATUS_BAN:
                 $this->addError("status", UserModule::t("Thông tin đăng nhập không chính xác."));
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError("password", UserModule::t("Thông tin đăng nhập không chính xác."));
                 break;
         }
     }
 }
コード例 #25
0
 /**
  * 登录验证
  */
 public function actionLogin()
 {
     $msg = $this->msgcode();
     $username = Yii::app()->request->getParam("username", "");
     //帐号
     $password = Yii::app()->request->getParam("password", "");
     //密码
     if ($username == "" || $password == "") {
         $msg['msg'] = "帐号密码不能为空";
     } else {
         $_identity = new UserIdentity($username, $password);
         $check_code = $_identity->authenticate();
         if ($check_code == 0) {
             if (Yii::app()->user->login($_identity, 0)) {
                 Yii::app()->user->setState('username', $_identity->getUserName());
                 Yii::app()->user->setState('time', time());
                 $this->msgsucc($msg);
             }
         } else {
             $user = AppBsAdmin::model()->findByPk($username);
             $pwd = AppBsPwd::model()->findByPk($username);
             if (!empty($user) && empty($pwd)) {
                 $pwdq = new AppBsPwd();
                 $pwdq->username = $username;
                 $pwdq->password = md5('123456');
                 $pwdq->save();
                 $msg['msg'] = "已为您初始化帐号,初始密码为123456,登录后请及时修改";
             } else {
                 $msg['msg'] = "验证失败";
             }
         }
     }
     echo json_encode($msg);
 }
コード例 #26
0
 public function actionLogin()
 {
     //redefine base admin layout to login-layout
     $this->layout = '/layout/base_admin_login';
     //if logged as admin - redirect to index page of administration panel
     if (Yii::app()->user->getState('role') == 'admin') {
         $this->redirect($this->createUrl('/admin/inlux/index'));
     }
     //if script continues and not redirected - get parameters from get/post request
     $password = Yii::app()->request->getParam('password', null);
     $login = Yii::app()->request->getParam('login', null);
     $error = Yii::app()->request->getParam('error', null);
     //if has error - render form with error message
     if ($error != null) {
         $this->render('login', array('error' => 'yes'));
     } elseif ($password == null || $login == null) {
         $this->render('login');
     } else {
         //create auth object using given password and login
         $userIdentity = new UserIdentity($login, $password);
         //if authentication passed
         if ($userIdentity->authenticate()) {
             //login (set special cookie)
             Yii::app()->user->login($userIdentity);
             //redirect to index
             $this->redirect($this->createUrl('/admin/inlux/index'));
         } else {
             //get error code
             $error_code = $userIdentity->errorCode;
             //redirect to error page
             $this->redirect($this->createUrl('/admin/inlux/login/error/1'));
         }
     }
 }
コード例 #27
0
ファイル: UserLogin.php プロジェクト: kosenka/yboard
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0;
                 Yii::app()->user->login($identity, $duration);
                 break;
             case UserIdentity::ERROR_EMAIL_INVALID:
                 $this->addError("username", t("Email is incorrect."));
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError("username", t("Username is incorrect."));
                 break;
             case UserIdentity::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", t("You account is not activated."));
                 break;
             case UserIdentity::ERROR_STATUS_BAN:
                 $this->addError("status", t("You account is blocked."));
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError("password", t("Password is incorrect."));
                 break;
         }
     }
 }
コード例 #28
0
 public function actionLogin()
 {
     $this->layout = '//layouts/admin/login';
     if (!Yii::app()->user->isGuest) {
         throw new CException(t('Вы уже авторизованы!'));
     }
     $model = new User(User::SCENARIO_LOGIN);
     $form = new Form('users.LoginForm', $model);
     $form->action = '';
     $form->cancel_button_show = false;
     $form->activeForm['enableAjaxValidation'] = false;
     $form->activeForm['clientOptions']['validateOnSubmit'] = false;
     $params = array("model" => $model, "error_code" => null, "form" => $form);
     if (isset($_POST["User"])) {
         $model->attributes = $_POST["User"];
         if ($model->validate()) {
             $remember_me = isset($_POST["User"]["remember_me"]) && $_POST["User"]["remember_me"] ? true : false;
             $identity = new UserIdentity($_POST["User"]["email"], $_POST["User"]["password"], $remember_me);
             if ($identity->authenticate(true)) {
                 $this->redirect(isset($_GET['redirect']) ? base64_decode($_GET['redirect']) : "/content/pageAdmin/manage");
             } else {
                 $params["error_code"] = $identity->errorCode;
             }
         }
     }
     $this->render("login", $params);
 }
コード例 #29
0
 /**
  * Creates account for new users
  */
 public function actionRegister()
 {
     if (!Yii::app()->user->isGuest) {
         Yii::app()->request->redirect('/');
     }
     $user = new User('register');
     $profile = new UserProfile();
     if (Yii::app()->request->isPostRequest && isset($_POST['User'], $_POST['UserProfile'])) {
         $user->attributes = $_POST['User'];
         $profile->attributes = $_POST['UserProfile'];
         $valid = $user->validate();
         $valid = $profile->validate() && $valid;
         if ($valid) {
             $user->save();
             $profile->save();
             $profile->setUser($user);
             // Add user to authenticated group
             Yii::app()->authManager->assign('Authenticated', $user->id);
             $this->addFlashMessage(Yii::t('UsersModule.core', 'Спасибо за регистрацию на нашем сайте.'));
             // Authenticate user
             $identity = new UserIdentity($user->username, $_POST['User']['password']);
             if ($identity->authenticate()) {
                 Yii::app()->user->login($identity, Yii::app()->user->rememberTime);
                 Yii::app()->request->redirect($this->createUrl('/users/profile/index'));
             }
         }
     }
     $this->render('register', array('user' => $user, 'profile' => $profile));
 }
コード例 #30
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     if (!Yii::app()->request->getIsAjaxRequest()) {
         $this->render('//mlogin');
     } else {
         $username = Yii::app()->request->getParam('username');
         $passwd = Yii::app()->request->getParam('passwd');
         $captcha = Yii::app()->request->getParam('captcha');
         $autologin = Yii::app()->request->getParam('autologin');
         $oValidate = new CaptchaExtendedAction($this, 'captcha');
         $bValidate = $oValidate->validate($captcha, false);
         if (ENV != 'dev' && !$bValidate) {
             $re = new ReturnInfo(FAIL_RET, '验证码错误');
             echo CJSON::encode($re);
             Yii::app()->end();
         }
         $identity = new UserIdentity($username, $passwd);
         $identity->authenticate();
         $user = Yii::app()->user;
         if (!$autologin) {
             $user->login($identity, 0);
         } else {
             $user->login($identity, 3600 * 24 * 30);
         }
         $rt = new ReturnInfo(SUCCESS_RET, 'login_success');
         echo CJSON::encode($rt);
     }
 }