crispycat
b1ab0bced2
\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/
98 lines
3.0 KiB
PHP
98 lines
3.0 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 PasswordResetAction extends \Crispage\Framework\Action {
|
|
public static function getExtensionInfo(): array {
|
|
return [
|
|
"id" => "crispage.actions.passwordreset",
|
|
"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 . "/");
|
|
|
|
$userid = intval($this->app->request->params["user_id"] ?? 0);
|
|
$token = strval($this->app->request->params["token"] ?? "");
|
|
$password = strval($this->app->request->params["password"] ?? "");
|
|
$passconf = strval($this->app->request->params["passconf"] ?? "");
|
|
|
|
if (
|
|
$this->app->request->method == "POST" && $userid && $token
|
|
) {
|
|
if ($password == $passconf) {
|
|
switch ($this->app->auth->resetPassword($userid, $token, $password)) {
|
|
case $this->app->auth::SUCCESS:
|
|
$this->app->page->setPersistentMessage(
|
|
"account_confirmed",
|
|
$this->app->i18n->translate("{%PASSWORD_RESET_}"),
|
|
"success"
|
|
);
|
|
$this->app->page->redirect(WROOT . "/login");
|
|
break;
|
|
case $this->app->auth::ERR_RESET_INVALID:
|
|
$this->app->page->data["messages"]["confirm_invalid"] = [
|
|
"color" => "danger",
|
|
"content" => $this->app->i18n->translate("{%INVALID_LINK}")
|
|
];
|
|
break;
|
|
case $this->app->auth::ERR_RESET_EXPIRED:
|
|
$this->app->page->data["messages"]["confirm_expired"] = [
|
|
"color" => "danger",
|
|
"content" => $this->app->i18n->translate("{%LINK_EXPIRED}")
|
|
];
|
|
break;
|
|
case $this->app->auth::ERR_RESET_TOKEN_MISMATCH:
|
|
$this->app->page->data["messages"]["token_mismatch"] = [
|
|
"color" => "danger",
|
|
"content" => $this->app->i18n->translate("{%TOKEN_MISMATCH}")
|
|
];
|
|
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("RESET_PASSWORD");
|
|
|
|
// Show registration form
|
|
$com = $this->app->page->createComponent(
|
|
"\\Crispage\\Components\\PasswordResetFormComponent", []
|
|
);
|
|
$this->app->page->setMainComponent($com);
|
|
|
|
$this->app->page->actionFinished();
|
|
}
|
|
}
|
|
?>
|