Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. function addNewUser($ES_Client, $username, $password, $fullname, $email, $function, $department, $access){
  2. auditLog($ES_Client, "Creating new user: ".$username.", ".$fullname.", ".$email.", ".$function.", ".$department.", ".$access);
  3. $checkIfUserExists = getUserDetails($ES_Client,$username)['hits']['total'];
  4. if($checkIfUserExists != 0){
  5. auditLog($ES_Client, "User ".$username." already exists! Operation aborted.");
  6. return -1;
  7. } else {
  8. $hashed_password = crypt($password);
  9. $userAddQuery= [
  10. 'index' => 'system',
  11. 'type' => 'users',
  12. 'body' => [
  13. 'username' => $username,
  14. 'password' => $hashed_password,
  15. 'fullname' => $fullname,
  16. 'email' => $email,
  17. 'function' => $function,
  18. 'department' => $department,
  19. 'access' => $access,
  20. 'lastlogin' => round(microtime(true) * 1000)
  21. ]
  22. ];
  23. try{
  24. $userAddResponse = $ES_Client->index($userAddQuery);
  25. if($userAddResponse['created'] == 1)
  26. {
  27. auditLog($ES_Client, "User ".$username." added successfully!");
  28. return 0;
  29. }
  30. else{
  31. auditLog($ES_Client, "Error adding user ".$username."! Did not receive acknowledgement from elastic.");
  32. return -1;
  33. }
  34. } catch(Exception $e) {
  35. auditLog($ES_Client, "Error adding user ".$username."! ".$e->getMessage());
  36. return -1;
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement