forked from mirror/pixelfed
Update SettingsController
This commit is contained in:
parent
e70d54763c
commit
8fedeb4ce8
1 changed files with 37 additions and 3 deletions
|
@ -22,21 +22,32 @@ class SettingsController extends Controller
|
|||
{
|
||||
$this->validate($request, [
|
||||
'name' => 'required|string|max:30',
|
||||
'bio' => 'string|max:125'
|
||||
]);
|
||||
|
||||
$changes = false;
|
||||
$name = $request->input('name');
|
||||
$bio = $request->input('bio');
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
|
||||
if($profile->name != $name) {
|
||||
$changes = true;
|
||||
$user->name = $name;
|
||||
$user->save();
|
||||
|
||||
$profile->name = $name;
|
||||
$profile->save();
|
||||
}
|
||||
|
||||
if($profile->bio != $bio) {
|
||||
$changes = true;
|
||||
$profile->bio = $bio;
|
||||
}
|
||||
|
||||
if($changes === true) {
|
||||
$user->save();
|
||||
$profile->save();
|
||||
return redirect('/settings/home')->with('status', 'Profile successfully updated!');
|
||||
}
|
||||
|
||||
return redirect('/settings/home');
|
||||
}
|
||||
|
||||
|
@ -45,6 +56,29 @@ class SettingsController extends Controller
|
|||
return view('settings.password');
|
||||
}
|
||||
|
||||
public function passwordUpdate(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'current' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
'password_confirmation' => 'required|string',
|
||||
]);
|
||||
|
||||
$current = $request->input('current');
|
||||
$new = $request->input('password');
|
||||
$confirm = $request->input('password_confirmation');
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if(password_verify($current, $user->password) && $new === $confirm) {
|
||||
$user->password = bcrypt($new);
|
||||
$user->save();
|
||||
|
||||
return redirect('/settings/home')->with('status', 'Password successfully updated!');
|
||||
}
|
||||
return redirect('/settings/home')->with('error', 'There was an error with your request!');
|
||||
}
|
||||
|
||||
public function email()
|
||||
{
|
||||
return view('settings.email');
|
||||
|
|
Loading…
Reference in a new issue