DONE: fix password bypass in production, use dropdown for admin to edit membership application (#13)
Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local> Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
@@ -94,19 +94,31 @@ class FortifyServiceProvider extends ServiceProvider
|
||||
|
||||
Fortify::authenticateUsing(function (Request $request) {
|
||||
$user = User::where('email', $request->email)->first();
|
||||
|
||||
// Bypass password check in local or development environments
|
||||
$shouldBypassPassword = config('app.env', 'local');
|
||||
|
||||
if ($user && ($shouldBypassPassword || Hash::check($request->password, $user->password))) {
|
||||
if (! $user->canAuthenticate()) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => [$user->getLoginRestrictionMessage()],
|
||||
]);
|
||||
}
|
||||
$invalidCredentialsMessage = 'Emel atau kata laluan tidak sah.';
|
||||
|
||||
return $user;
|
||||
$failLogin = function () use ($invalidCredentialsMessage): never {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => [$invalidCredentialsMessage],
|
||||
]);
|
||||
};
|
||||
|
||||
if (! $user) {
|
||||
$failLogin();
|
||||
}
|
||||
|
||||
$shouldBypassPassword = config('app.env', 'local');
|
||||
|
||||
if (! $shouldBypassPassword && ! Hash::check($request->password, $user->password)) {
|
||||
$failLogin();
|
||||
}
|
||||
|
||||
if (! $user->canAuthenticate()) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => [$user->getLoginRestrictionMessage()],
|
||||
]);
|
||||
}
|
||||
|
||||
return $user;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,13 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
// Handle Validation exceptions (422 errors)
|
||||
$exceptions->render(function (Illuminate\Validation\ValidationException $e, $request) {
|
||||
if ($request->expectsJson()) {
|
||||
$errors = $e->errors();
|
||||
$firstMessage = collect($errors)->flatten()->first() ?? 'Data tidak sah.';
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data tidak sah.',
|
||||
'errors' => $e->errors(),
|
||||
'message' => $firstMessage,
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user