Skip to content
Snippets Groups Projects
MyAccountController.php 1.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * @copyright  2020 Podlibre
     * @license    https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
     * @link       https://castopod.org/
     */
    
    namespace App\Controllers\Admin;
    
    
    use CodeIgniter\HTTP\RedirectResponse;
    
    class MyAccountController extends BaseController
    
        public function index(): string
    
        public function changePassword(): string
    
        public function attemptChange(): RedirectResponse
    
    
            // 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()
    
            }
    
            $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())) {
    
                ->with('message', lang('MyAccount.messages.passwordChangeSuccess'));