From ac2a24187deb89447922569b16b5d86d0e9a5d59 Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Tue, 11 Apr 2017 18:31:56 +0100 Subject: [PATCH] #9, #12: Change password is now working. Updated the default album view to Bootstrap v4's cards. --- .idea/deployment.xml | 3 +- .../Auth/ChangePasswordController.php | 40 +++++++++++++++++++ resources/lang/en/passwords.php | 1 + .../themes/base/admin/show_album.blade.php | 18 ++------- .../auth/passwords/change_password.blade.php | 6 ++- .../base/gallery/album_default.blade.php | 37 +++++++++-------- .../themes/base/gallery/album_empty.blade.php | 12 ++---- .../views/themes/base/gallery/index.blade.php | 2 +- .../base/partials/album_permissions.blade.php | 10 ++--- routes/web.php | 1 + 10 files changed, 81 insertions(+), 49 deletions(-) diff --git a/.idea/deployment.xml b/.idea/deployment.xml index 02a52c6..981e50c 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,6 +1,6 @@ - + @@ -10,6 +10,5 @@ - \ No newline at end of file diff --git a/app/Http/Controllers/Auth/ChangePasswordController.php b/app/Http/Controllers/Auth/ChangePasswordController.php index 9eb10d8..9aa161e 100644 --- a/app/Http/Controllers/Auth/ChangePasswordController.php +++ b/app/Http/Controllers/Auth/ChangePasswordController.php @@ -6,6 +6,8 @@ use App\Facade\Theme; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Password; class ChangePasswordController extends Controller { @@ -28,8 +30,46 @@ class ChangePasswordController extends Controller $this->middleware('auth'); } + public function processChangePassword(Request $request) + { + $this->validate($request, ['password' => 'required|confirmed|min:6']); + + // Here we will attempt to reset the user's password. If it is successful we + // will update the password on an actual user model and persist it to the + // database. Otherwise we will parse the error and return the response. + $response = $this->broker()->reset( + $this->credentials($request), function ($user, $password) { + $this->resetPassword($user, $password); + } + ); + + // If the password was successfully reset, we will redirect the user back to + // the application's home authenticated view. If there is an error we can + // redirect them back to where they came from with their error message. + return $response == Password::PASSWORD_RESET + ? $this->sendResetResponse($response) + : $this->sendResetFailedResponse($request, $response); + } + public function showChangePasswordForm(Request $request) { return Theme::render('auth.passwords.change_password'); } + + protected function credentials(Request $request) + { + $data = $request->only('password', 'password_confirmation', 'token'); + $data['email'] = Auth::user()->email; + + // Create a token for the password broker to validate + $data['token'] = $this->broker()->createToken($this->getUser()); + + return $data; + } + + protected function sendResetResponse($response) + { + return redirect($this->redirectPath()) + ->with('status', trans('passwords.changed')); + } } \ No newline at end of file diff --git a/resources/lang/en/passwords.php b/resources/lang/en/passwords.php index 7e193a7..29523da 100644 --- a/resources/lang/en/passwords.php +++ b/resources/lang/en/passwords.php @@ -13,6 +13,7 @@ return [ | */ + 'changed' => 'Your password has been changed.', 'password' => 'Passwords must be at least six characters and match the confirmation.', 'reset' => 'Your password has been reset!', 'sent' => 'We have sent your password reset link to your e-mail address.', diff --git a/resources/views/themes/base/admin/show_album.blade.php b/resources/views/themes/base/admin/show_album.blade.php index a2630a2..aaf9f5b 100644 --- a/resources/views/themes/base/admin/show_album.blade.php +++ b/resources/views/themes/base/admin/show_album.blade.php @@ -45,7 +45,7 @@ {{ csrf_field() }} @if (count($existing_groups) > 0) -
+
@foreach ($existing_groups as $group) @include(Theme::viewName('partials.album_permissions'), [ 'key_id' => 'group_' . $group->id, @@ -59,7 +59,7 @@
@endif -
+
@@ -248,16 +248,6 @@ $('.nav-tabs a[href="#upload-tab"]').tab('show'); }); - {{-- Photo editing tasks - the buttons beneath the photos in partials/single_photo_admin --}} - /*$('a.change-album').click(editViewModel.changeAlbum); - $('a.delete-photo').click(editViewModel.delete); - $('a.flip-photo-both').click(editViewModel.flipBoth); - $('a.flip-photo-horizontal').click(editViewModel.flipHorizontal); - $('a.flip-photo-vertical').click(editViewModel.flipVertical); - $('a.regenerate-thumbnails').click(editViewModel.regenerateThumbnails); - $('a.rotate-photo-left').click(editViewModel.rotateLeft); - $('a.rotate-photo-right').click(editViewModel.rotateRight);*/ - {{-- Photo uploads using AJAX --}} if (window.FormData) { diff --git a/resources/views/themes/base/auth/passwords/change_password.blade.php b/resources/views/themes/base/auth/passwords/change_password.blade.php index 6f4ad71..e4a02b1 100644 --- a/resources/views/themes/base/auth/passwords/change_password.blade.php +++ b/resources/views/themes/base/auth/passwords/change_password.blade.php @@ -14,9 +14,13 @@
-
+ {{ csrf_field() }} + @if ($errors->has('email')) +
{{ $errors->first('email') }}
+ @endif +
diff --git a/resources/views/themes/base/gallery/album_default.blade.php b/resources/views/themes/base/gallery/album_default.blade.php index 7db37dd..38b0bfd 100644 --- a/resources/views/themes/base/gallery/album_default.blade.php +++ b/resources/views/themes/base/gallery/album_default.blade.php @@ -1,21 +1,21 @@ @extends('themes.base.layout') @section('title', $album->name) -@section('breadcrumb') -