简体   繁体   中英

User login does not work in laravel with sql server. previously created database

I am working on a project where the database on sql server already existed, so I had to change the names of the tables and columns to run the user registry. Registration works perfectly, now, login does not work. When trying to login, the page does nothing, just reload. If you could help me, I would appreciate it very much, thanks

------------User model--------------
 <?php

namespace App;

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

class User extends Authenticatable
{
    protected $table = 'tb_postulantes';
    protected $primaryKey = 'id_postulante';

    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'nombre_postulante',  'appaterno_postulante', 'correo_postulante', 'password_postulante',
        'apmaterno_postulante', 'telefono_postulante', 'fechaingreso_postulante', 'estado_postulante'





    ];

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

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

-------RegisterController----------
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

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

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


    /**
     * 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, [
            'nombre_postulante' => ['required', 'string', 'max:255'],
            'correo_postulante' => ['required', 'string', 'email', 'max:255', 'unique:tb_postulantes,correo_postulante'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'nombre_postulante' => $data['nombre_postulante'],
            'correo_postulante' => $data['correo_postulante'],
            'password_postulante' => Hash::make($data['password']),
            'appaterno_postulante' => $data['nombre_postulante'],
            'apmaterno_postulante' => $data['nombre_postulante'],
            'telefono_postulante' => $data['nombre_postulante'],
            'fechaingreso_postulante' => '2012-02-21T18:10:00',
            'estado_postulante' => '1',



        ]);
    }
}

----------LoginController--------
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    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 beforelogin()
    {

        return view('Auth.beforelogin');
    }
}

well first of all Laravel authentication uses field 'email' to login user - you dont have this field in your User model so if you want to change this you have to define username in your LoginController like so:

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

And for different password field you can use accessor in your User Model like so:

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

You can find some more informaction in Laravel Documentation https://laravel.com/docs/5.5/authentication#included-authenticating

But if you want to use all three parameters to log in users I will recommend making your own LoginController with different logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM