feat: forgot password
config: msg
This commit is contained in:
@@ -198,10 +198,14 @@ class AdminService implements AdminServiceInterface
|
||||
|
||||
public function resetAllCards(): void
|
||||
{
|
||||
$activeUserCount = User::where('status', config('constants.STATUS_ACTIVE'))->count();
|
||||
|
||||
User::where('status', config('constants.STATUS_ACTIVE'))->update([
|
||||
'card' => 0,
|
||||
'flag_send' => config('constants.FLAG_SEND_DISABLED'),
|
||||
]);
|
||||
|
||||
\Illuminate\Support\Facades\Log::info("Thực hiện reset thẻ hàng tháng thành công cho {$activeUserCount} tài khoản active.");
|
||||
}
|
||||
|
||||
public function updateAddCard(int $id, array $data): void
|
||||
|
||||
@@ -47,4 +47,36 @@ class AuthService implements AuthServiceInterface
|
||||
|
||||
return route('user.dashboard');
|
||||
}
|
||||
|
||||
public function forgotPassword(string $email): array
|
||||
{
|
||||
$email = \Illuminate\Support\Str::lower(trim($email));
|
||||
$user = User::where('mail', $email)->first();
|
||||
|
||||
if (!$user) {
|
||||
return ['success' => false, 'error_msg' => config('constants.MSG_FORGOT_PWD_EMAIL_NOT_FOUND')];
|
||||
}
|
||||
|
||||
if ($user->status != config('constants.STATUS_ACTIVE')) {
|
||||
return ['success' => false, 'error_msg' => config('constants.MSG_FORGOT_PWD_ACCOUNT_INACTIVE')];
|
||||
}
|
||||
|
||||
// Generate random password (8 characters)
|
||||
$newPassword = \Illuminate\Support\Str::random(8);
|
||||
|
||||
// Update password with md5 and set first_login flag to 1
|
||||
$user->pass = md5($newPassword);
|
||||
$user->first_login = config('constants.FIRST_LOGIN_TRUE');
|
||||
$user->save();
|
||||
|
||||
// Send Email
|
||||
try {
|
||||
\Illuminate\Support\Facades\Mail::to($user->mail)->send(new \App\Mail\ResetPasswordMail($user, $newPassword));
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error('Failed to send reset password email: ' . $e->getMessage());
|
||||
return ['success' => false, 'error_msg' => config('constants.MSG_FORGOT_PWD_MAIL_FAILED')];
|
||||
}
|
||||
|
||||
return ['success' => true, 'message' => config('constants.MSG_FORGOT_PWD_SUCCESS')];
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,6 @@ interface AuthServiceInterface
|
||||
public function logout(Request $request): void;
|
||||
|
||||
public function getRedirectRouteForUser(User $user): string;
|
||||
|
||||
public function forgotPassword(string $email): array;
|
||||
}
|
||||
Reference in New Issue
Block a user