getBody(), true) ?? []; try { v::key('username', v::alnum(' ')->notEmpty()) ->key('password', v::stringType()->length(8, null)) ->key('email', v::email()) ->key('company_id', v::intType()->positive()) ->key('role_id', v::intType()->positive()) ->assert($body); } catch (ValidationException $e) { return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401); } $username = $body['username']; $password = $body['password']; $email = $body['email']; $company_id = (int) $body['company_id']; $role_id = (int) $body['role_id']; $userModel = new UserModel(); $userData = $userModel->createUser($username, $email, $password, $company_id, $role_id); if (!$userData) { return ResponseLib::sendFail("Username Already Exists or Creation Failed", [], "E_VALIDATE")->withStatus(400); } return ResponseLib::sendOk($userData, "S_CREATED"); } }