#99: User settings are now saving. Still need to implement validation on the profile name and e-mail verification for the new e-mail address.
This commit is contained in:
parent
e4863af668
commit
929237ef90
@ -7,6 +7,7 @@ use App\Facade\Theme;
|
||||
use App\Facade\UserConfig;
|
||||
use App\Helpers\DbHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SaveUserSettingsRequest;
|
||||
use App\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\App;
|
||||
@ -15,9 +16,31 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
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)
|
||||
{
|
||||
return Theme::render('gallery.user_settings', [
|
||||
'success' => $request->session()->get('success'),
|
||||
'user' => $this->getUser()
|
||||
]);
|
||||
}
|
||||
|
33
app/Http/Requests/SaveUserSettingsRequest.php
Normal file
33
app/Http/Requests/SaveUserSettingsRequest.php
Normal 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
|
||||
];
|
||||
}
|
||||
}
|
@ -80,6 +80,7 @@ return [
|
||||
],
|
||||
'user_settings' => [
|
||||
'change_password' => 'Change password',
|
||||
'settings_saved' => 'Your settings were updated successfully.',
|
||||
'title' => 'Change my settings'
|
||||
]
|
||||
];
|
@ -16,7 +16,6 @@
|
||||
<div class="card-body">
|
||||
<form action="{{ route('saveUserSettings') }}" method="post">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('PUT') }}
|
||||
|
||||
<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>
|
||||
|
@ -120,6 +120,6 @@ Route::get('u/{idOrAlias}', 'Gallery\UserController@show')
|
||||
Route::get('me/settings', 'Gallery\UserController@settings')
|
||||
->name('userSettings')
|
||||
->middleware('auth');
|
||||
Route::get('me/save-settings', 'Gallery\UserController@saveSettings')
|
||||
Route::post('me/save-settings', 'Gallery\UserController@saveSettings')
|
||||
->name('saveUserSettings')
|
||||
->middleware('auth');
|
Loading…
Reference in New Issue
Block a user