1
resposta

não consigo fazer login

mesmo aparecendo que o email já está registrado no banco de dados, não consigo entrar com essa conta na tela de login UserController:

<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class UsersController
{
    public function create()
    {
        return view('users.create');
    }

    public function store(Request $request)
    {
        $data = $request->except(['_token']);
        $data['password'] = Hash::make($data['password']);

        $user = User::create($data);
        Auth::login($user);

        return to_route('series.index');
    }
}

web.php:

<?php

use App\Http\Controllers\EpisodesController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\SeasonsController;
use App\Http\Controllers\SeriesController;
use App\Http\Controllers\UsersController;
use Illuminate\Support\Facades\Route;
use  Illuminate\Http\Request;


Route::get('/', function () {
    return redirect('/series');
})->middleware(\App\Http\Middleware\Authenticador::class);

Route::resource('/series', SeriesController::class)
    ->except(['show']);

Route::get('/series/{series}/seasons', [SeasonsController::class, 'index'])->name('seasons.index');

Route::get('/seasons/{season}/episodes', [EpisodesController::class,'index'])->name('episodes.index');
Route::post('/seasons/{season}/episodes', [EpisodesController::class, 'update'])->name('episode.update');

Route::get('/login', [LoginController::class, 'index'])->name('login');
Route::post('/login',[LoginController::class,'store'])->name('sign-in');
Route::get('/logout', [LoginController::class,'destroy'])->name('logout');

Route::get('/register', [UsersController::class, 'create'])->name('users.create');
Route::post('/register', [UsersController::class, 'store'])->name('users.store');


index.blade:

<x-layout title="">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f2f2f2;
        }
        .login-container {
            padding: 40px;
            border-radius: 5px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2); /* Adicionando sombra ao redor do quadrado */
            background-color: #fff;
        }
    </style>
    <form method="post">
        @csrf
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-md-4 login-container">
                    <h2 class="text-center mb-4">SeriesWatch</h2>
                    <form method="post">

                        <div class="form-group">
                            <input type="email" name="email" id="email" class="form-control" placeholder="E-mail" required>
                        </div>
                        <div class="form-group">
                            <input type="password" name="email" id="email" class="form-control" placeholder="Password" required>
                        </div>
                        <button class="btn btn-primary btn-block">Login</button>
                        <a class="btn btn-secondary mt-3" href="{{ route('users.create') }}">
                            sign-in
                        </a>
                    </form>
                </div>
            </div>
        </div>
    </form>
</x-layout>
1 resposta

Oiii, Arthur!

Você está repetindo o atributo "email" para o campo de senha. Isso pode estar causando a falha no login, pois o Laravel espera que o campo de senha tenha o atributo "password".

Você pode corrigir isso alterando a linha do campo de senha no arquivo index.blade.php para:

<input type="password" name="password" id="password" class="form-control" placeholder="Password" required>

Após fazer essa alteração, tente fazer o login novamente e verifique se o problema foi resolvido.

Espero ter ajudado e bons estudos!