diff --git a/exam/api/Login/Login.php b/exam/api/Login/Login.php index a98a5a5..0fbcca6 100644 --- a/exam/api/Login/Login.php +++ b/exam/api/Login/Login.php @@ -15,7 +15,7 @@ class Login extends Api $email = Input::post("email"); if (empty($email)) throw new Exception("Missing email", 400); $password = Input::post("password"); - if (empty($password)) throw new Exception("Missing Password", 400); + if (empty($password)) throw new Exception("Missing password", 400); try { return Response::json(User::logIn($email, $password)); @@ -24,9 +24,9 @@ class Login extends Api case "Failed": throw new Exception("Login failed", 500); case "NotFound": - throw new Exception("User not Found", 404); + throw new Exception("User not found", 404); case "Invalid": - throw new Exception("Invalid Username or Password", 401); + throw new Exception("Invalid username or password", 401); default: throw $err; } diff --git a/exam/api/Register/Register.php b/exam/api/Register/Register.php new file mode 100644 index 0000000..bc38868 --- /dev/null +++ b/exam/api/Register/Register.php @@ -0,0 +1,33 @@ +getMessage()) { + case "Duplicate": + throw new Exception("A user with this username or email already exists", 400); + default: + throw $err; + } + } + } +} diff --git a/exam/api/User/User.php b/exam/api/User/User.php index b2b1868..4683d8e 100644 --- a/exam/api/User/User.php +++ b/exam/api/User/User.php @@ -18,7 +18,7 @@ class User extends Api } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": - throw new Exception("User not Found", 404); + throw new Exception("User not found", 404); default: throw $err; } @@ -36,7 +36,7 @@ class User extends Api } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": - throw new Exception("User not Found", 404); + throw new Exception("User not found", 404); case "FailedUsername": throw new Exception("Failed to update username", 500); case "FailedPassword": @@ -61,7 +61,7 @@ class User extends Api } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": - throw new Exception("User not Found", 404); + throw new Exception("User not found", 404); case "FailedUsername": throw new Exception("Failed to update username", 500); case "FailedPassword": @@ -81,7 +81,7 @@ class User extends Api } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": - throw new Exception("User not Found", 404); + throw new Exception("User not found", 404); default: throw $err; } diff --git a/exam/api/docs/api.yaml b/exam/api/docs/api.yaml index e02ccca..6f0b20c 100644 --- a/exam/api/docs/api.yaml +++ b/exam/api/docs/api.yaml @@ -28,13 +28,13 @@ paths: Success: value: true 400: - description: Missing Fields + description: Missing fields content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" examples: - Missing Fields: + Missing fields: value: { "message": "Missing email" } 401: description: Invalid credentials @@ -43,17 +43,17 @@ paths: schema: $ref: "#/components/schemas/ErrorResponse" examples: - Invalid Username or Password: - value: { "message": "Invalid Username or Password" } + Invalid username or password: + value: { "message": "Invalid username or password" } 404: - description: User not Found + description: User not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" examples: - User not Found: - value: { "message": "User not Found" } + User not found: + value: { "message": "User not found" } 500: description: Failed content: @@ -68,7 +68,7 @@ paths: /logout: post: summary: Logout - description: Log out User + description: Log out user security: - BasicAuth: [] responses: @@ -83,6 +83,42 @@ paths: value: true tags: - Login/Logout + /register: + post: + summary: Register + description: Register a new user + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/RegisterRequest" + responses: + 200: + description: Success + content: + application/json: + schema: + $ref: "#/components/schemas/BooleanResponse" + examples: + Success: + value: true + 400: + description: Missing fields or duplicate + content: + application/json: + schema: + $ref: "#/components/schemas/ErrorResponse" + examples: + Missing fields: + value: { "message": "Missing email" } + Duplicate: + value: + { + "message": "A user with this username or email already exists", + } + tags: + - Register /user{id}: get: summary: Get user @@ -116,14 +152,14 @@ paths: "isAdmin": true, } 404: - description: User not Found + description: User not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" examples: - User not Found: - value: { "message": "User not Found" } + User not found: + value: { "message": "User not found" } tags: - User patch: @@ -158,14 +194,14 @@ paths: Success: value: true 404: - description: User not Found + description: User not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" examples: - User not Found: - value: { "message": "User not Found" } + User not found: + value: { "message": "User not found" } 500: description: Update failed content: @@ -173,7 +209,7 @@ paths: schema: $ref: "#/components/schemas/ErrorResponse" examples: - User not Found: + User not found: value: { "message": "Failed to update username" } tags: - User @@ -202,14 +238,14 @@ paths: Success: value: true 404: - description: User not Found + description: User not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" examples: - User not Found: - value: { "message": "User not Found" } + User not found: + value: { "message": "User not found" } tags: - User @@ -263,6 +299,19 @@ components: image: type: string format: binary + RegisterRequest: + type: object + required: + - username + - email + - password + properties: + username: + type: string + email: + type: string + password: + type: string securitySchemes: BasicAuth: type: apiKey @@ -270,4 +319,5 @@ components: in: header tags: - name: Login/Logout + - name: Register - name: User diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index 40e5c7d..1541416 100644 --- a/exam/api/docs/index.html +++ b/exam/api/docs/index.html @@ -366,7 +366,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ -

Log in user

Request Body schema: application/json
required
username
required
string
password
required
string

Responses

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string"
}

Response samples

Content type
application/json
true

Logout

Log out User

+

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string"
}

Response samples

Content type
application/json
true

Logout

Log out user

Authorizations:
BasicAuth

Responses

Response samples

Content type
application/json
true

User

Get user

Response samples

Content type
application/json
true

Register

Register

Register a new user

+
Request Body schema: application/json
required
username
required
string
email
required
string
password
required
string

Responses

Request samples

Content type
application/json
{
  • "username": "string",
  • "email": "string",
  • "password": "string"
}

Response samples

Content type
application/json
true

User

Get user

Get user by ID

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

Responses

Response samples

Content type
application/json
{
  • "id": 1,
  • "username": "Admin",
  • "status": 1,
  • "email": "marvin@zedat.fu-berlin.de",
  • "image": "profilbilder\\/admin.svg",
  • "isAdmin": true
}

Update user

404

User not found

+

Response samples

Content type
application/json
{
  • "id": 1,
  • "username": "Admin",
  • "status": 1,
  • "email": "marvin@zedat.fu-berlin.de",
  • "image": "profilbilder\\/admin.svg",
  • "isAdmin": true
}

Update user

Update user with ID. Fields are updated in order username, password, image. If one fails, subsequent are not updated.
Use special ID self to update logged in user.
Requires logged in user to have admin permissions for any ID other than self.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

Request Body schema: application/json
username
string
password
string
image
string <binary>

Responses

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string",
  • "image": "string"
}

Response samples

Content type
application/json
true

Delete user

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string",
  • "image": "string"
}

Response samples

Content type
application/json
true

Delete user

Delete user with ID.
Requires logged in user to have admin permissions.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

Responses

Response samples

Content type
application/json
true
+

Response samples

Content type
application/json
true