mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-08-29 15:07:18 +02:00
- rename podlibre to adaures - rename castopod-host to castopod - simplify README and redirect to docs site - move INSTALL and UPDATE docs - add new gitlabci pipeline to deploy docs - upgrade node to v16 in Dockerfile
79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* @copyright 2020 Ad Aures
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace Modules\Admin\Controllers;
|
|
|
|
use App\Models\UserModel;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use Config\Services;
|
|
|
|
class MyAccountController extends BaseController
|
|
{
|
|
public function index(): string
|
|
{
|
|
return view('my_account/view');
|
|
}
|
|
|
|
public function changePassword(): string
|
|
{
|
|
helper('form');
|
|
|
|
return view('my_account/change_password');
|
|
}
|
|
|
|
public function attemptChange(): RedirectResponse
|
|
{
|
|
$auth = Services::authentication();
|
|
$userModel = new UserModel();
|
|
|
|
// Validate here first, since some things,
|
|
// like the password, can only be validated properly here.
|
|
$rules = [
|
|
'password' => 'required',
|
|
'new_password' => 'required|strong_password|differs[password]',
|
|
];
|
|
|
|
if (! $this->validate($rules)) {
|
|
return redirect()
|
|
->back()
|
|
->withInput()
|
|
->with('errors', $userModel->errors());
|
|
}
|
|
|
|
$credentials = [
|
|
'email' => user()
|
|
->email,
|
|
'password' => $this->request->getPost('password'),
|
|
];
|
|
|
|
if (! $auth->validate($credentials)) {
|
|
return redirect()
|
|
->back()
|
|
->withInput()
|
|
->with('error', lang('MyAccount.messages.wrongPasswordError'));
|
|
}
|
|
|
|
user()
|
|
->password = $this->request->getPost('new_password');
|
|
|
|
if (! $userModel->update(user_id(), user())) {
|
|
return redirect()
|
|
->back()
|
|
->withInput()
|
|
->with('errors', $userModel->errors());
|
|
}
|
|
|
|
// Success!
|
|
return redirect()
|
|
->back()
|
|
->with('message', lang('MyAccount.messages.passwordChangeSuccess'));
|
|
}
|
|
}
|