当前位置: 首页>>代码示例>>PHP>>正文


PHP UserIdentity::authenticate方法代码示例

本文整理汇总了PHP中UserIdentity::authenticate方法的典型用法代码示例。如果您正苦于以下问题:PHP UserIdentity::authenticate方法的具体用法?PHP UserIdentity::authenticate怎么用?PHP UserIdentity::authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserIdentity的用法示例。


在下文中一共展示了UserIdentity::authenticate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: login

 /**
  * 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();
 }
开发者ID:eneelkant,项目名称:oprecx-project,代码行数:12,代码来源:UserLoginForm.php

示例2: authenticate

 public function authenticate()
 {
     $this->_identity = new UserIdentity($this->username, $this->password);
     $this->_identity->modelName = 'common\\model\\Admin';
     if (!$this->_identity->authenticate()) {
         $this->addError('password', '用户或密码错误!');
     }
 }
开发者ID:wuhailin,项目名称:composer,代码行数:8,代码来源:LoginForm.php

示例3: login

 /**
  * 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;
     }
 }
开发者ID:DarkAiR,项目名称:test,代码行数:19,代码来源:LoginForm.php

示例4: authenticate

 /**
  * 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;
         }
     }
 }
开发者ID:Greka163,项目名称:Yii-blog-new,代码行数:30,代码来源:LoginForm.php

示例5: testUserIdentity

 public function testUserIdentity()
 {
     $oIden = new UserIdentity('', '');
     $this->assertFalse($oIden->authenticate());
     $oIden = new UserIdentity('admin', 'admin');
     $this->assertTrue($oIden->authenticate());
 }
开发者ID:rawaludin,项目名称:jenkins-yii,代码行数:7,代码来源:ExampleText.php

示例6: actionActivation

	/**
	 * 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.")));
		}
	}
开发者ID:rallin,项目名称:yii-user,代码行数:30,代码来源:ActivationController.php

示例7: authenticate

	/**
	 * 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;
			}
		}
	}
开发者ID:nizsheanez,项目名称:PolymorphCMS,代码行数:34,代码来源:UserLogin.php

示例8: actionRegister

 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));
 }
开发者ID:vetalded,项目名称:homelibrary16mbcom,代码行数:29,代码来源:IndexController.php

示例9: actionRegistration

 /**
  * 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));
     }
 }
开发者ID:Aplay,项目名称:myhistorypark_site,代码行数:63,代码来源:RegistrationController.php

示例10: init

 /**
  * 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;
     }
 }
开发者ID:snapfrozen,项目名称:boxomatic,代码行数:37,代码来源:BoxomaticController.php

示例11: authenticate

 /**
  * 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;
         }
     }
 }
开发者ID:jessesiu,项目名称:GigaDBV3,代码行数:33,代码来源:LoginForm.php

示例12: actionLogin

 /**
  * 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);
     }
 }
开发者ID:schlypel,项目名称:YiiBackboneBoilerplate,代码行数:29,代码来源:SiteController.php

示例13: init

 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);
     }
 }
开发者ID:smoothcoder,项目名称:DISCARDEDYiiblog,代码行数:26,代码来源:BaseController.php

示例14: change_pass

 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>";
 }
开发者ID:norayr,项目名称:notabenoid,代码行数:26,代码来源:UserSettings.php

示例15: testAuthenticate

 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);
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:25,代码来源:UserIdentityTest.php


注:本文中的UserIdentity::authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。