2FAuth/app/Http/Controllers/Auth/PasswordController.php

37 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2022-03-15 14:47:07 +01:00
namespace App\Http\Controllers\Auth;
2022-03-15 14:47:07 +01:00
use App\Http\Requests\UserPatchPwdRequest;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
2022-10-18 17:34:56 +02:00
use Illuminate\Support\Facades\Log;
class PasswordController extends Controller
{
/**
* Update the user's password.
*
* @param \App\Http\Requests\UserPatchPwdRequest $request
2021-11-26 11:18:58 +01:00
* @return \Illuminate\Http\JsonResponse
*/
public function update(UserPatchPwdRequest $request)
{
$validated = $request->validated();
if (!Hash::check( $validated['currentPassword'], Auth::user()->password) ) {
2022-10-18 17:34:56 +02:00
Log::notice('Password update failed: wrong password provided');
return response()->json(['message' => __('errors.wrong_current_password')], 400);
}
if (!config('2fauth.config.isDemoApp') ) {
$request->user()->update([
'password' => bcrypt($validated['password']),
]);
2022-10-18 17:34:56 +02:00
Log::info('User password updated');
}
return response()->json(['message' => __('auth.forms.password_successfully_changed')]);
}
}