Sfoglia il codice sorgente

Update SettingsController

Daniel Supernault 7 anni fa
parent
commit
a2d4b7c1fc
1 ha cambiato i file con 29 aggiunte e 8 eliminazioni
  1. 29 8
      app/Http/Controllers/SettingsController.php

+ 29 - 8
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) {