crispage/core/actions/Crispage/Actions/RegisterAction.php
crispycat b1ab0bced2 reorganized core
\Crispage\Events renamed to \Crispage\Signaling
Action, Component, ExtensionClass, ModuleComponent, Renderable, Runnable now part of \Crispage\Framework
PluginRunnable now \Crispage\Framework\PluginClass
core extensions modified to fit new naming scheme
/core/app/media and /core/app/search moved to /core/app/cms/
2024-05-19 12:31:01 -04:00

104 lines
3.3 KiB
PHP

<?php
/*
Crispage CMS
crispycat <the@crispy.cat>
https://crispy.cat/software/crispage
Crispage is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
namespace Crispage\Actions;
defined("ROOT") or die();
class RegisterAction extends \Crispage\Framework\Action {
public static function getExtensionInfo(): array {
return [
"id" => "crispage.actions.register",
"version" => VERSION
];
}
public function __construct(\Crispage $app, array $data) {
parent::__construct($app, $data);
}
public function run(): void {
// If already logged in, redirect
if ($this->app->auth->sessionActive())
$this->app->page->redirect(WROOT . "/");
// Register the user
$username = strval($this->app->request->params["username"] ?? "");
$password = strval($this->app->request->params["password"] ?? "");
$passconf = strval($this->app->request->params["passconf"] ?? "");
$data = $this->app->request->params["data"] ?? [];
if (!is_array($data)) $data = [];
if ($password == $passconf) {
if ($this->app->request->method = "POST" && $username && $password) {
switch ($this->app->auth->registerUser($username, $password, $data)) {
case $this->app->auth::SUCCESS:
$this->app->page->data["messages"]["confemailsent"] = [
"color" => "info",
"content" => $this->app->i18n->translate(
"{%REGISTER_CONFIRM_SENT}", $data["email"] ?? ""
)
];
break;
case $this->app->auth::ERR_REGISTER_DISABLED:
$this->app->page->data["messages"]["registration_disabled"] = [
"color" => "danger",
"content" => $this->app->i18n->translate("{%REGISTRATION_DISABLED}")
];
break;
case $this->app->auth::ERR_REGISTER_TAKEN:
$this->app->page->data["messages"]["username_taken"] = [
"color" => "danger",
"content" => $this->app->i18n->translate("{%USERNAME_TAKEN}")
];
break;
case $this->app->auth::ERR_SETPASSWD_REQS_NOT_MET:
$this->app->page->data["messages"]["passwd_reqs_not_met"] = [
"color" => "danger",
"content" => $this->app->i18n->translate("{%PASSWORD_REQUIREMENTS_NOT_MET}")
];
break;
case $this->app->auth::ERR_SENDCONF_EMAIL_FAILED:
$this->app->page->data["messages"]["mailing_failed"] = [
"color" => "danger",
"content" => $this->app->i18n->translate("{%MAILING_FAILED}", $this->app->mailer->pm->ErrorInfo)
];
break;
default:
$this->app->page->data["messages"]["error"] = [
"color" => "danger",
"content" => $this->app->i18n->translate("{%AN_ERROR_HAS_OCCURRED}")
];
}
}
}
else {
$this->app->page->data["messages"]["password_mismatch"] = [
"color" => "danger",
"content" => $this->app->i18n->translate("{%PASSWORDS_DO_NOT_MATCH}")
];
}
// Set title
$this->app->page->data["title"] = $this->app->i18n->getTranslation("REGISTER");
// Show registration form
$com = $this->app->page->createComponent(
"\\Crispage\\Components\\RegisterFormComponent", []
);
$this->app->page->setMainComponent($com);
$this->app->page->actionFinished();
}
}
?>