From 8fedeb4ce85f4d159c5b47f46fb7381af72fede1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 31 May 2018 21:11:56 -0600 Subject: [PATCH] Update SettingsController --- app/Http/Controllers/SettingsController.php | 40 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 005a98238..b1a17700b 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -22,21 +22,32 @@ class SettingsController extends Controller { $this->validate($request, [ 'name' => 'required|string|max:30', + 'bio' => 'string|max:125' ]); + $changes = false; $name = $request->input('name'); + $bio = $request->input('bio'); $user = Auth::user(); $profile = $user->profile; if($profile->name != $name) { + $changes = true; $user->name = $name; - $user->save(); - $profile->name = $name; - $profile->save(); + } + if($profile->bio != $bio) { + $changes = true; + $profile->bio = $bio; + } + + if($changes === true) { + $user->save(); + $profile->save(); return redirect('/settings/home')->with('status', 'Profile successfully updated!'); } + return redirect('/settings/home'); } @@ -45,6 +56,29 @@ class SettingsController extends Controller return view('settings.password'); } + public function passwordUpdate(Request $request) + { + $this->validate($request, [ + 'current' => 'required|string', + 'password' => 'required|string', + 'password_confirmation' => 'required|string', + ]); + + $current = $request->input('current'); + $new = $request->input('password'); + $confirm = $request->input('password_confirmation'); + + $user = Auth::user(); + + if(password_verify($current, $user->password) && $new === $confirm) { + $user->password = bcrypt($new); + $user->save(); + + return redirect('/settings/home')->with('status', 'Password successfully updated!'); + } + return redirect('/settings/home')->with('error', 'There was an error with your request!'); + } + public function email() { return view('settings.email');