@@ -8320,6 +8320,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8320
8320
$ passwordLength = $ this ->getProperty ('passwordLength ' , '12 ' );
8321
8321
$ pkName = $ table ->getPk ()->getName ();
8322
8322
$ registerUser = $ this ->getProperty ('registerUser ' , '' );
8323
+ $ loginAfterRegistration = $ this ->getProperty ('loginAfterRegistration ' , '' );
8323
8324
$ condition = new ColumnCondition ($ usernameColumn , 'eq ' , $ username );
8324
8325
$ returnedColumns = $ this ->getProperty ('returnedColumns ' , '' );
8325
8326
if (!$ returnedColumns ) {
@@ -8334,6 +8335,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8334
8335
if (!$ registerUser ) {
8335
8336
return $ this ->responder ->error (ErrorCode::AUTHENTICATION_FAILED , $ username );
8336
8337
}
8338
+ if (strlen (trim ($ username )) == 0 ){
8339
+ return $ this ->responder ->error (ErrorCode::USERNAME_EMPTY , $ username );
8340
+ }
8337
8341
if (strlen ($ password ) < $ passwordLength ) {
8338
8342
return $ this ->responder ->error (ErrorCode::PASSWORD_TOO_SHORT , $ passwordLength );
8339
8343
}
@@ -8348,8 +8352,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8348
8352
$ this ->db ->createSingle ($ table , $ data );
8349
8353
$ users = $ this ->db ->selectAll ($ table , $ columnNames , $ condition , $ columnOrdering , 0 , 1 );
8350
8354
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
+ }
8353
8366
}
8354
8367
return $ this ->responder ->error (ErrorCode::AUTHENTICATION_FAILED , $ username );
8355
8368
}
@@ -11070,6 +11083,7 @@ class ErrorCode
11070
11083
const PAGINATION_FORBIDDEN = 1019 ;
11071
11084
const USER_ALREADY_EXIST = 1020 ;
11072
11085
const PASSWORD_TOO_SHORT = 1021 ;
11086
+ const USERNAME_EMPTY = 1022 ;
11073
11087
11074
11088
private $ values = [
11075
11089
0000 => ["Success " , ResponseFactory::OK ],
@@ -11095,6 +11109,7 @@ class ErrorCode
11095
11109
1019 => ["Pagination forbidden " , ResponseFactory::FORBIDDEN ],
11096
11110
1020 => ["User '%s' already exists " , ResponseFactory::CONFLICT ],
11097
11111
1021 => ["Password too short (<%d characters) " , ResponseFactory::UNPROCESSABLE_ENTITY ],
11112
+ 1022 => ["Username is empty or only whitespaces " , ResponseFactory::UNPROCESSABLE_ENTITY ],
11098
11113
9999 => ["%s " , ResponseFactory::INTERNAL_SERVER_ERROR ],
11099
11114
];
11100
11115
0 commit comments