34 lines
820 B
PHP
34 lines
820 B
PHP
<?php
|
|
|
|
namespace Api\Login;
|
|
|
|
use Exception;
|
|
use Khofmann\Input\Input;
|
|
|
|
class Login
|
|
{
|
|
public function post()
|
|
{
|
|
$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);
|
|
|
|
try {
|
|
$response = \Khofmann\Models\User\User::logIn($email, $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);
|
|
default:
|
|
throw $err;
|
|
}
|
|
}
|
|
}
|
|
}
|