diff --git a/app/Http/Controllers/MailController.php b/app/Http/Controllers/MailController.php index 2e34fe9..b4ed019 100644 --- a/app/Http/Controllers/MailController.php +++ b/app/Http/Controllers/MailController.php @@ -5,29 +5,45 @@ use Mail; use App\Models\Cliente; use App\Models\Funcionario; +use Illuminate\Support\Facades\DB; class MailController extends Controller { public function recuperaAcessoCliente(Request $request){ - $novaSenha = rand(100000, 999999); - define('email', $request->email); - Cliente::alterarSenha($request->email, $novaSenha); - Mail::raw("Sua nova senha é: {$novaSenha}", function($message) - { - $message->to(email, 'BusOn')->subject('BusOn - Recuperação de Senha'); - }); - return view("auth.login"); + $usuario = DB::select("select * from cliente where email = ?", [$request->email]); + if(!empty($usuario)){ + $novaSenha = rand(100000, 999999); + define('email', $request->email); + Cliente::alterarSenha($request->email, $novaSenha); + Mail::raw("Sua nova senha é: {$novaSenha}", function($message) + { + $message->to(email, 'BusOn')->subject('BusOn - Recuperação de Senha'); + }); + return redirect()->route('clienteLogin') + ->with('success', 'Email foi enviado com a nova senha.'); + }else{ + return redirect()->back() + ->with('error', 'Email não cadastrado no nosso sistema.'); + } + } public function recuperaAcessoFuncionario(Request $request){ - $novaSenha = rand(100000, 999999); - define('email', $request->email); - Funcionario::alterarSenha($request->email, $novaSenha); - Mail::raw("Sua nova senha é: {$novaSenha}", function($message) - { - $message->to(email, 'BusOn')->subject('BusOn - Recuperação de Senha'); - }); - return ('/login/funcionario'); + $usuario = DB::select("select * from cliente where email = ?", [$request->email]); + if(!empty($usuario)){ + $novaSenha = rand(100000, 999999); + define('email', $request->email); + Funcionario::alterarSenha($request->email, $novaSenha); + Mail::raw("Sua nova senha é: {$novaSenha}", function($message) + { + $message->to(email, 'BusOn')->subject('BusOn - Recuperação de Senha'); + }); + return redirect()->route('clienteLogin') + ->with('success', 'Email foi enviado com a nova senha.'); + }else{ + return redirect()->back() + ->with('error', 'Email não cadastrado no nosso sistema.'); + } } } diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 884d35e..7a65a4c 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -24,19 +24,32 @@
- @if(Session::has('message')) -
- × - {{session('message')}} -
- @endif - - @if(Session::has('error')) -
- × - {{session('error')}} -
- @endif + @if ($errors->any()) +
+ × +
    + @foreach($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + @if (session('success')) +
+ × +
    +
  • {{session ('success')}}
  • +
+
+ @endif + @if (session('error')) +
+ × +
    +
  • {{session ('error')}}
  • +
+
+ @endif diff --git a/resources/views/cliente/recuperarAcesso.blade.php b/resources/views/cliente/recuperarAcesso.blade.php index 30260f4..2f68425 100644 --- a/resources/views/cliente/recuperarAcesso.blade.php +++ b/resources/views/cliente/recuperarAcesso.blade.php @@ -7,12 +7,38 @@
Recuperar Acesso
+ @if ($errors->any()) +
+ × +
    + @foreach($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + @if (session('success')) +
+ × +
    +
  • {{session ('success')}}
  • +
+
+ @endif + @if (session('error')) +
+ × +
    +
  • {{session ('error')}}
  • +
+
+ @endif
@csrf
- +
diff --git a/resources/views/funcionario/recuperarAcesso.blade.php b/resources/views/funcionario/recuperarAcesso.blade.php index 7a1def9..aa22cbc 100644 --- a/resources/views/funcionario/recuperarAcesso.blade.php +++ b/resources/views/funcionario/recuperarAcesso.blade.php @@ -7,12 +7,38 @@
Recuperar Acesso
+ @if ($errors->any()) +
+ × +
    + @foreach($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + @if (session('success')) +
+ × +
    +
  • {{session ('success')}}
  • +
+
+ @endif + @if (session('error')) +
+ × +
    +
  • {{session ('error')}}
  • +
+
+ @endif
@csrf
- +