Merge user settings page #101

Merged
aheathershaw merged 8 commits from feature/99-user-settings-page into master 2018-09-12 21:25:02 +01:00
5 changed files with 58 additions and 2 deletions
Showing only changes of commit 929237ef90 - Show all commits

View File

@ -7,6 +7,7 @@ use App\Facade\Theme;
use App\Facade\UserConfig; use App\Facade\UserConfig;
use App\Helpers\DbHelper; use App\Helpers\DbHelper;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\SaveUserSettingsRequest;
use App\User; use App\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
@ -15,9 +16,31 @@ use Symfony\Component\HttpFoundation\Request;
class UserController extends Controller class UserController extends Controller
{ {
public function saveSettings(SaveUserSettingsRequest $request)
{
$data = $request->only(['name', 'email', 'profile_alias', 'enable_profile_page']);
if (UserConfig::get('require_email_verification'))
{
// 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"
unset($data['email']);
}
$user = $this->getUser();
$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) public function settings(Request $request)
{ {
return Theme::render('gallery.user_settings', [ return Theme::render('gallery.user_settings', [
'success' => $request->session()->get('success'),
'user' => $this->getUser() 'user' => $this->getUser()
]); ]);
} }

View File

@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
class SaveUserSettingsRequest 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 [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users,email,' . Auth::user()->id
// TODO include user profile alias
];
}
}

View File

@ -80,6 +80,7 @@ return [
], ],
'user_settings' => [ 'user_settings' => [
'change_password' => 'Change password', 'change_password' => 'Change password',
'settings_saved' => 'Your settings were updated successfully.',
'title' => 'Change my settings' 'title' => 'Change my settings'
] ]
]; ];

View File

@ -16,7 +16,6 @@
<div class="card-body"> <div class="card-body">
<form action="{{ route('saveUserSettings') }}" method="post"> <form action="{{ route('saveUserSettings') }}" method="post">
{{ csrf_field() }} {{ csrf_field() }}
{{ method_field('PUT') }}
<div class="form-group row{{ $errors->has('name') ? ' has-danger' : '' }}"> <div class="form-group row{{ $errors->has('name') ? ' has-danger' : '' }}">
<label class="col-md-4 col-form-label text-md-right" for="user-name">@lang('forms.name_label')</label> <label class="col-md-4 col-form-label text-md-right" for="user-name">@lang('forms.name_label')</label>

View File

@ -120,6 +120,6 @@ Route::get('u/{idOrAlias}', 'Gallery\UserController@show')
Route::get('me/settings', 'Gallery\UserController@settings') Route::get('me/settings', 'Gallery\UserController@settings')
->name('userSettings') ->name('userSettings')
->middleware('auth'); ->middleware('auth');
Route::get('me/save-settings', 'Gallery\UserController@saveSettings') Route::post('me/save-settings', 'Gallery\UserController@saveSettings')
->name('saveUserSettings') ->name('saveUserSettings')
->middleware('auth'); ->middleware('auth');