I am in the process of developing a community forum for a certain group. For this project, I have decided to employ Flarum as the core platform.
The critical tasks, such as user login, registration, password update/reset, and account deletion, are intended to be performed through my own website instead of the Flarum interface directly. This functionality has been accomplished by leveraging the SSO extension developed by Maicol Battistini (https://discuss.flarum.org/d/21666-php-and-wordpress-single-sign-on-sso-with-optional-jwt-addon).
However, a few queries and concerns have cropped up during the development process which are as follows:
Verifying API Success
How can I definitively confirm the success of an API request?
For instance, I need to determine whether a user's login attempt, password modification, or account deletion request has been successful. This validation is particularly crucial when a user alters their password on my site, as it automatically triggers a password update on the forum as well. I must ascertain that the forum password is updated successfully prior to modifying it in my own system. This is to avoid a situation where a user cannot access the forum because the password is only updated on my website.
Post-Account Deletion Error
Once a user deletes their account via API, they encounter an error while attempting to access the forum. The issue can only be resolved by clearing the browser's cookies. Here is the stack trace for this error:
Error thrown with message "Call to a member function updateLastSeen() on null"
Stacktrace:
#30 Error in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\AuthenticateWithSession.php:41
#29 Flarum\Http\Middleware\AuthenticateWithSession:getActor in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\AuthenticateWithSession.php:27
#28 Flarum\Http\Middleware\AuthenticateWithSession:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#27 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\RememberFromCookie.php:52
#26 Flarum\Http\Middleware\RememberFromCookie:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#25 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\StartSession.php:61
#24 Flarum\Http\Middleware\StartSession:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#23 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\CollectGarbage.php:46
#22 Flarum\Http\Middleware\CollectGarbage:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#21 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\ParseJsonBody.php:28
#20 Flarum\Http\Middleware\ParseJsonBody:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#19 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\HandleErrors.php:57
#18 Flarum\Http\Middleware\HandleErrors:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#17 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\InjectActorReference.php:25
#16 Flarum\Http\Middleware\InjectActorReference:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#15 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\MiddlewarePipe.php:75
#14 Laminas\Stratigility\MiddlewarePipe:process in C:\xampp\htdocs\site\forum\vendor\middlewares\request-handler\src\RequestHandler.php:84
#13 Middlewares\RequestHandler:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#12 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\middlewares\base-path-router\src\BasePathRouter.php:99
#11 Middlewares\BasePathRouter:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#10 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Middleware\OriginalMessages.php:36
#9 Laminas\Stratigility\Middleware\OriginalMessages:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#8 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\middlewares\base-path\src\BasePath.php:73
#7 Middlewares\BasePath:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#6 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Middleware\ProcessIp.php:24
#5 Flarum\Http\Middleware\ProcessIp:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\Next.php:49
#4 Laminas\Stratigility\Next:handle in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\MiddlewarePipe.php:75
#3 Laminas\Stratigility\MiddlewarePipe:process in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-stratigility\src\MiddlewarePipe.php:64
#2 Laminas\Stratigility\MiddlewarePipe:handle in C:\xampp\htdocs\site\forum\vendor\laminas\laminas-httphandlerrunner\src\RequestHandlerRunner.php:73
#1 Laminas\HttpHandlerRunner\RequestHandlerRunner:run in C:\xampp\htdocs\site\forum\vendor\flarum\core\src\Http\Server.php:45
#0 Flarum\Http\Server:listen in C:\xampp\htdocs\site\forum\index.php:26
UserValidator.php Edits:
Is it a sound practice to modify username and password requirements by directly editing the UserValidator.php file? Currently, I have adjusted the getRules method as such:
protected function getRules()
{
$idSuffix = $this->user ? ','.$this->user->id : '';
return [
'username' => [
'required',
'regex:/^[a-z0-9_-]+$/i',
'unique:users,username'.$idSuffix,
],
'email' => [
'required',
],
'password' => [
'required',
]
];
}
Other validation requirements are checked via my own authentication system. I am concerned about potential complications stemming from these changes.
Plaintext Password Transmission:
For user login/registration, the API necessitates sending passwords in plain text. Is this a secure approach? If not, could there be a workaround? It would be ideal if the system could just authenticate the user and disregard the password.
Any assistance or insights you can offer would be greatly appreciated. Thank you in advance.