4

I inherited an application that I am currently porting to laravel. They already have the database designed and they use different tables for authentication than the defaults for laravel. In the database, they have upper case field names.

The emails are saved in a field called MCP_EMAIL and the password are saved in a field called MCP_PASSWORD

I have managed to change the registration process and users can register fine. The problem is with login. When you attempt to login, nothing happens. No error messages, no logs, nothing. It just keeps coming back to the login page!

Here is the user class.

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{

    use Notifiable;

    protected $table = "user_profiles";

    protected $primaryKey ="MCP_ID";

    protected $rememberTokenName = 'MCP_REMEMBER_TOKEN';


    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'MCP_DISPLAY_NAME', 'MCP_EMAIL', 'MCP_PASSWORD',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    const CREATED_AT  = "ADDED";
    const UPDATED_AT = "MODIFIED";

    public function getAuthPassword(){
        return $this->MCP_PASSWORD;
    }

    //seems to be a repetition of protected$rememberTokenName 
    public function getRememberTokenName()
    {
        return $this->MCP_REMEMBER_TOKEN;
    }

}

And the login controller

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facade\Auth;
use Log;

class LoginController extends Controller
{       

    use AuthenticatesUsers;

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

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function username(){
        return 'MCP_EMAIL';
    }

}

What am I missing? Why can't I see any error messages?

Update

I was doing everything right. Besides doing everything above, you need to change the name of the input in login.blade.php

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

                            <div class="col-md-6">
                                <input id="MCP_EMAIL" type="email" class="form-control" name="MCP_EMAIL" value="{{ old('MCP_EMAIL') }}" required autofocus>

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

See related question here

Community
  • 1
  • 1
The Sammie
  • 1,218
  • 15
  • 25

1 Answers1

-3

Did you know that L5.4 ships with pre-built authentication, to provide a quick way to scaffold you need to run php artisan auth:make, I'm pretty sure that you need to surcharge some functions within AuthenticatesUsers trait, unless the database columns. Check this out AuthenticatesUsers

In the case you don't use Authentication scaffolding :

1) there's no need to remove the AuthenticatesUsers from your LoginController

2) Try to implement your LoginController according this section Manually Authenticating Users

  • I am not sure If you read my question correctly or if I wasn't articulate, but I was using the inbuilt authentication. It is just that my table wasn't called `users` and my my email field wasn't called `email`. I found a solution though! – The Sammie Sep 04 '17 at 09:30