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: KoPKB/My-KOPKB#13
This commit is contained in:
@@ -94,19 +94,31 @@ class FortifyServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Fortify::authenticateUsing(function (Request $request) {
|
Fortify::authenticateUsing(function (Request $request) {
|
||||||
$user = User::where('email', $request->email)->first();
|
$user = User::where('email', $request->email)->first();
|
||||||
|
$invalidCredentialsMessage = 'Emel atau kata laluan tidak sah.';
|
||||||
// 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()],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -59,10 +59,13 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
// Handle Validation exceptions (422 errors)
|
// Handle Validation exceptions (422 errors)
|
||||||
$exceptions->render(function (Illuminate\Validation\ValidationException $e, $request) {
|
$exceptions->render(function (Illuminate\Validation\ValidationException $e, $request) {
|
||||||
if ($request->expectsJson()) {
|
if ($request->expectsJson()) {
|
||||||
|
$errors = $e->errors();
|
||||||
|
$firstMessage = collect($errors)->flatten()->first() ?? 'Data tidak sah.';
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Data tidak sah.',
|
'message' => $firstMessage,
|
||||||
'errors' => $e->errors(),
|
'errors' => $errors,
|
||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user