PHP-Course/exam/api/Login/Login.php
2024-07-21 15:49:43 +02:00

27 lines
594 B
PHP

<?php
namespace Api\Login;
use Exception;
use Khofmann\Input\Input;
class Login
{
public function post()
{
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);
}
}
}
}