You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.7 KiB
49 lines
1.7 KiB
<?php |
|
|
|
namespace App\Http\Controllers\Auth; |
|
|
|
use Illuminate\Http\Request; |
|
use App\Http\Controllers\Controller; |
|
use Illuminate\Support\Facades\Hash; |
|
use Illuminate\Http\RedirectResponse; |
|
use Illuminate\Validation\Rules\Password; |
|
use Illuminate\Validation\ValidationException; |
|
|
|
class PasswordController extends Controller |
|
{ |
|
/** |
|
* Update the user's password. |
|
*/ |
|
// public function update(Request $request): RedirectResponse |
|
// { |
|
// $validated = $request->validateWithBag('updatePassword', [ |
|
// 'current_password' => ['required', 'current_password'], |
|
// 'password' => ['required', Password::defaults(), 'confirmed'], |
|
// ]); |
|
|
|
// $request->user()->update([ |
|
// 'password' => Hash::make($validated['password']), |
|
// ]); |
|
|
|
// return back()->with('status', 'password-updated'); |
|
// } |
|
public function update(Request $request): RedirectResponse |
|
{ |
|
try { |
|
$validated = $request->validateWithBag('updatePassword', [ |
|
'current_password' => ['required', 'current_password'], |
|
'password' => ['required', Password::defaults(), 'confirmed'], |
|
]); |
|
|
|
$request->user()->update([ |
|
'password' => Hash::make($validated['password']), |
|
]); |
|
|
|
return back()->with('success-password', 'Password berhasil diperbarui.'); |
|
} catch (ValidationException $e) { |
|
return back()->withErrors($e->errors(), 'updatePassword')->with('error-password', 'Gagal memperbarui password. Silakan periksa kembali masukan Anda.'); |
|
} catch (\Exception $e) { |
|
return back()->with('error-password', 'Gagal memperbarui password. Silakan coba lagi.'); |
|
} |
|
} |
|
}
|
|
|