Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin login errors not showing #14

Open
knnhcn opened this issue Dec 8, 2017 · 4 comments
Open

Admin login errors not showing #14

knnhcn opened this issue Dec 8, 2017 · 4 comments

Comments

@knnhcn
Copy link

knnhcn commented Dec 8, 2017

I did all the tutorials and it works fine. But I have the problem, that admin login form does not show errors when for example entering a wrong e-mail addresse. The user login form shows the errors, but the admin login not.

@sayhicoelho
Copy link

Please post your Admin/LoginController's code. I'll try to help you.

@knnhcn
Copy link
Author

knnhcn commented Jan 27, 2018

Hi there, thank you for your offer. Here is my AdminLoginController:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;

class AdminLoginController extends Controller
{
    public function __construct()
    {
        $this->middleware('guest:admin', ['except' => ['logout']]);
    }

    public function showLoginForm()
    {
        return view('auth.admin-login');
    }

    public function login(Request $request)
    {
        // Validate the form data
        $this->validate($request, [
            'email'   => 'required|email',
            'password' => 'required|min:6'
        ]);
        // Attempt to log the user in
        if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
            // if successful, then redirect to their intended location
            return redirect()->intended(route('admin.dashboard'));
        }
        // if unsuccessful, then redirect back to the login with the form data
        return redirect()->back()->withInput($request->only('email', 'remember'));
    }

    public function logout()
    {
        Auth::guard('admin')->logout();
        return redirect('/');
    }
}

@sayhicoelho
Copy link

It seems fine.

What can be causing the bug:

  • In your view you are pointing the request to another controller
  • In your web routes you have not pointed to the AdminLoginController properly
  • Maybe you forgot the $error->has('email') ? 'has-error' : '' in <div class="form-group">

You should paste the admin login view here.

Furthermore, try to go into this step by step created by me: https://medium.com/@renandiett/laravel-5-4-trabalhando-com-autentica%C3%A7%C3%B5es-independentes-sem-packages-adicionais-6e50c11a0b79

If you do not understand Portuguese, I suggest you to use a translator like Google.

@tulioribeiro
Copy link

I had the same issue and it's because of this line:
return redirect()->back()->withInput($request->only('email', 'remember'));

To resolve this I followed the same paradigm of the AuthenticatesUsers trait:

protected function sendFailedLoginResponse(Request $request)
{
    throw ValidationException::withMessages([
        $this->username() => [trans('auth.failed')],
    ]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants