Diff #4 - trunk/views/php/admin/change_password.php
1,393 bytes
|
|
January 20, 2025 at 08:20
|
Diff
Index: change_password.php
--- change_password.php (nonexistent) +++ change_password.php (revision 4) @@ -0,0 +1,51 @@ +<?php +declare(strict_types = 1); + +namespace Views\admin; + +use Apex\Svc{View, App}; +use Apex\Armor\Auth\Login; + +/** + * Render the template. + */ +class change_password +{ + + /** + *Post + */ + public function post(View $view, App $app, Login $login):void + { + + // Return, if not updating + if ($app->getAction() != 'change_password') { + return; + } + + // Perform checks + if ($app->post('password', '') == '') { + $view->addCallout('You did not specify a current password.', 'error'); + return; + } elseif ($app->post('new_password') == '') { + $view->addCallout('You did not specify a new password.', 'error'); + return; + } elseif ($app->post('new_password') != $app->post('new_password2')) { + $view->addCallout('Passwords do not match. Please try again.', 'error'); + return; + } elseif (!$login->checkCredentials($app->getUser()->getUsername(), $app->post('password'), 'admin')) { + $view->addCallout('Invalid current password specified. Please try again.', 'error'); + return; + } + + // Update password + $user = $app->getUser(); + $user->updatePassword($app->post('new_password'), $app->post('password')); + + // Callout + $view->addCallout('Successfully updated your account password.'); + } + +} + +
Full Code
<?php declare(strict_types = 1);
namespace Views\admin;
use Apex\Svc{View, App}; use Apex\Armor\Auth\Login;
/** * Render the template. */ class change_password {
/**
*Post
*/
public function post(View $view, App $app, Login $login):void
{
// Return, if not updating
if ($app->getAction() != 'change_password') {
return;
}
// Perform checks
if ($app->post('password', '') == '') {
$view->addCallout('You did not specify a current password.', 'error');
return;
} elseif ($app->post('new_password') == '') {
$view->addCallout('You did not specify a new password.', 'error');
return;
} elseif ($app->post('new_password') != $app->post('new_password2')) {
$view->addCallout('Passwords do not match. Please try again.', 'error');
return;
} elseif (!$login->checkCredentials($app->getUser()->getUsername(), $app->post('password'), 'admin')) {
$view->addCallout('Invalid current password specified. Please try again.', 'error');
return;
}
// Update password
$user = $app->getUser();
$user->updatePassword($app->post('new_password'), $app->post('password'));
// Callout
$view->addCallout('Successfully updated your account password.');
}
}