Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 login doesn't work, no redirect and no errors

my Laravel login worked last week and now it doesn't (using the standard login generated by Laravel). I don't get an error message (wrong password, exceptions, anything). Every time I press "Login" it reloads the page. I have set the redirect to /member. Does anyone have an idea how to fix this?

Here are some files:

routes.php:

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

if(env("APP_ENV") == "prod"){
    Route::get('/', function() {
        return view("pages.demo");
    });
} else {

    Route::get('/', 'PagesController@index');

    Route::group(['middleware' => ['loggedin']], function(){
        Route::get('member/', function(){
            return redirect('member/dashboard');
        });
        Route::get('member/dashboard', 'PagesController@dashboard');
        Route::get('member/tree', 'TreeController@displayTree');
        Route::get('member/statistics', 'PagesController@statistics');
        Route::get('member/link', 'PagesController@link');
        Route::get('member/advertising-tools', 'PagesController@advertising');
    });

    Route::get('/click/{idhash}', 'ClickController@clickHandler');



    //Route::get('/login', 'PagesController@login');
    //Route::get('/register', 'PagesController@register');
    Route::auth();
}

login.blade.php:

            <div>
                <h1>
                    <span class="navy">ReferralTree</span>
                    <br/>
                    Login
                </h1>
            </div>
            <br/>
            <div class="col-md-8 col-md-offset-2">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
                            {!! csrf_field() !!}

                            <div class="form-group{{ $errors->has('user_email') ? ' has-error' : '' }}">
                                <label class="col-md-4 control-label">E-Mail Address</label>

                                <div class="col-md-6">
                                    <input type="user_email" class="form-control" name="user_email"
                                           value="{{ old('user_email') }}">

                                    @if ($errors->has('user_email'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('user_email') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>

                            <div class="form-group{{ $errors->has('user_password') ? ' has-error' : '' }}">
                                <label class="col-md-4 control-label">Password</label>

                                <div class="col-md-6">
                                    <input type="password" class="form-control" name="user_password">

                                    @if ($errors->has('user_password'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('user_password') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-4">
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" name="remember"> Remember Me
                                        </label>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-4">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fa fa-btn fa-sign-in"></i>Login
                                    </button>

                                    <a class="btn btn-link" href="{{ url('/password/reset') }}">Forgot Your
                                        Password?</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

AuthController.php:

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/member';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'user_firstname' => 'required|max:255',
            'user_lastname' => 'required|max:255',
            'user_email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array $data
     * @return User
     */
    protected function create(array $data)
    {

        $cookie = request()->cookie('referrer');
        if($cookie != null) {
            $user_click_id = request()->cookie('referrer');
        } else {
            $user_click_id = 0;
        }

            $user_create = User::create([
                'user_firstname' => $data['user_firstname'],
                'user_lastname' => $data['user_lastname'],
                'user_email' => $data['user_email'],
                'user_password' => bcrypt($data['password']),
                'user_country' => $data['user_country'],
                'user_city' => $data['user_city'],
                'user_streetname' => $data['user_streetname'],
                'user_zipcode' => $data['user_zipcode'],
                'user_dob' => $data['user_dob'],
                'user_click_id' => $user_click_id,
                'user_registerip' => $_SERVER['REMOTE_ADDR']
            ]);



        $user_create->user_id_hash = md5($user_create->user_id);
        $user_create->save();

        return $user_create;
    }


    public function postLogin(Request $request)
    {
        $this->validate($request, [
            'user_email' => 'required|email', 'user_password' => 'required',
        ]);

        $credentials = $request->only('user_email', 'user_password');

        if ($this->auth->attempt($credentials, $request->has('remember'))) {
            return redirect()->intended($this->redirectPath());
        }

        return redirect($this->loginPath())
            ->withInput($request->only('user_email', 'remember'))
            ->withErrors([
                'user_email' => $this->getFailedLoginMessage(),
            ]);
    }
}

If you need more info I will post it here.

php artisan route:list

+--------+----------+--------------------------+------+-----------------------------------------------------------------+---------------+
| Domain | Method   | URI                      | Name | Action                                                          | Middleware    |
+--------+----------+--------------------------+------+-----------------------------------------------------------------+---------------+
|        | GET|HEAD | /                        |      | App\Http\Controllers\PagesController@index                      | web           |
|        | GET|HEAD | click/{idhash}           |      | App\Http\Controllers\ClickController@clickHandler               | web           |
|        | GET|HEAD | login                    |      | App\Http\Controllers\Auth\AuthController@showLoginForm          | web,web,guest |
|        | POST     | login                    |      | App\Http\Controllers\Auth\AuthController@login                  | web,web,guest |
|        | GET|HEAD | logout                   |      | App\Http\Controllers\Auth\AuthController@logout                 | web,web       |
|        | GET|HEAD | member                   |      | Closure                                                         | web,loggedin  |
|        | GET|HEAD | member/advertising-tools |      | App\Http\Controllers\PagesController@advertising                | web,loggedin  |
|        | GET|HEAD | member/dashboard         |      | App\Http\Controllers\PagesController@dashboard                  | web,loggedin  |
|        | GET|HEAD | member/link              |      | App\Http\Controllers\PagesController@link                       | web,loggedin  |
|        | GET|HEAD | member/statistics        |      | App\Http\Controllers\PagesController@statistics                 | web,loggedin  |
|        | GET|HEAD | member/tree              |      | App\Http\Controllers\TreeController@displayTree                 | web,loggedin  |
|        | POST     | password/email           |      | App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail | web,web,guest |
|        | POST     | password/reset           |      | App\Http\Controllers\Auth\PasswordController@reset              | web,web,guest |
|        | GET|HEAD | password/reset/{token?}  |      | App\Http\Controllers\Auth\PasswordController@showResetForm      | web,web,guest |
|        | GET|HEAD | register                 |      | App\Http\Controllers\Auth\AuthController@showRegistrationForm   | web,web,guest |
|        | POST     | register                 |      | App\Http\Controllers\Auth\AuthController@register               | web,web,guest |
+--------+----------+--------------------------+------+-----------------------------------------------------------------+---------------+
like image 495
Lars Koole Avatar asked Jun 03 '16 09:06

Lars Koole


1 Answers

I found out the answer by combining some of your answers and comments!

I added use Illuminate\Http\Request; to the AuthController

I also renamed "password" to "user_password" in the EloquentUserProvider

And I edited the routes: Route::get('/login', 'PagesController@login'); Route::post('/login', 'Auth\AuthController@postLogin');

like image 164
Lars Koole Avatar answered Oct 27 '22 02:10

Lars Koole