You are here

public function GetServices::createNewUser in Simple Node Importer 8

2 calls to GetServices::createNewUser()
GetServices::getUserByEmail in src/Services/GetServices.php
GetServices::getUserByUsername in src/Services/GetServices.php

File

src/Services/GetServices.php, line 444

Class

GetServices

Namespace

Drupal\simple_node_importer\Services

Code

public function createNewUser(string $email = NULL, string $uname = NULL) {
  if (!empty($email)) {
    $today = date('dmy');
    $username = explode('@', $email);
    $userId = $this
      ->getUserByUsername($username[0]);
    if ($userId && is_int($userId)) {
      $uname = $username . $today;
    }
    else {
      $uname = $username;
    }
  }
  elseif (!empty($uname)) {
    $email = '';
  }
  $user = User::create([
    'name' => $uname,
    'mail' => $email,
    'pass' => user_password(10),
    'status' => 1,
    'roles' => [
      'authenticated',
    ],
  ]);
  return $user
    ->save();
}