Newer
Older

Yassine Doghri
committed
<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Controllers\Admin;

Yassine Doghri
committed
use Config\Services;
use App\Models\UserModel;

Yassine Doghri
committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Myaccount extends BaseController
{
public function index()
{
return view('admin/my_account/view');
}
public function changePassword()
{
return view('admin/my_account/change_password');
}
public function attemptChange()
{
$auth = Services::authentication();
$user_model = new UserModel();
// Validate here first, since some things,
// like the password, can only be validated properly here.
$rules = [
'email' => 'required|valid_email',
'password' => 'required',
'new_password' => 'required|strong_password',
'new_pass_confirm' => 'required|matches[new_password]',
];
if (!$this->validate($rules)) {
return redirect()
->back()
->withInput()
->with('errors', $user_model->errors());
}
$credentials = [
'email' => user()->email,
'password' => $this->request->getPost('password'),
];
if (!$auth->validate($credentials)) {
return redirect()
->back()
->withInput()
->with('errors', $user_model->errors());
}
user()->password = $this->request->getPost('new_password');
$user_model->save(user());
if (!$user_model->save(user())) {
return redirect()
->back()
->withInput()
->with('errors', $user_model->errors());
}
// Success!
return redirect()
->route('myAccount')
->with('message', lang('MyAccount.passwordChangeSuccess'));
}
}