當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserIdentity::getUserModel方法代碼示例

本文整理匯總了PHP中UserIdentity::getUserModel方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserIdentity::getUserModel方法的具體用法?PHP UserIdentity::getUserModel怎麽用?PHP UserIdentity::getUserModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UserIdentity的用法示例。


在下文中一共展示了UserIdentity::getUserModel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: login

 /**
  * Logs a user in.
  *
  * If $rememberMe is set to `true`, the user will be logged in for the duration specified by the
  * [rememberedUserSessionDuration](http://craftcms.com/docs/config-settings#rememberedUserSessionDuration)
  * config setting. Otherwise it will last for the duration specified by the
  * [userSessionDuration](http://craftcms.com/docs/config-settings#userSessionDuration)
  * config setting.
  *
  * @param string $username   The user’s username.
  * @param string $password   The user’s submitted password.
  * @param bool   $rememberMe Whether the user should be remembered.
  *
  * @throws Exception
  * @return bool Whether the user was logged in successfully.
  */
 public function login($username, $password, $rememberMe = false)
 {
     // Require a userAgent string and an IP address to help prevent direct socket connections from trying to login.
     if (!craft()->request->userAgent || !$_SERVER['REMOTE_ADDR']) {
         Craft::log('Someone tried to login with loginName: ' . $username . ', without presenting an IP address or userAgent string.', LogLevel::Warning);
         $this->logout(true);
         $this->requireLogin();
     }
     // Validate the username/password first.
     $usernameModel = new UsernameModel();
     $passwordModel = new PasswordModel();
     $usernameModel->username = $username;
     $passwordModel->password = $password;
     // Validate the models.
     if ($usernameModel->validate() && $passwordModel->validate()) {
         $this->_identity = new UserIdentity($username, $password);
         // Did we authenticate?
         if ($this->_identity->authenticate()) {
             return $this->loginByUserId($this->_identity->getUserModel()->id, $rememberMe, true);
         }
     }
     Craft::log($username . ' tried to log in unsuccessfully.', LogLevel::Warning);
     return false;
 }
開發者ID:codeforamerica,項目名稱:oakland-beta,代碼行數:40,代碼來源:UserSessionService.php


注:本文中的UserIdentity::getUserModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。