Skip to content

Commit a68b385

Browse files
committed
build for #901 and #906
1 parent 06834e9 commit a68b385

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

Diff for: api.include.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -8320,6 +8320,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
83208320
$passwordLength = $this->getProperty('passwordLength', '12');
83218321
$pkName = $table->getPk()->getName();
83228322
$registerUser = $this->getProperty('registerUser', '');
8323+
$loginAfterRegistration = $this->getProperty('loginAfterRegistration', '');
83238324
$condition = new ColumnCondition($usernameColumn, 'eq', $username);
83248325
$returnedColumns = $this->getProperty('returnedColumns', '');
83258326
if (!$returnedColumns) {
@@ -8334,6 +8335,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
83348335
if (!$registerUser) {
83358336
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
83368337
}
8338+
if(strlen(trim($username)) == 0){
8339+
return $this->responder->error(ErrorCode::USERNAME_EMPTY, $username);
8340+
}
83378341
if (strlen($password) < $passwordLength) {
83388342
return $this->responder->error(ErrorCode::PASSWORD_TOO_SHORT, $passwordLength);
83398343
}
@@ -8348,8 +8352,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
83488352
$this->db->createSingle($table, $data);
83498353
$users = $this->db->selectAll($table, $columnNames, $condition, $columnOrdering, 0, 1);
83508354
foreach ($users as $user) {
8351-
unset($user[$passwordColumnName]);
8352-
return $this->responder->success($user);
8355+
if($loginAfterRegistration){
8356+
if (!headers_sent()) {
8357+
session_regenerate_id(true);
8358+
}
8359+
unset($user[$passwordColumnName]);
8360+
$_SESSION['user'] = $user;
8361+
return $this->responder->success($user);
8362+
} else {
8363+
unset($user[$passwordColumnName]);
8364+
return $this->responder->success($user);
8365+
}
83538366
}
83548367
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
83558368
}
@@ -11070,6 +11083,7 @@ class ErrorCode
1107011083
const PAGINATION_FORBIDDEN = 1019;
1107111084
const USER_ALREADY_EXIST = 1020;
1107211085
const PASSWORD_TOO_SHORT = 1021;
11086+
const USERNAME_EMPTY = 1022;
1107311087

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

Diff for: api.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -8320,6 +8320,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
83208320
$passwordLength = $this->getProperty('passwordLength', '12');
83218321
$pkName = $table->getPk()->getName();
83228322
$registerUser = $this->getProperty('registerUser', '');
8323+
$loginAfterRegistration = $this->getProperty('loginAfterRegistration', '');
83238324
$condition = new ColumnCondition($usernameColumn, 'eq', $username);
83248325
$returnedColumns = $this->getProperty('returnedColumns', '');
83258326
if (!$returnedColumns) {
@@ -8334,6 +8335,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
83348335
if (!$registerUser) {
83358336
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
83368337
}
8338+
if(strlen(trim($username)) == 0){
8339+
return $this->responder->error(ErrorCode::USERNAME_EMPTY, $username);
8340+
}
83378341
if (strlen($password) < $passwordLength) {
83388342
return $this->responder->error(ErrorCode::PASSWORD_TOO_SHORT, $passwordLength);
83398343
}
@@ -8348,8 +8352,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
83488352
$this->db->createSingle($table, $data);
83498353
$users = $this->db->selectAll($table, $columnNames, $condition, $columnOrdering, 0, 1);
83508354
foreach ($users as $user) {
8351-
unset($user[$passwordColumnName]);
8352-
return $this->responder->success($user);
8355+
if($loginAfterRegistration){
8356+
if (!headers_sent()) {
8357+
session_regenerate_id(true);
8358+
}
8359+
unset($user[$passwordColumnName]);
8360+
$_SESSION['user'] = $user;
8361+
return $this->responder->success($user);
8362+
} else {
8363+
unset($user[$passwordColumnName]);
8364+
return $this->responder->success($user);
8365+
}
83538366
}
83548367
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
83558368
}
@@ -11070,6 +11083,7 @@ class ErrorCode
1107011083
const PAGINATION_FORBIDDEN = 1019;
1107111084
const USER_ALREADY_EXIST = 1020;
1107211085
const PASSWORD_TOO_SHORT = 1021;
11086+
const USERNAME_EMPTY = 1022;
1107311087

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

0 commit comments

Comments
 (0)