Bläddra i källkod

Added edit default recipient email

Will Browning 5 år sedan
förälder
incheckning
00e1ebd015

+ 22 - 0
app/Http/Controllers/DefaultRecipientController.php

@@ -6,6 +6,16 @@ use App\Http\Requests\UpdateDefaultRecipientRequest;
 
 class DefaultRecipientController extends Controller
 {
+    /**
+     * Create a new controller instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        $this->middleware('throttle:1,1')->only('edit');
+    }
+
     public function update(UpdateDefaultRecipientRequest $request)
     {
         $recipient = user()->verifiedRecipients()->findOrFail($request->default_recipient);
@@ -15,4 +25,16 @@ class DefaultRecipientController extends Controller
 
         return back()->with(['status' => 'Default Recipient Updated Successfully']);
     }
+
+    public function edit(EditDefaultRecipientRequest $request)
+    {
+        $recipient = user()->defaultRecipient;
+
+        $recipient->email = $request->email;
+        $recipient->save();
+
+        user()->sendEmailVerificationNotification();
+
+        return back()->with(['status' => 'Email Updated Successfully, Please Check Your Inbox For The Verification Email']);
+    }
 }

+ 50 - 0
app/Http/Requests/EditDefaultRecipientRequest.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Http\Requests;
+
+use App\Rules\RegisterUniqueRecipient;
+use Illuminate\Foundation\Http\FormRequest;
+
+class EditDefaultRecipientRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'email' => [
+                'required',
+                'email',
+                'max:254',
+                'confirmed',
+                new RegisterUniqueRecipient,
+                'not_in:'.$this->user()->email
+            ]
+        ];
+    }
+
+    /**
+     * Get the error messages for the defined validation rules.
+     *
+     * @return array
+     */
+    public function messages()
+    {
+        return [
+            'email.not_in' => 'That email is the same as the current one.'
+        ];
+    }
+}

+ 83 - 30
resources/views/settings/show.blade.php

@@ -35,49 +35,102 @@
 
         <div class="px-6 py-8 md:p-10 bg-white rounded-lg shadow mb-10">
 
-            <form class="mb-16" method="POST" action="{{ route('settings.default_recipient') }}">
-                @csrf
+            @if($user->hasVerifiedDefaultRecipient())
 
-                <div class="mb-6">
+                <form class="mb-16" method="POST" action="{{ route('settings.default_recipient') }}">
+                    @csrf
 
-                    <h3 class="font-bold text-xl">
-                        Update Default Recipient
-                    </h3>
+                    <div class="mb-6">
 
-                    <div class="mt-4 w-24 border-b-2 border-grey-200"></div>
+                        <h3 class="font-bold text-xl">
+                            Update Default Recipient
+                        </h3>
 
-                    <p class="mt-6">The default recipient is used for all new aliases and any aliases that do not have any recipients attached. Once an alias has been created in your dashboard you can update the recipient to a different one.</p>
+                        <div class="mt-4 w-24 border-b-2 border-grey-200"></div>
 
-                    <div class="mt-6 flex flex-wrap mb-4">
-                        <label for="default-recipient" class="block text-grey-700 text-sm mb-2">
-                            {{ __('Select Recipient') }}:
-                        </label>
+                        <p class="mt-6">The default recipient is used for all new aliases and any aliases that do not have any recipients attached. Once an alias has been created in your dashboard you can update the recipient to a different one.</p>
 
-                        <div class="block relative w-full">
-                            <select id="default-recipient" class="block appearance-none w-full text-grey-700 bg-grey-100 p-3 pr-8 rounded shadow focus:shadow-outline" name="default_recipient" required>
-                                @foreach($recipientOptions as $recipient)
-                                <option value="{{ $recipient->id }}" {{ $user->email === $recipient->email ? 'selected' : '' }}>{{ $recipient->email }}</option>
-                                @endforeach
-                            </select>
-                            <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
-                                <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/></svg>
+                        <div class="mt-6 flex flex-wrap mb-4">
+                            <label for="default-recipient" class="block text-grey-700 text-sm mb-2">
+                                {{ __('Select Recipient') }}:
+                            </label>
+
+                            <div class="block relative w-full">
+                                <select id="default-recipient" class="block appearance-none w-full text-grey-700 bg-grey-100 p-3 pr-8 rounded shadow focus:shadow-outline" name="default_recipient" required>
+                                    @foreach($recipientOptions as $recipient)
+                                    <option value="{{ $recipient->id }}" {{ $user->email === $recipient->email ? 'selected' : '' }}>{{ $recipient->email }}</option>
+                                    @endforeach
+                                </select>
+                                <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
+                                    <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/></svg>
+                                </div>
                             </div>
