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


PHP AuthService::setAuthenticatedUser方法代码示例

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


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

示例1: createUser

 /**
  * Creates a new user
  *
  * @param  Array $params
  * @return The created user
  * @throws InvalidModelException
  * @throws ExistingUserException
  */
 public function createUser($params, $setAsAuthenticated = true, $role = User::ROLE_USER, $userType = null)
 {
     if ($userType == null) {
         $userType = $this->userClass;
     }
     // Check if there's a user with this email first.
     $select = $this->dbService->select();
     $select->from(strtolower($userType), '*')->where('username=?', $params['username'])->orWhere('email=?', $params['email']);
     $existing = $this->dbService->getObject($select, $userType);
     if ($existing) {
         throw new ExistingUserException($params['username'] . ' already exists');
     }
     $newPass = null;
     if (isset($params['password'])) {
         $newPass = $params['password'];
     }
     $params['role'] = $role;
     // Create a user with initial information
     $user = $userType;
     $user = new $user();
     $user->generateSaltedPassword($params['password']);
     unset($params['password']);
     $user->bind($params);
     $validator = new ModelValidator();
     if (!$validator->isValid($user)) {
         throw new InvalidModelException($validator->getMessages());
     }
     // so now we save the user, then reset their password which emails,
     // then we set them as the authenticated user.
     if ($this->dbService->createObject($user)) {
         $this->trackerService->track('create-user', $user->id);
         if ($setAsAuthenticated) {
             $this->authService->setAuthenticatedUser($user);
         }
         return $user;
     }
     return null;
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:46,代码来源:UserService.php


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