Parcourir la source

feat: adiciona URL

ebagabee il y a 3 semaines
Parent
commit
63bf0d45ec

+ 4 - 1
app/Http/Controllers/AuthController.php

@@ -54,7 +54,10 @@ public function forgotPassword(ForgotPasswordRequest $request): JsonResponse
     {
         $validated = $request->validated();
 
-        $sent = $this->authService->forgotPassword(email: $validated['email']);
+        $sent = $this->authService->forgotPassword(
+            email: $validated['email'],
+            portal: $validated['portal'] ?? 'franchisee',
+        );
 
         if (!$sent) {
             return $this->errorResponse(message: __('auth.email_not_found'), code: 422);

+ 2 - 1
app/Http/Requests/ForgotPasswordRequest.php

@@ -14,7 +14,8 @@ public function authorize(): bool
     public function rules(): array
     {
         return [
-            'email' => ['required', 'string', 'email'],
+            'email'  => ['required', 'string', 'email'],
+            'portal' => ['nullable', 'string', 'in:franchisor,franchisee'],
         ];
     }
 }

+ 6 - 2
app/Services/AuthService.php

@@ -77,7 +77,7 @@ public function refresh(string $refreshToken): ?array
         ];
     }
 
-    public function forgotPassword(string $email): bool
+    public function forgotPassword(string $email, string $portal = 'franchisee'): bool
     {
         $user = User::where('email', $email)->first();
 
@@ -96,7 +96,11 @@ public function forgotPassword(string $email): bool
             ]
         );
 
-        $recoveryLink = config('app.franchisee_url') . '/recovery-password?email=' . urlencode($email);
+        $baseUrl = $portal === 'franchisor'
+            ? config('app.franchisor_url')
+            : config('app.franchisee_url');
+
+        $recoveryLink = $baseUrl . '/recovery-password?email=' . urlencode($email);
 
         Mail::to($email)->send(new PasswordResetCodeMail($code, $recoveryLink));
 

+ 3 - 1
config/app.php

@@ -54,7 +54,9 @@
 
     'url' => env('APP_URL', 'http://localhost'),
 
-    'franchisee_url' => env('FRANCHISEE_URL', 'http://localhost:9000'),
+    'franchisor_url' => env('FRANCHISOR_URL', 'http://localhost:9000'),
+
+    'franchisee_url' => env('FRANCHISEE_URL', 'http://localhost:9001'),
 
     /*
     |--------------------------------------------------------------------------