diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 1141142..6de4f15 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -5,6 +5,7 @@ namespace App\Exceptions; use Exception; use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Validation\ValidationException; class Handler extends ExceptionHandler { @@ -63,4 +64,20 @@ class Handler extends ExceptionHandler ? response()->json(['message' => $exception->getMessage()], 401) : redirect()->guest(route('login')); } + + /** + * Convert a validation exception into a response. + * + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Validation\ValidationException $exception + * @return \Illuminate\Http\Response + */ + protected function invalid($request, ValidationException $exception) + { + flash()->error("Some form fields were not filled correctly."); + + return redirect($exception->redirectTo ?? url()->previous()) + ->withInput($request->except($this->dontFlash)) + ->withErrors($exception->errors(), $exception->errorBag); + } } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index fdbd6a1..2e42d19 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -27,20 +27,41 @@ class ProfileController extends Controller } /** - * Edit own profile + * Edit own profile (this does not include auth settings etc) * * @param User $user * @return \Illuminate\View\View */ - public function edit() + public function editProfile() { - return view('profile.edit')->with('user', \user()); + return view('profile.edit-profile')->with('user', \user()); + } + + public function editAccount() + { + return view('profile.edit-account', ['user' => user()]); } /** * Store changed profile */ - public function store(Request $request) + public function storeProfile(Request $request) + { + $input = $this->validate($request, [ + 'bio' => ['nullable', VALI_TEXT], + 'title' => ['required', VALI_LINE], + 'website' => ['required', VALI_LINE], + ]); + + $user = user(); + $user->fill($input->all()); + $user->save(); + + flash()->success('Settings saved'); + return back(); + } + + public function storeAccount(Request $request) { $input = $this->validate($request, [ 'name' => [ @@ -53,9 +74,6 @@ class ProfileController extends Controller VALI_EMAIL, Rule::unique('users')->ignoreModel(\user()), ], - 'bio' => ['nullable', VALI_TEXT], - 'title' => ['required', VALI_LINE], - 'website' => ['required', VALI_LINE], 'new_password' => ['nullable', 'confirmed', VALI_PASSWORD], ]); @@ -90,11 +108,6 @@ class ProfileController extends Controller return back(); } - public function manageOauth() - { - return view('profile.logins', ['user' => user()]); - } - public function forgetSocialLogin($id) { $identity = user()->socialIdentities()->where('id', $id)->first(); diff --git a/app/View/WidgetFactory.php b/app/View/WidgetFactory.php index ffa104b..c5ee215 100644 --- a/app/View/WidgetFactory.php +++ b/app/View/WidgetFactory.php @@ -21,11 +21,13 @@ class WidgetFactory ""; } - public function par($text, $extraClasses='') + public function par($text, $extraClasses='', $escape=true) { return "
". - "

fieldCols offset-md-$this->labelCols mb-2 ".e($extraClasses)."\">".e($text)."". + "

fieldCols offset-md-$this->labelCols mb-2 ".e($extraClasses)."\">". + ($escape ? e($text) : $text) . + "

". "
"; } diff --git a/resources/views/layouts/nav-buttons.blade.php b/resources/views/layouts/nav-buttons.blade.php index 9ec6a61..babc741 100644 --- a/resources/views/layouts/nav-buttons.blade.php +++ b/resources/views/layouts/nav-buttons.blade.php @@ -8,13 +8,13 @@ $aclass = $dropdown ? 'dropdown-item' : 'nav-link'; {!! $li !!} - {{ __('Settings') }} + {{ __('Profile') }} {!! $endli !!} {!! $li !!} - - {{ __('Security') }} + + {{ __('Account') }} {!! $endli !!} diff --git a/resources/views/profile/logins.blade.php b/resources/views/profile/edit-account.blade.php similarity index 97% rename from resources/views/profile/logins.blade.php rename to resources/views/profile/edit-account.blade.php index 2ba5544..96b56a0 100644 --- a/resources/views/profile/logins.blade.php +++ b/resources/views/profile/edit-account.blade.php @@ -5,12 +5,12 @@ @section('content') @php(Widget::setLayout(3, 7)) -
+ @csrf
- {!! Widget::header(1, 'Login Settings') !!} - {!! Widget::par('Confirm using the save button at the bottom.') !!} + {!! Widget::header(1, 'Your Account') !!} + {!! Widget::par('Confirm using the save button at the bottom.', 'text-muted') !!}
diff --git a/resources/views/profile/edit.blade.php b/resources/views/profile/edit-profile.blade.php similarity index 82% rename from resources/views/profile/edit.blade.php rename to resources/views/profile/edit-profile.blade.php index 85cf52b..42667b0 100644 --- a/resources/views/profile/edit.blade.php +++ b/resources/views/profile/edit-profile.blade.php @@ -10,7 +10,11 @@
@php(Widget::setLayout(3, 7)) - {!! Widget::header(1, 'Settings') !!} + {!! Widget::header(1, 'Your Profile') !!} + {!! Widget::par(' + Username can be changed on the + account settings page. + ', 'text-muted', false) !!} {!! Widget::text('title', 'Display Name')->value($user->title)->required()->autofocus() ->help('Shown on your profile page, tables, comments, etc.') !!} diff --git a/routes/web.php b/routes/web.php index 6eba96a..3665085 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,10 +30,13 @@ Route::group(['middleware' => 'auth'], function () { Route::group([ 'prefix' => 'profile', ], function () { - Route::get('edit', 'ProfileController@edit')->name('profile.edit'); - Route::post('edit', 'ProfileController@store')->name('profile.store'); + Route::get('edit', 'ProfileController@editProfile')->name('profile.edit'); + Route::post('edit', 'ProfileController@storeProfile')->name('profile.store'); + Route::post('create', 'TableController@storeNew')->name('table.storeNew'); - Route::get('logins', 'ProfileController@manageOauth')->name('profile.manage-oauth'); + + Route::get('logins', 'ProfileController@editAccount')->name('account.edit'); + Route::post('logins', 'ProfileController@storeAccount')->name('account.store'); }); });