fix(auth): isolate password reset flows by application role
This commit is contained in:
@@ -28,7 +28,8 @@ class ResetPasswordAttemptService
|
||||
try {
|
||||
$attemptId = DB::transaction(function () use ($email, $emailFingerprint, $reason): ?int {
|
||||
$user = User::query()
|
||||
->where('email', $email)
|
||||
->where('active_email', mb_strtolower(trim($email)))
|
||||
->where('rol_codigo', RoleCode::User->value)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
@@ -65,7 +66,7 @@ class ResetPasswordAttemptService
|
||||
try {
|
||||
$result = DB::transaction(function () use ($email, $emailFingerprint, $reason): ?array {
|
||||
$user = User::query()
|
||||
->where('email', $email)
|
||||
->where('active_email', mb_strtolower(trim($email)))
|
||||
->where('rol_codigo', RoleCode::AdminApp->value)
|
||||
->whereNotNull('tenant_codigo')
|
||||
->lockForUpdate()
|
||||
@@ -113,7 +114,7 @@ class ResetPasswordAttemptService
|
||||
try {
|
||||
$result = DB::transaction(function () use ($email, $emailFingerprint, $reason): ?array {
|
||||
$user = User::query()
|
||||
->where('email', $email)
|
||||
->where('active_email', mb_strtolower(trim($email)))
|
||||
->where('rol_codigo', RoleCode::Scanner->value)
|
||||
->whereNotNull('tenant_codigo')
|
||||
->lockForUpdate()
|
||||
@@ -152,14 +153,15 @@ class ResetPasswordAttemptService
|
||||
);
|
||||
}
|
||||
|
||||
public function validateCode(string $email, string $code): string
|
||||
public function validateCode(string $email, string $code, RoleCode $role = RoleCode::User): string
|
||||
{
|
||||
$emailFingerprint = $this->emailFingerprint($email);
|
||||
|
||||
try {
|
||||
return DB::transaction(function () use ($email, $code, $emailFingerprint): string {
|
||||
return DB::transaction(function () use ($email, $code, $emailFingerprint, $role): string {
|
||||
$user = User::query()
|
||||
->where('email', $email)
|
||||
->where('active_email', mb_strtolower(trim($email)))
|
||||
->where('rol_codigo', $role->value)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
@@ -207,14 +209,15 @@ class ResetPasswordAttemptService
|
||||
}
|
||||
}
|
||||
|
||||
public function resetPassword(string $email, string $code, string $password): bool
|
||||
public function resetPassword(string $email, string $code, string $password, RoleCode $role = RoleCode::User): bool
|
||||
{
|
||||
$emailFingerprint = $this->emailFingerprint($email);
|
||||
|
||||
try {
|
||||
return DB::transaction(function () use ($email, $code, $password, $emailFingerprint): bool {
|
||||
return DB::transaction(function () use ($email, $code, $password, $emailFingerprint, $role): bool {
|
||||
$user = User::query()
|
||||
->where('email', $email)
|
||||
->where('active_email', mb_strtolower(trim($email)))
|
||||
->where('rol_codigo', $role->value)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user