Standard\Controllers\AccountController::saveAction PHP Method

saveAction() public method

public saveAction ( )
    public function saveAction()
    {
        if (!empty($_POST['password_new'])) {
            try {
                v::length(6)->check($_POST['password_new']);
            } catch (ValidationException $e) {
                $this->flasher->error('Please make sure new password is longer than 6 characters!');
            }
            if ($_POST['password_new'] !== $_POST['password_new_confirm']) {
                $this->flasher->error('New password fields were not identical!');
            }
            if (!Gatekeeper::authenticate(['username' => $this->user->username, 'password' => $_POST['password_old']])) {
                $this->flasher->error('Invalid password. Changes ignored.');
            } else {
                $this->user->password = $_POST['password_new'];
                $this->user->save();
                $this->flasher->success('Password updated!');
            }
        }
        if ($_POST['firstname'] != '-') {
            try {
                v::alnum(' ')->check($_POST['firstname']);
                $this->user->firstName = $_POST['firstname'];
                $this->user->save();
                $this->flasher->success('First name changed.');
            } catch (ValidationException $e) {
                $this->flasher->error('Name contains invalid characters. ' . $e->getMainMessage());
            }
        }
        if ($_POST['lastname'] != '-') {
            try {
                v::alnum(' ')->check($_POST['lastname']);
                $this->user->lastName = $_POST['lastname'];
                $this->user->save();
                $this->flasher->success('Last name changed.');
            } catch (ValidationException $e) {
                $this->flasher->error('Last name contains invalid characters. ' . $e->getMainMessage());
            }
        }
        $this->redirect('/account');
    }