diff --git a/exam/.htaccess b/exam/.htaccess index 9d3bd7c..6f932f6 100644 --- a/exam/.htaccess +++ b/exam/.htaccess @@ -14,11 +14,6 @@ RewriteRule ^phpCourse/exam/vendor/.* index.php [L,NC] RewriteRule ^phpCourse/exam/routes/.* index.php [L,NC] RewriteRule ^phpCourse/exam/react/.* index.php [L,NC] -RewriteCond %{REQUEST_FILENAME} -f -RewriteCond %{REQUEST_FILENAME} !/uploads/.* -RewriteCond %{REQUEST_FILENAME} !/dist/.* -RewriteRule ^ dist [L,NC] - ## ## API routes ## @@ -32,4 +27,10 @@ RewriteRule ^ api/index.php [L,NC,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !/api/docs RewriteCond %{REQUEST_FILENAME} !/dist -RewriteRule ^ dist [L,NC,QSA] \ No newline at end of file +RewriteRule ^ dist [L,NC,QSA] + +RewriteCond %{REQUEST_FILENAME} -f +RewriteCond %{REQUEST_FILENAME} !/storage/.* +RewriteCond %{REQUEST_FILENAME} !/dist/.* +RewriteCond %{REQUEST_FILENAME} !/api/docs +RewriteRule ^ dist [L,NC] \ No newline at end of file diff --git a/exam/api/User/User.php b/exam/api/User/User.php index e8ce88c..aa65bb0 100644 --- a/exam/api/User/User.php +++ b/exam/api/User/User.php @@ -45,4 +45,29 @@ class User } } } + + public function postSelf() + { + $token = Input::header("token"); + $username = Input::post("username"); + $password = Input::post("password"); + $image = Input::file("image"); + + try { + return json_encode(MUser::getByToken($token)->update($username, $password, $image)); + } catch (Exception $err) { + switch ($err->getMessage()) { + case "NotFound": + throw new Exception("User not Found", 404); + case "FailedUsername": + throw new Exception("Failed to update username", 500); + case "FailedPassword": + throw new Exception("Failed to update password", 500); + case "FailedImage": + throw new Exception("Failed to update image", 500); + default: + throw $err; + } + } + } } diff --git a/exam/api/docs/api.yaml b/exam/api/docs/api.yaml index e4205b3..dc48c0c 100644 --- a/exam/api/docs/api.yaml +++ b/exam/api/docs/api.yaml @@ -128,7 +128,10 @@ paths: - User post: summary: Update user - description: Update user with ID. Fields are updated in order username,password,image. If one fails, subsequent are not updated + description: + 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.
security: - BasicAuth: [] parameters: @@ -228,6 +231,7 @@ components: type: string image: type: string + format: binary securitySchemes: BasicAuth: type: apiKey diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index 8a3853b..c519119 100644 --- a/exam/api/docs/index.html +++ b/exam/api/docs/index.html @@ -408,11 +408,11 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

Success

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

+

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

Responses

Request samples

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

Response samples

Content type
application/json
true