Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addNewUser($ES_Client, $username, $password, $fullname, $email, $function, $department, $access){
- auditLog($ES_Client, "Creating new user: ".$username.", ".$fullname.", ".$email.", ".$function.", ".$department.", ".$access);
- $checkIfUserExists = getUserDetails($ES_Client,$username)['hits']['total'];
- if($checkIfUserExists != 0){
- auditLog($ES_Client, "User ".$username." already exists! Operation aborted.");
- return -1;
- } else {
- $hashed_password = crypt($password);
- $userAddQuery= [
- 'index' => 'system',
- 'type' => 'users',
- 'body' => [
- 'username' => $username,
- 'password' => $hashed_password,
- 'fullname' => $fullname,
- 'email' => $email,
- 'function' => $function,
- 'department' => $department,
- 'access' => $access,
- 'lastlogin' => round(microtime(true) * 1000)
- ]
- ];
- try{
- $userAddResponse = $ES_Client->index($userAddQuery);
- if($userAddResponse['created'] == 1)
- {
- auditLog($ES_Client, "User ".$username." added successfully!");
- return 0;
- }
- else{
- auditLog($ES_Client, "Error adding user ".$username."! Did not receive acknowledgement from elastic.");
- return -1;
- }
- } catch(Exception $e) {
- auditLog($ES_Client, "Error adding user ".$username."! ".$e->getMessage());
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement