unch-cms/app/Http/Controllers/ProfileController.php

55 lines
1.5 KiB
PHP
Raw Normal View History

2022-09-02 11:25:50 +07:00
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ProfileRequest;
use App\Http\Requests\PasswordRequest;
use Illuminate\Support\Facades\Hash;
class ProfileController extends Controller
{
/**
* Show the form for editing the profile.
*
* @return \Illuminate\View\View
*/
public function edit()
{
return view('profile.edit');
}
/**
* Update the profile
*
* @param \App\Http\Requests\ProfileRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function update(ProfileRequest $request)
{
if (auth()->user()->id == 1) {
return back()->withErrors(['not_allow_profile' => __('You are not allowed to change data for a default user.')]);
}
auth()->user()->update($request->all());
return back()->withStatus(__('Profile successfully updated.'));
}
/**
* Change the password
*
* @param \App\Http\Requests\PasswordRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function password(PasswordRequest $request)
{
if (auth()->user()->id == 1) {
return back()->withErrors(['not_allow_password' => __('You are not allowed to change the password for a default user.')]);
}
auth()->user()->update(['password' => Hash::make($request->get('password'))]);
return back()->withPasswordStatus(__('Password successfully updated.'));
}
}