mirror of
https://github.com/standardebooks/web.git
synced 2025-07-21 06:45:14 -04:00
Convert some constants to enums
This commit is contained in:
parent
06425d3dd6
commit
ee7c8343dd
52 changed files with 282 additions and 268 deletions
|
@ -8,8 +8,8 @@ if($GLOBALS['User'] !== null){
|
|||
exit();
|
||||
}
|
||||
|
||||
$email = HttpInput::Str(SESSION, 'email');
|
||||
$redirect = HttpInput::Str(SESSION, 'redirect') ?? HttpInput::Str(GET, 'redirect');
|
||||
$email = HttpInput::Str(HttpVariableSource::Session, 'email');
|
||||
$redirect = HttpInput::Str(HttpVariableSource::Session, 'redirect') ?? HttpInput::Str(HttpVariableSource::Get, 'redirect');
|
||||
|
||||
$exception = $_SESSION['exception'] ?? null;
|
||||
$passwordRequired = false;
|
||||
|
|
|
@ -1,40 +1,38 @@
|
|||
<?
|
||||
use function Safe\preg_match;
|
||||
use function Safe\session_unset;
|
||||
|
||||
if(HttpInput::RequestMethod() != HTTP_POST){
|
||||
http_response_code(405);
|
||||
exit();
|
||||
}
|
||||
|
||||
session_start();
|
||||
|
||||
$requestType = HttpInput::RequestType();
|
||||
|
||||
$session = new Session();
|
||||
$email = HttpInput::Str(POST, 'email');
|
||||
$password = HttpInput::Str(POST, 'password');
|
||||
$redirect = HttpInput::Str(POST, 'redirect');
|
||||
|
||||
try{
|
||||
HttpInput::ValidateRequestMethod([HttpMethod::Post]);
|
||||
|
||||
session_start();
|
||||
|
||||
$requestType = HttpInput::RequestType();
|
||||
|
||||
$session = new Session();
|
||||
$email = HttpInput::Str(HttpVariableSource::Post, 'email');
|
||||
$password = HttpInput::Str(HttpVariableSource::Post, 'password');
|
||||
$redirect = HttpInput::Str(HttpVariableSource::Post, 'redirect');
|
||||
|
||||
if($redirect === null){
|
||||
$redirect = '/';
|
||||
}
|
||||
|
||||
$session->Create($email, $password);
|
||||
|
||||
if($requestType == WEB){
|
||||
session_unset();
|
||||
|
||||
if($requestType == HttpRequestType::Web){
|
||||
http_response_code(303);
|
||||
header('Location: ' . $redirect);
|
||||
}
|
||||
else{
|
||||
// Access via REST api; 201 CREATED with location
|
||||
// Access via HttpRequestType::Rest api; 201 CREATED with location
|
||||
http_response_code(201);
|
||||
header('Location: ' . $session->Url);
|
||||
}
|
||||
}
|
||||
catch(Exceptions\AppException $ex){
|
||||
if($requestType == WEB){
|
||||
catch(Exceptions\InvalidLoginException | Exceptions\PasswordRequiredException $ex){
|
||||
if($requestType == HttpRequestType::Web){
|
||||
$_SESSION['email'] = $email;
|
||||
$_SESSION['redirect'] = $redirect;
|
||||
$_SESSION['exception'] = $ex;
|
||||
|
@ -44,7 +42,7 @@ catch(Exceptions\AppException $ex){
|
|||
header('Location: /sessions/new');
|
||||
}
|
||||
else{
|
||||
// Access via REST api; 422 Unprocessable Entity
|
||||
// Access via HttpRequestType::Rest api; 422 Unprocessable Entity
|
||||
http_response_code(422);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue