public function editProfile(UserModel $user, $new_password) { $validator = new Validation(); $validator->setRule('required', $user->email, null, 'Email'); $validator->setRule('required', $user->password, null, 'Current Password'); $validator->setRule('email', $user->email, null, 'Email'); if (!$validator->validate()) { Session::setError($validator->getErrors()); Redirect::back(); } /* @var $user \Models\UserModel */ $userFromDb = $this->user->getUser(Auth::getUserId()); if (!Common::verifyPassword($user->password, $userFromDb->password)) { Session::setError('Current password is not correct'); Redirect::back(); } if ($this->user->editUser(Auth::getUserId(), $user->email, Common::hashPassword($new_password)) !== 1) { Session::setError('Something is wrong. Try again.'); Redirect::back(); } Session::setMessage('The profile is edited'); Redirect::to(''); }