Beispiel #1
0
 public function create($login, $details = NULL)
 {
     if (!preg_match('/^[a-zA-Z0-9\\.\\_\\-]+$/', $login)) {
         http_response_code(409);
         echo "Invalid username";
         return NULL;
     }
     $user = $this->find($login);
     if ($user != NULL) {
         http_response_code(409);
         echo "User already exists";
         return NULL;
     }
     if ($user == NULL && $this->useLdap()) {
         $user = $this->createFromLdap($login);
         if ($user != NULL) {
             Audit::log($this->current_user ? $this->current_user : $user, 'imported user ' . $user, $user);
         }
     }
     if ($user == NULL && $this->current_user != NULL && $this->current_user->isAdmin()) {
         if ($details == NULL) {
             $details = array('login' => $login);
         }
         $user = $this->users->create($details);
         if ($user == NULL) {
             http_response_code(500);
             echo "Failed to create user";
             die;
         } else {
             Audit::log($this->current_user, 'created user ' . $user, $user);
         }
     }
     if ($user == NULL) {
         http_response_code(403);
         echo "Access denied";
         die;
     }
     return $user;
 }
Beispiel #2
0
 /**
  * @param array  $data
  * @param int    $level
  * @param string $type The type of audit entry
  *
  * @return bool
  */
 function audit($data = [], $level = AuditLevels::INFO, $type = null)
 {
     return \Audit::log($data, $level, app('request'), $type);
 }