with('title', auth()->user()->email)->with('subTitle', trans('firefly.change_your_password'))->with( 'mainTitleIcon', 'fa-user' ); } /** * @return View */ public function deleteAccount() { return view('profile.delete-account')->with('title', auth()->user()->email)->with('subTitle', trans('firefly.delete_account'))->with( 'mainTitleIcon', 'fa-user' ); } /** * @return View * */ public function index() { return view('profile.index')->with('title', trans('firefly.profile'))->with('subTitle', auth()->user()->email)->with('mainTitleIcon', 'fa-user'); } /** * @param ProfileFormRequest $request * * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function postChangePassword(ProfileFormRequest $request) { // old, new1, new2 if (!Hash::check($request->get('current_password'), auth()->user()->password)) { Session::flash('error', strval(trans('firefly.invalid_current_password'))); return redirect(route('profile.change-password')); } $result = $this->validatePassword($request->get('current_password'), $request->get('new_password')); if (!($result === true)) { Session::flash('error', $result); return redirect(route('profile.change-password')); } // update the user with the new password. auth()->user()->password = bcrypt($request->get('new_password')); auth()->user()->save(); Session::flash('success', strval(trans('firefly.password_changed'))); return redirect(route('profile')); } /** * @param DeleteAccountFormRequest $request * * @return \Illuminate\Http\RedirectResponse * @throws \Exception */ public function postDeleteAccount(DeleteAccountFormRequest $request) { // old, new1, new2 if (!Hash::check($request->get('password'), auth()->user()->password)) { Session::flash('error', strval(trans('firefly.invalid_password'))); return redirect(route('profile.delete-account')); } // respond to deletion: event(new UserIsDeleted(auth()->user(), $request->ip())); // store some stuff for the future: $registration = Preferences::get('registration_ip_address')->data; $confirmation = Preferences::get('confirmation_ip_address')->data; // DELETE! $email = auth()->user()->email; auth()->user()->delete(); Session::flush(); Session::flash('gaEventCategory', 'user'); Session::flash('gaEventAction', 'delete-account'); // create a new user with the same email address so re-registration is blocked. $newUser = User::create( [ 'email' => $email, 'password' => 'deleted', 'blocked' => 1, 'blocked_code' => 'deleted', ] ); if (strlen($registration) > 0) { Preferences::setForUser($newUser, 'registration_ip_address', $registration); } if (strlen($confirmation) > 0) { Preferences::setForUser($newUser, 'confirmation_ip_address', $confirmation); } return redirect(route('index')); } /** * * @param string $old * @param string $new1 * * @return string|bool */ protected function validatePassword(string $old, string $new1) { if ($new1 == $old) { return trans('firefly.should_change'); } return true; } }