diff --git a/exam/api/Login/Login.php b/exam/api/Login/Login.php index e0d43c2..894f369 100644 --- a/exam/api/Login/Login.php +++ b/exam/api/Login/Login.php @@ -2,11 +2,25 @@ namespace Api\Login; +use Exception; +use Khofmann\Input\Input; + class Login { public function post() { - echo "LOGIN HANDLER post"; - print_r(input()->all()); + try { + $response = \Khofmann\Models\User\User::logIn(Input::post("email"), Input::post("password")); + return json_encode($response); + } catch (Exception $err) { + switch ($err->getMessage()) { + case "Failed": + throw new Exception("Login failed", 500); + case "NotFound": + throw new Exception("User not Found", 404); + case "Invalid": + throw new Exception("Invalid Username or Password", 401); + } + } } } diff --git a/exam/api/Logout/Logout.php b/exam/api/Logout/Logout.php index b325ee1..fb13a51 100644 --- a/exam/api/Logout/Logout.php +++ b/exam/api/Logout/Logout.php @@ -2,11 +2,13 @@ namespace Api\Logout; +use \Khofmann\Models\User\User; + class Logout { public function post() { - echo "LOGOUT HANDLER post"; - print_r(input()->all()); + $token = request()->getHeader("token"); + return json_decode(User::getByToken($token)->logOut($token)); } } diff --git a/exam/api/docs/api.yaml b/exam/api/docs/api.yaml index 2b42c8d..b147bab 100644 --- a/exam/api/docs/api.yaml +++ b/exam/api/docs/api.yaml @@ -28,7 +28,7 @@ paths: Success: value: true 401: - description: Failed + description: Invalid credentials content: application/json: schema: @@ -37,7 +37,7 @@ paths: Invalid Username or Password: value: { "message": "Invalid Username or Password" } 404: - description: Failed + description: User not Found content: application/json: schema: @@ -45,18 +45,23 @@ paths: examples: User not Found: value: { "message": "User not Found" } + 500: + description: Failed + content: + application/json: + schema: + $ref: "#/components/schemas/ErrorResponse" + examples: + Failed: + value: { "message": "Login failed" } tags: - Login/Logout /logout: post: summary: Logout description: Log out User - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/LogoutRequest" + security: + - BasicAuth: [] responses: 200: description: Success @@ -98,13 +103,6 @@ components: type: string password: type: string - LogoutRequest: - type: object - required: - - token - properties: - token: - type: string securitySchemes: BasicAuth: type: apiKey diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index 77b521d..4b00ab1 100644 --- a/exam/api/docs/index.html +++ b/exam/api/docs/index.html @@ -52,7 +52,8 @@ data-styled.g14[id="sc-jCbFiK"]{content:"hSvuOo,"}/*!sc*/ .ezFOZv polygon{fill:#d41f1c;}/*!sc*/ .iMxoRf{height:20px;width:20px;min-width:20px;vertical-align:middle;float:right;transition:transform 0.2s ease-out;transform:rotateZ(0);}/*!sc*/ .iMxoRf polygon{fill:white;}/*!sc*/ -data-styled.g15[id="sc-cBYhjr"]{content:"gUrACV,fqtTpb,ezFOZv,iMxoRf,"}/*!sc*/ +.dJanPw{height:1.3em;width:1.3em;min-width:1.3em;vertical-align:middle;transition:transform 0.2s ease-out;transform:rotateZ(-90deg);}/*!sc*/ +data-styled.g15[id="sc-cBYhjr"]{content:"gUrACV,fqtTpb,ezFOZv,iMxoRf,dJanPw,"}/*!sc*/ .gbdrVc{border-left:1px solid #7c7cbb;box-sizing:border-box;position:relative;padding:10px 10px 10px 0;}/*!sc*/ @media screen and (max-width: 50rem){.gbdrVc{display:block;overflow:hidden;}}/*!sc*/ tr:first-of-type>.gbdrVc,tr.last>.gbdrVc{border-left-width:0;background-position:top left;background-repeat:no-repeat;background-size:1px 100%;}/*!sc*/ @@ -227,6 +228,29 @@ data-styled.g62[id="sc-hrDJJk"]{content:"gLEAmN,"}/*!sc*/ .dHStET a:visited{color:#32329f;}/*!sc*/ .dHStET a:hover{color:#6868cf;text-decoration:auto;}/*!sc*/ data-styled.g70[id="sc-iNJlaU"]{content:"dHStET,"}/*!sc*/ +.fyveIh:after{content:' and ';font-weight:normal;}/*!sc*/ +.fyveIh:last-child:after{content:none;}/*!sc*/ +.fyveIh a{text-decoration:auto;color:#32329f;}/*!sc*/ +.fyveIh a:visited{color:#32329f;}/*!sc*/ +.fyveIh a:hover{color:#6868cf;text-decoration:auto;}/*!sc*/ +data-styled.g80[id="sc-blcnQh"]{content:"fyveIh,"}/*!sc*/ +.lkBZak{white-space:nowrap;}/*!sc*/ +.lkBZak:after{content:' or ';white-space:pre;}/*!sc*/ +.lkBZak:last-child:after,.lkBZak:only-child:after{content:none;}/*!sc*/ +.lkBZak a{text-decoration:auto;color:#32329f;}/*!sc*/ +.lkBZak a:visited{color:#32329f;}/*!sc*/ +.lkBZak a:hover{color:#6868cf;text-decoration:auto;}/*!sc*/ +data-styled.g81[id="sc-iHlJgr"]{content:"lkBZak,"}/*!sc*/ +.febKCY{flex:1 1 auto;cursor:pointer;}/*!sc*/ +data-styled.g82[id="sc-jHofgq"]{content:"febKCY,"}/*!sc*/ +.juVMxG{width:75%;text-overflow:ellipsis;border-radius:4px;overflow:hidden;}/*!sc*/ +@media screen and (max-width: 50rem){.juVMxG{margin-top:10px;}}/*!sc*/ +data-styled.g83[id="sc-iRFtIJ"]{content:"juVMxG,"}/*!sc*/ +.eGMvsx{display:inline-block;margin:0;}/*!sc*/ +data-styled.g84[id="sc-jRHPII"]{content:"eGMvsx,"}/*!sc*/ +.cCfxdS{width:100%;display:flex;margin:1em 0;flex-direction:row;}/*!sc*/ +@media screen and (max-width: 50rem){.cCfxdS{flex-direction:column;}}/*!sc*/ +data-styled.g85[id="sc-hWiVxH"]{content:"cCfxdS,"}/*!sc*/ .edbYXQ{margin-top:0;margin-bottom:0.5em;}/*!sc*/ data-styled.g91[id="sc-gjHHYa"]{content:"edbYXQ,"}/*!sc*/ .cwcfQE{border:1px solid #32329f;color:#32329f;font-weight:normal;margin-left:0.5em;padding:4px 8px 4px;display:inline-block;text-decoration:none;cursor:pointer;}/*!sc*/ @@ -363,17 +387,19 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD">

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

Request samples

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

Response samples

Content type
application/json
true

Logout

Log out User

-
Request Body schema: application/json
required
token
required
string

Responses

Request samples

Content type
application/json
{
  • "token": "string"
}

Response samples

Content type
application/json
true

Users

Posts

+

Response samples

Content type
application/json
true

Users

Posts