From a2d4b7c1fc00d80d5de219ae177a7616f0940784 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 12 Aug 2018 20:50:49 -0600 Subject: [PATCH] Update SettingsController --- app/Http/Controllers/SettingsController.php | 37 ++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index f3a8415cb..95859efa7 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use App\{AccountLog, Media, Profile, User}; +use App\{AccountLog, EmailVerification, Media, Profile, User}; use Auth, DB; use App\Util\Lexer\PrettyNumber; @@ -31,24 +31,45 @@ class SettingsController extends Controller { $this->validate($request, [ 'name' => 'required|string|max:30', - 'bio' => 'nullable|string|max:125' + 'bio' => 'nullable|string|max:125', + 'website' => 'nullable|url', + 'email' => 'nullable|email' ]); $changes = false; $name = $request->input('name'); $bio = $request->input('bio'); + $website = $request->input('website'); + $email = $request->input('email'); $user = Auth::user(); $profile = $user->profile; - if($profile->name != $name) { + + if($user->email != $email) { $changes = true; - $user->name = $name; - $profile->name = $name; + $user->email = $email; + $user->email_verified_at = null; + // Prevent old verifications from working + EmailVerification::whereUserId($user->id)->delete(); } - if($profile->bio != $bio) { - $changes = true; - $profile->bio = $bio; + // Only allow email to be updated if not yet verified + if(!$changes && $user->email_verified_at) { + if($profile->name != $name) { + $changes = true; + $user->name = $name; + $profile->name = $name; + } + + if($profile->website != $website) { + $changes = true; + $profile->website = $website; + } + + if($profile->bio != $bio) { + $changes = true; + $profile->bio = $bio; + } } if($changes === true) {