diff --git a/app/Http/Controllers/Gallery/UserController.php b/app/Http/Controllers/Gallery/UserController.php
index 014420b..12e4714 100644
--- a/app/Http/Controllers/Gallery/UserController.php
+++ b/app/Http/Controllers/Gallery/UserController.php
@@ -7,14 +7,115 @@ use App\Facade\Theme;
use App\Facade\UserConfig;
use App\Helpers\DbHelper;
use App\Http\Controllers\Controller;
+use App\Http\Requests\SaveUserSettingsRequest;
+use App\Mail\UserChangeEmailRequired;
use App\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Mail;
use Symfony\Component\HttpFoundation\Request;
class UserController extends Controller
{
+ public function confirmEmailChangeState(Request $request)
+ {
+ $user = $this->getUser();
+ if (!$user->is_email_change_in_progress)
+ {
+ return redirect(route('userSettings'));
+ }
+
+ // Update the e-mail address
+ $user->email = $user->new_email_address;
+
+ // Reset the e-mail change state
+ $user->is_email_change_in_progress = false;
+ $user->new_email_address = null;
+ $user->save();
+
+ $request->session()->flash('success', trans('auth.change_email_success_message'));
+ return redirect(route('userSettings'));
+ }
+
+ public function resetEmailChangeState(Request $request)
+ {
+ $user = $this->getUser();
+ if (!$user->is_email_change_in_progress)
+ {
+ return redirect(route('userSettings'));
+ }
+
+ $data = $request->all();
+
+ if (isset($data['resend_email']))
+ {
+ $this->sendEmailChangeConfirmationEmail($user, $user->new_email_address);
+ $request->session()->flash('info', trans('auth.change_email_required_message'));
+ }
+
+ if (isset($data['cancel_change']))
+ {
+ $user->is_email_change_in_progress = false;
+ $user->new_email_address = null;
+ $user->save();
+ }
+
+ return redirect(route('userSettings'));
+ }
+
+ public function saveSettings(SaveUserSettingsRequest $request)
+ {
+ $data = $request->only(['name', 'email', 'profile_alias', 'enable_profile_page']);
+ $user = $this->getUser();
+
+ if (
+ UserConfig::get('require_email_verification') &&
+ isset($data['email']) &&
+ $data['email'] != $user->email &&
+ !$user->is_email_change_in_progress
+ )
+ {
+ // Can't update the e-mail directly until the new e-mail address has been verified.
+ // TODO - send e-mail and handle response, flag e-mail as being "change in-progress"
+ // Send activation e-mail
+
+ $this->sendEmailChangeConfirmationEmail($user, $data['email']);
+ $request->session()->flash('info', trans('auth.change_email_required_message'));
+
+ // Flag the user as a change e-mail in progress
+ $user->new_email_address = $data['email'];
+ $user->is_email_change_in_progress = true;
+ $user->save();
+
+ unset($data['email']);
+ $request->session()->flash('info', trans('auth.change_email_required_message'));
+ }
+
+ // Don't allow e-mail address to be changed if a change is in progress
+ if ($user->is_email_change_in_progress)
+ {
+ unset($data['email']);
+ }
+
+ $user->fill($data);
+ $user->enable_profile_page = (isset($data['enable_profile_page']) && strtolower($data['enable_profile_page']) == 'on');
+ $user->save();
+
+ $request->session()->flash('success', trans('gallery.user_settings.settings_saved'));
+
+ return redirect(route('userSettings'));
+ }
+
+ public function settings(Request $request)
+ {
+ return Theme::render('gallery.user_settings', [
+ 'info' => $request->session()->get('info'),
+ 'success' => $request->session()->get('success'),
+ 'user' => $this->getUser()
+ ]);
+ }
+
public function show(Request $request, $idOrAlias)
{
// If a user has a profile alias set, their profile page cannot be accessed by the ID
@@ -198,4 +299,13 @@ class UserController extends Controller
return $results;
}
+
+ private function sendEmailChangeConfirmationEmail(User $user, $newEmailAddress)
+ {
+ $oldEmailAddress = $user->email;
+ $user->email = $newEmailAddress;
+
+ Mail::to($user)->send(new UserChangeEmailRequired($user));
+ $user->email = $oldEmailAddress;
+ }
}
\ No newline at end of file
diff --git a/app/Http/Requests/SaveUserSettingsRequest.php b/app/Http/Requests/SaveUserSettingsRequest.php
new file mode 100644
index 0000000..4797455
--- /dev/null
+++ b/app/Http/Requests/SaveUserSettingsRequest.php
@@ -0,0 +1,33 @@
+ 'required|max:255',
+ 'email' => 'required|email|max:255|unique:users,email,' . Auth::user()->id,
+ 'profile_alias' => 'sometimes|max:255|unique:users,profile_alias,' . Auth::user()->id
+ ];
+ }
+}
\ No newline at end of file
diff --git a/app/Mail/UserChangeEmailRequired.php b/app/Mail/UserChangeEmailRequired.php
new file mode 100644
index 0000000..6f39a27
--- /dev/null
+++ b/app/Mail/UserChangeEmailRequired.php
@@ -0,0 +1,46 @@
+user = $user;
+ }
+
+ /**
+ * Build the message.
+ *
+ * @return $this
+ */
+ public function build()
+ {
+ $subject = trans('email.change_email_required_subject', ['app_name' => UserConfig::get('app_name')]);
+
+ return $this
+ ->subject($subject)
+ ->markdown(Theme::viewName('email.user_change_email_required'))
+ ->with([
+ 'subject' => $subject,
+ 'user' => $this->user
+ ]);
+ }
+}
diff --git a/database/migrations/2018_09_12_142055_add_user_email_change_columns.php b/database/migrations/2018_09_12_142055_add_user_email_change_columns.php
new file mode 100644
index 0000000..727bf75
--- /dev/null
+++ b/database/migrations/2018_09_12_142055_add_user_email_change_columns.php
@@ -0,0 +1,36 @@
+boolean('is_email_change_in_progress')->default(false);
+ $table->string('new_email_address')->nullable(true);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('users', function (Blueprint $table)
+ {
+ $table->dropColumn('is_email_change_in_progress');
+ $table->dropColumn('new_email_address');
+ });
+ }
+}
diff --git a/resources/lang/en/auth.php b/resources/lang/en/auth.php
index 545f1b6..b184749 100644
--- a/resources/lang/en/auth.php
+++ b/resources/lang/en/auth.php
@@ -20,6 +20,9 @@ return [
'and password you provided when you registered.',
'activation_required_message' => 'An e-mail containing an activation link has been sent to the e-mail address you provided. ' .
'Please click the link in this e-mail to activate your account.',
+ 'change_email_required_message' => 'An e-mail containing an activation link has been sent to the e-mail address you provided. ' .
+ 'Please click the link in this e-mail to confirm your new e-mail address.',
+ 'change_email_success_message' => 'Your e-mail address change has been confirmed. You will now need to login with your new e-mail address.',
'change_password_action' => 'Change password',
'change_password_title' => 'Change your password',
'email_password_login' => 'Alternatively, login with your e-mail address and password:',
diff --git a/resources/lang/en/email.php b/resources/lang/en/email.php
index 698bc6a..15d7776 100644
--- a/resources/lang/en/email.php
+++ b/resources/lang/en/email.php
@@ -4,6 +4,9 @@ return [
'activation_required_p2' => 'To confirm your e-mail address and activate your account, please click the link below. ' .
'You may also need to copy + paste this into your browser\'s address bar if your e-mail reader has split this line.',
'activation_required_subject' => 'Activate your :app_name account',
+ 'change_email_required_p1' => 'A change was requested to your e-mail address on :app_name.',
+ 'change_email_required_p2' => 'To confirm this e-mail address is valid and update the e-mail address on your account, please click the button below.',
+ 'change_email_required_subject' => 'Confirm the e-mail change to your :app_name account',
'generic_intro' => 'Hi :user_name,',
'generic_regards' => 'Regards,',
'test_email_subject' => 'Test e-mail from :app_name'
diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php
index 0473b7f..b96752f 100644
--- a/resources/lang/en/forms.php
+++ b/resources/lang/en/forms.php
@@ -14,6 +14,7 @@ return [
'bulk_edit_photos_placeholder' => 'Select an action',
'cancel_action' => 'Cancel',
'close_action' => 'Close',
+ 'confirm_email_action' => 'Confirm e-mail address',
'continue_action' => 'Continue',
'create_action' => 'Create',
'create_album_label' => 'Create a new album:',
@@ -24,6 +25,7 @@ return [
'download_action' => 'Download',
'edit_action' => 'Edit',
'email_label' => 'E-mail address:',
+ 'enable_profile_page_label' => 'Allow others to see my profile page',
'labels_label' => 'Labels:',
'login_action' => 'Login',
'name_label' => 'Name:',
@@ -33,6 +35,8 @@ return [
'password_confirm_label' => 'Confirm password:',
'please_select' => '- Select an Option -',
'private_album_label' => 'Private album (only visible to me)',
+ 'profile_alias_label' => 'Alias:',
+ 'profile_alias_help' => 'The profile alias is used to create a unique URL direct to your profile page.',
'quick_upload_file_label' => 'Photo:',
'realname_label' => 'Your name:',
'register_action' => 'Create account',
diff --git a/resources/lang/en/gallery.php b/resources/lang/en/gallery.php
index c2b6384..485683a 100644
--- a/resources/lang/en/gallery.php
+++ b/resources/lang/en/gallery.php
@@ -77,5 +77,13 @@ return [
'cameras' => 'Cameras',
'no_albums_p1' => 'No Photo Albums',
'no_albums_p2' => ':user_name has not created any albums yet.'
+ ],
+ 'user_settings' => [
+ 'cancel_email_change' => 'Don\'t change e-mail address',
+ 'change_email_in_progress' => 'To confirm your new e-mail address, please click on the "confirm" link in the e-mail that was sent to: :new_email_address.',
+ 'change_email_resend' => 'Re-send confirmation e-mail.',
+ 'change_password' => 'Change password',
+ 'settings_saved' => 'Your settings were updated successfully.',
+ 'title' => 'Change my settings'
]
];
\ No newline at end of file
diff --git a/resources/lang/en/navigation.php b/resources/lang/en/navigation.php
index dc352b7..28ce905 100644
--- a/resources/lang/en/navigation.php
+++ b/resources/lang/en/navigation.php
@@ -36,6 +36,7 @@ return [
'public_profile_page' => 'My public profile',
'quick_post' => 'Quick Upload',
'register' => 'Register',
- 'statistics' => 'Statistics'
+ 'statistics' => 'Statistics',
+ 'user_settings' => 'Change my settings'
]
];
\ No newline at end of file
diff --git a/resources/views/themes/base/email/user_change_email_required.blade.php b/resources/views/themes/base/email/user_change_email_required.blade.php
new file mode 100644
index 0000000..75fe1e4
--- /dev/null
+++ b/resources/views/themes/base/email/user_change_email_required.blade.php
@@ -0,0 +1,17 @@
+@component('mail::message')
+@lang('email.generic_intro', ['user_name' => $user->name])
+
+
+@lang('email.change_email_required_p1', ['app_name' => UserConfig::get('app_name')])
+
+
+@lang('email.change_email_required_p2')
+
+@component('mail::button', ['url' => route('userSettings.confirmEmailChangeState'), 'color' => 'blue'])
+ @lang('forms.confirm_email_action')
+@endcomponent
+
+@lang('email.generic_regards')
+{{ UserConfig::get('app_name') }}
+{{ route('home') }}
+@endcomponent
\ No newline at end of file
diff --git a/resources/views/themes/base/gallery/user_settings.blade.php b/resources/views/themes/base/gallery/user_settings.blade.php
new file mode 100644
index 0000000..461ab04
--- /dev/null
+++ b/resources/views/themes/base/gallery/user_settings.blade.php
@@ -0,0 +1,103 @@
+@extends(Theme::viewName('layout'))
+@section('title', trans('gallery.user_settings.title'))
+
+@section('content')
+
@lang('gallery.user_settings.change_email_in_progress', ['new_email_address' => $user->new_email_address])
+ +@lang('auth.social_login')
@include(Theme::viewName('partials.social_login_providers')) +@lang('auth.email_password_login')
@endif - -@lang('auth.email_password_login')
@else@lang('auth.email_password_login_sso')
@lang('auth.email_password_login_sso_2')
diff --git a/resources/views/themes/base/partials/navbar.blade.php b/resources/views/themes/base/partials/navbar.blade.php index bd3b2a3..369ba68 100644 --- a/resources/views/themes/base/partials/navbar.blade.php +++ b/resources/views/themes/base/partials/navbar.blade.php @@ -78,8 +78,9 @@