protected function AuthController::createDrupalUser in Auth0 Single Sign On 8.2
Same name and namespace in other branches
- 8 src/Controller/AuthController.php \Drupal\auth0\Controller\AuthController::createDrupalUser()
Create the Drupal user based on the Auth0 user profile.
Parameters
array $userInfo: The user info array.
Return value
\Drupal\user\Entity\User The Drupal user entity.
Throws
\Exception
1 call to AuthController::createDrupalUser()
- AuthController::signupUser in src/
Controller/ AuthController.php - Create or link a new user based on the auth0 profile.
File
- src/
Controller/ AuthController.php, line 987 - Contains \Drupal\auth0\Controller\AuthController.
Class
- AuthController
- Controller routines for auth0 authentication.
Namespace
Drupal\auth0\ControllerCode
protected function createDrupalUser(array $userInfo) {
$user_name_claim = $this->config
->get('auth0_username_claim');
if ($user_name_claim == '') {
$user_name_claim = 'nickname';
}
$user = User::create();
$user
->setPassword($this
->generatePassword(16));
$user
->enforceIsNew();
if (!empty($userInfo['email'])) {
$user
->setEmail($userInfo['email']);
}
else {
$user
->setEmail("change_this_email@" . uniqid() . ".com");
}
// If the username already exists, create a new random one.
$username = !empty($userInfo[$user_name_claim]) ? $userInfo[$user_name_claim] : $userInfo['user_id'];
if (user_load_by_name($username)) {
$username .= time();
}
$user
->setUsername($username);
$user
->activate();
$user
->save();
return $user;
}