+
+                            @if ($errors->has('default_recipient'))
+                                <p class="text-red-500 text-xs italic mt-4">
+                                    {{ $errors->first('default_recipient') }}
+                                </p>
+                            @endif
                         </div>
 
-                        @if ($errors->has('default_recipient'))
-                            <p class="text-red-500 text-xs italic mt-4">
-                                {{ $errors->first('default_recipient') }}
-                            </p>
-                        @endif
                     </div>
 
-                </div>
+                    <button type="submit" class="bg-cyan-400 w-full hover:bg-cyan-300 text-cyan-900 font-bold py-3 px-4 rounded focus:outline-none">
+                        {{ __('Update Default Recipient') }}
+                    </button>
 
-                <button type="submit" class="bg-cyan-400 w-full hover:bg-cyan-300 text-cyan-900 font-bold py-3 px-4 rounded focus:outline-none">
-                    {{ __('Update Default Recipient') }}
-                </button>
+                </form>
 
-            </form>
+            @else
+
+                <form class="mb-16" method="POST" action="{{ route('settings.edit_default_recipient') }}">
+                    @csrf
+
+                    <div class="mb-6">
+
+                        <h3 class="font-bold text-xl">
+                            Update Email
+                        </h3>
+
+                        <div class="mt-4 w-24 border-b-2 border-grey-200"></div>
+
+                        <p class="mt-6">Made a mistake or typo with the email addresss you signed up with? Update your email below, you'll receive a new email verification link.</p>
+
+                        <div class="mt-6 flex flex-wrap mb-4">
+                            <label for="email" class="block text-grey-700 text-sm mb-2">
+                                {{ __('Email') }}:
+                            </label>
+
+                            <div class="block relative w-full">
+                                <input id="email" type="email" class="block appearance-none w-full text-grey-700 bg-grey-100 p-3 pr-8 rounded shadow focus:shadow-outline" name="email" value="{{ old('email') ?? $user->email }}">
+                            </div>
+
+                            @if ($errors->has('email'))
+                                <p class="text-red-500 text-xs italic mt-4">
+                                    {{ $errors->first('email') }}
+                                </p>
+                            @endif
+                        </div>
+
+                        <div class="mt-6 flex flex-wrap mb-4">
+                            <label for="email_confirmation" class="block text-grey-700 text-sm mb-2">
+                                {{ __('Confirm Email') }}:
+                            </label>
+
+                            <div class="block relative w-full">
+                                <input id="email_confirmation" type="email" class="block appearance-none w-full text-grey-700 bg-grey-100 p-3 pr-8 rounded shadow focus:shadow-outline" name="email_confirmation">
+                            </div>
+                        </div>
+
+                    </div>
+
+                    <button type="submit" class="bg-cyan-400 w-full hover:bg-cyan-300 text-cyan-900 font-bold py-3 px-4 rounded focus:outline-none">
+                        {{ __('Update Email') }}
+                    </button>
+
+                </form>
+
+            @endif
 
             <form class="mb-16" method="POST" action="{{ route('settings.password') }}">
                 @csrf

+ 1 - 0
routes/web.php

@@ -65,6 +65,7 @@ Route::middleware(['auth', '2fa'])->group(function () {
     Route::post('/settings/account', 'SettingController@destroy')->name('account.destroy');
 
     Route::post('/settings/default-recipient', 'DefaultRecipientController@update')->name('settings.default_recipient');
+    Route::post('/settings/edit-default-recipient', 'DefaultRecipientController@edit')->name('settings.edit_default_recipient');
 
     Route::post('/settings/from-name', 'FromNameController@update')->name('settings.from_name');