本文整理汇总了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;
}