Skip to content

Commit

Permalink
build for #901 and #906
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Oct 30, 2022
1 parent 06834e9 commit a68b385
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions api.include.php
Expand Up @@ -8320,6 +8320,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$passwordLength = $this->getProperty('passwordLength', '12');
$pkName = $table->getPk()->getName();
$registerUser = $this->getProperty('registerUser', '');
$loginAfterRegistration = $this->getProperty('loginAfterRegistration', '');
$condition = new ColumnCondition($usernameColumn, 'eq', $username);
$returnedColumns = $this->getProperty('returnedColumns', '');
if (!$returnedColumns) {
Expand All @@ -8334,6 +8335,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if (!$registerUser) {
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
}
if(strlen(trim($username)) == 0){
return $this->responder->error(ErrorCode::USERNAME_EMPTY, $username);
}
if (strlen($password) < $passwordLength) {
return $this->responder->error(ErrorCode::PASSWORD_TOO_SHORT, $passwordLength);
}
Expand All @@ -8348,8 +8352,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$this->db->createSingle($table, $data);
$users = $this->db->selectAll($table, $columnNames, $condition, $columnOrdering, 0, 1);
foreach ($users as $user) {
unset($user[$passwordColumnName]);
return $this->responder->success($user);
if($loginAfterRegistration){
if (!headers_sent()) {
session_regenerate_id(true);
}
unset($user[$passwordColumnName]);
$_SESSION['user'] = $user;
return $this->responder->success($user);
} else {
unset($user[$passwordColumnName]);
return $this->responder->success($user);
}
}
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
}
Expand Down Expand Up @@ -11070,6 +11083,7 @@ class ErrorCode
const PAGINATION_FORBIDDEN = 1019;
const USER_ALREADY_EXIST = 1020;
const PASSWORD_TOO_SHORT = 1021;
const USERNAME_EMPTY = 1022;

private $values = [
0000 => ["Success", ResponseFactory::OK],
Expand All @@ -11095,6 +11109,7 @@ class ErrorCode
1019 => ["Pagination forbidden", ResponseFactory::FORBIDDEN],
1020 => ["User '%s' already exists", ResponseFactory::CONFLICT],
1021 => ["Password too short (<%d characters)", ResponseFactory::UNPROCESSABLE_ENTITY],
1022 => ["Username is empty or only whitespaces", ResponseFactory::UNPROCESSABLE_ENTITY],
9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
];

Expand Down
19 changes: 17 additions & 2 deletions api.php
Expand Up @@ -8320,6 +8320,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$passwordLength = $this->getProperty('passwordLength', '12');
$pkName = $table->getPk()->getName();
$registerUser = $this->getProperty('registerUser', '');
$loginAfterRegistration = $this->getProperty('loginAfterRegistration', '');
$condition = new ColumnCondition($usernameColumn, 'eq', $username);
$returnedColumns = $this->getProperty('returnedColumns', '');
if (!$returnedColumns) {
Expand All @@ -8334,6 +8335,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if (!$registerUser) {
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
}
if(strlen(trim($username)) == 0){
return $this->responder->error(ErrorCode::USERNAME_EMPTY, $username);
}
if (strlen($password) < $passwordLength) {
return $this->responder->error(ErrorCode::PASSWORD_TOO_SHORT, $passwordLength);
}
Expand All @@ -8348,8 +8352,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$this->db->createSingle($table, $data);
$users = $this->db->selectAll($table, $columnNames, $condition, $columnOrdering, 0, 1);
foreach ($users as $user) {
unset($user[$passwordColumnName]);
return $this->responder->success($user);
if($loginAfterRegistration){
if (!headers_sent()) {
session_regenerate_id(true);
}
unset($user[$passwordColumnName]);
$_SESSION['user'] = $user;
return $this->responder->success($user);
} else {
unset($user[$passwordColumnName]);
return $this->responder->success($user);
}
}
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
}
Expand Down Expand Up @@ -11070,6 +11083,7 @@ class ErrorCode
const PAGINATION_FORBIDDEN = 1019;
const USER_ALREADY_EXIST = 1020;
const PASSWORD_TOO_SHORT = 1021;
const USERNAME_EMPTY = 1022;

private $values = [
0000 => ["Success", ResponseFactory::OK],
Expand All @@ -11095,6 +11109,7 @@ class ErrorCode
1019 => ["Pagination forbidden", ResponseFactory::FORBIDDEN],
1020 => ["User '%s' already exists", ResponseFactory::CONFLICT],
1021 => ["Password too short (<%d characters)", ResponseFactory::UNPROCESSABLE_ENTITY],
1022 => ["Username is empty or only whitespaces", ResponseFactory::UNPROCESSABLE_ENTITY],
9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
];

Expand Down

0 comments on commit a68b385

Please sign in to comment.