Laravel - Redirect :: to or Redirect :: back giving TokenMismatchException error?

0

The following is happening, I have the login screen that does some checks, if it does not happen in some of my Controller I make a redirect to url login with the message of error .

error if I give redirect to the page.

I've tried using:

return Redirect::to('login');

and

return Redirect::back()->withInput();'

but without success.

Follow the codes:

View :

<form class="sign-in form-horizontal shadow rounded no-overflow" action="{{url('login/doLogin')}}" method="post">
    {{ csrf_field() }}
    <input type="text" class="form-control input-sm" placeholder="E-mail" name="username">
    <input type="password" class="form-control input-sm" placeholder="Senha" name="password">
    <button type="submit" class="btn btn-theme btn-lg btn-block no-margin rounded" id="login-btn">Entrar</button>
</form>

Controller :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use Hash;
use Auth;
use Redirect;

class AuthController extends BaseController
{
    public $request = null;
    public function __construct(Request $request) {
        $this->request = $request;
    }
    public function doLogin(){
        $erro = "Erro ao logar";
        $requestedUser = $this->request->get('username');
        $requestedPassword = $this->request->get('password');
        $usuario = User::where('email', '=', $requestedUser)->first();
        if ($usuario) {
            if (Hash::check($requestedPassword, $usuario->password)) {
                if (!$usuario->userValidation) {
                    Auth::loginUsingId($usuario->id);
                    $this->toastrMessage("success", 'Logado com sucesso!');
                    return redirect('dashboard');
                }else{
                    $erro = "Acesse o seu e-mail para autenticar sua conta";
                }
            }else{
                $erro = "Senha incorreta";
            }
        }else{
            $erro = "Usuário não encontrado";
        }
        $this->toastrMessage("error", $erro);
        return Redirect::back()->withInput();
        // return Redirect::to('login');
    }
}

Note: The version of TokenMismatchException is refresh and I have already done projects with previous versions of Laravel and in none it gave error .

Note²: As a temporary measure I put the route that logs in 5.4 of Laravel .

    
asked by anonymous 24.02.2017 / 14:27

0 answers