当前位置: 首页>>代码示例>>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;未经允许,请勿转载。