Support the ongoing development of Laravel.io →
Authentication
Last updated 2 years ago.
0

See if parts of this thread helps ==http://laravel.io/forum/04-25-2015-debug-authentication. Look at my controller code in that post all of those use statements have to be at top.
If L5 request not get. See the Docs on request.

Last updated 9 years ago.
0

There is no username field in users table created by L5.

0

jimgwhit said:

See if parts of this thread helps ==http://laravel.io/forum/04-25-2015-debug-authentication. Look at my controller code in that post all of those use statements have to be at top.
If L5 request not get. See the Docs on request.

My postLogin method is exactly like yours, but im unable to do login

0

jimgwhit said:

See if parts of this thread helps ==http://laravel.io/forum/04-25-2015-debug-authentication. Look at my controller code in that post all of those use statements have to be at top.
If L5 request not get. See the Docs on request.

the user is getting logged in, if i registers it with the builtin REGISTER and LOGIN form of laravel, but if i tries to Register or login with my own form, it gives error

0

Are you using email or did you change yours to use userid, reread the documentation on this, email is optional but try it with email and see if it works. Is your MySQL database setup with the correct fields that you are using to log in check all this stuff.
Make sure you have these statements at the top of the auth controller.

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests\RegisterRequest;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

Show your view, model, controller, routes, code.
And are you wanting to use something other than email field for the login?

Last updated 9 years ago.
0

jimgwhit said:

Are you using email or did you change yours to use userid, reread the documentation on this, email is optional but try it with email and see if it works. Is your MySQL database setup with the correct fields that you are using to log in check all this stuff.
Make sure you have these statements at the top of the auth controller.

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests\RegisterRequest;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

Show your view, model, controller, routes, code.
And are you wanting to use something other than email field for the login?

Now i'm using email but still same problem

this is my authController

<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Registrar; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; use Illuminate\Http\Request; use Input; use App\Http\Requests\CreateCustomerLoginRequest; 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; //protected $auth; protected $redirectTo= 'SignUpOptPage'; /** * Create a new authentication controller instance. * * @param \Illuminate\Contracts\Auth\Guard $auth * @param \Illuminate\Contracts\Auth\Registrar $registrar * @return void */ public function __construct(Guard $auth, Registrar $registrar) { $this->auth = $auth; $this->registrar = $registrar; $this->middleware('guest', ['except' => 'getLogout']); } public function postLogin(Request $request) { $tvar = $request->input('email'); $pw = $request->input('password'); if ($this->auth->attempt(['email' => $tvar, 'password' => $pw])) { return redirect('home'); } echo ' not logged in'; } /* public function authenticate() { if (Auth::attempt(['email' => $email, 'password' => $password])) { return redirect()->intended('SignUpOptPage'); } } */ }
0

jimgwhit said:

Are you using email or did you change yours to use userid, reread the documentation on this, email is optional but try it with email and see if it works. Is your MySQL database setup with the correct fields that you are using to log in check all this stuff.
Make sure you have these statements at the top of the auth controller.

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests\RegisterRequest;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

Show your view, model, controller, routes, code.
And are you wanting to use something other than email field for the login?

This is my Route Route :: post('CustomerLogin' , 'Auth\AuthController@postLogin');

My View

@extends('BootstrapSignUp')

@section('content')

{!! Form::open() !!}

<h1>Login</h1> <!-- if there are login errors, show them here --> <p> {!! Form::label('Email', 'Email') !!} {!! Form::email('email',null,['placeholder'=>'Enter Your EmailAddress'])!!} <p> {!! Form::label('Password', 'Password') !!} {!! Form::password('password',null,['placeholder'=>'Enter Your Password']) !!} </p>

{!! Form::submit('Submit',['class'=>'btn btn-primary btn-block btn-small outline form-control'])!!}

{!! Form::close() !!}

@if ($errors->any())

<div class= 'alert alert-danger' >
<ul >
 @foreach ($errors->all() as $errors)
      
     <li>
     {{ $errors }}
     </li>
  @endforeach      
</ul>
    </div>

@endif

@stop

0

jimgwhit said:

Are you using email or did you change yours to use userid, reread the documentation on this, email is optional but try it with email and see if it works. Is your MySQL database setup with the correct fields that you are using to log in check all this stuff.
Make sure you have these statements at the top of the auth controller.

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests\RegisterRequest;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

Show your view, model, controller, routes, code.
And are you wanting to use something other than email field for the login?

and this is User Model

<?php namespace App; use Illuminate\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; class User extends Model implements AuthenticatableContract, CanResetPasswordContract { use Authenticatable, CanResetPassword; public $timestamps =true; /** * The database table used by the model. * * @var string */ protected $table = 'users'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = ['email','password','statustype']; /** * The attributes excluded from the model's JSON form. * * @var array */ protected $hidden = ['password', 'remember_token']; /* public function customersignup(){ return $this->hasOne('App\customersignup'); } */ }
0

After these lines try this, first comment out everything after these lines then:

  $tvar = $request->input('email');
 $echo tvar;
  $pw = $request->input('password');
$echo $pw;

Does that part work? Also are you getting any kind of an error if so what?

0

jimgwhit said:

After these lines try this, first comment out everything after these lines then:

 $tvar = $request->input('email');
$echo tvar;
 $pw = $request->input('password');
$echo $pw;

Does that part work? Also are you getting any kind of an error if so what?

yes that part works,

0

musamagoher said:

jimgwhit said:

After these lines try this, first comment out everything after these lines then:

 $tvar = $request->input('email');
$echo tvar;
 $pw = $request->input('password');
$echo $pw;

Does that part work? Also are you getting any kind of an error if so what?

yes that part works, >jimgwhit said:

After these lines try this, first comment out everything after these lines then:

 $tvar = $request->input('email');
$echo tvar;
 $pw = $request->input('password');
$echo $pw;

Does that part work? Also are you getting any kind of an error if so what?

actually i'm not using default registration page to register user, isn't it causing a problem??

0

Are you trying to register a new user or login an existing user? And if not default, what package are you using?
Make sure your database has the fields you are using. Give me a couple of minutes I am trying something.

Last updated 9 years ago.
0

jimgwhit said:

Are you trying to register a new user or login an existing user? And if not default, what package are you using?
Make sure your database has the fields you are using. Give me a couple of minutes I am trying something.

i'm doing login, with the data which i entered through registration form (not the default ),

0

here is my register page:

{!! Form::open(array('url' => 'doregister')) !!}

    <!--Email Form Input-->
    
    
    
    <div class="form-group">
        {!! Form::label('userid', 'userid:') !!}
        {!! Form::text('userid', null, ['class' => 'form-control']) !!}
    </div>

    <!--Password Form Input-->
    <div class="form-group">
        {!! Form::label('password', 'Password:') !!}
        {!! Form::password('password', ['class' => 'form-control']) !!}
    </div>

    <!--Password Confirmation Form Input-->
     <div class="form-group">
        {!! Form::label('password_confirmation', 'Confirm Password:') !!}
        {!! Form::password('password_confirmation', ['class' => 'form-control']) !!}
    </div>
   {!! Form::submit('Register', ['class' => 'btn btn-primary']) !!}
    <!--Register Form Input-->
    <div class="form-group">
       
    </div>
{!! Form::close() !!}

Route

Route::get('login', 'Auth\AuthController@getLogin');
Route::post('loggin', 'Auth\AuthController@postLogin');
Route::get('logout', 'Auth\AuthController@getLogout');
Route::get('register', array('uses' => 'Auth\AuthController@getRegister'));
Route::post('doregister', array('uses' => 'Auth\AuthController@postRegister'));

controller

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests\RegisterRequest;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
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;

	/**
	 * Create a new authentication controller instance.
	 *
	 * @param  \Illuminate\Contracts\Auth\Guard  $auth
	 * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
	 * @return void
	 */
	public function __construct(Guard $auth, Registrar $registrar)
	{
		$this->auth = $auth;
		$this->registrar = $registrar;

		$this->middleware('guest', ['except' => 'getLogout']);
	}
        
        
        public function getRegister()
	{
		//return view('auth.register');
                return \View::make('auth.register');
	}
        
        
        
        public function postRegister(RegisterRequest $request)
       	{
		// Registration form is valid, create user...
                
             //$user = \App\User::create($request->all());
            
            //$this->validate($request, [
			//'userid' => 'required', 'password' => 'required',
		//]);
                $user = new \App\User(); 
                $user->userid = $request->input('userid');
                $user->password = \Illuminate\Support\Facades\Hash::make($request->input('password'));
                $user->save();

                $this->auth->login($user);

		return redirect('pets');
	}


        
        
        
        
        
        
        
        
        public function getLogin()
	{
		//return view('auth.login');
                return view('auth.testview');
	}
        
        public function postLogin(Request $request)
	{
		$this->validate($request, [
			'userid' => 'required', 'password' => 'required',
		]);
                
                //added
                
                echo 'made it here====';
            $tvar = $request->input('userid');
            //echo $tvar;
            $pw = $request->input('password');
            if ($this->auth->attempt(['userid' => $tvar, 'password' => $pw]))
		{
                    //echo 'logged in========'.$request->user->userid;
                    //echo 'logged in========'.$request->user()->userid;
                    $yourvar = $request->user()->userid;
                    echo $yourvar;
                    echo "====loggin in now";
                    return redirect('pets');
		}
            else
                {
                    echo ' not logged in';
                }

                //added

		/*$credentials = $request->only('email', 'password');

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

		return redirect('/auth/login')
					->withInput($request->only('email'))
					->withErrors([
						'email' => 'These credentials do not match our records.',
					]);*/
	}
        
        public function getLogout()
	{
		$this->auth->logout();

		return redirect('/');
	}



}//end class


A file under \app\Http\Requests named RegisterRequest.php

<?php namespace App\Http\Requests;

class RegisterRequest extends Request {

	/**
	 * Get the validation rules that apply to the request.
	 *
	 * @return array
	 */
	public function rules()
	{
		
            
            /*return [
			'email' => 'required|email|unique:users',
			'password' => 'required|confirmed|min:8',
		];*/
            
            
            return [
			'userid' => 'required',
			'password' => 'required',
		];
	/*$user =  [
			'email' => 'required|email|unique:users',
			'password' => 'required|confirmed|min:8',
		];
            
         return $user; */  
        }

	/**
	 * Determine if the user is authorized to make this request.
	 *
	 * @return bool
	 */
	public function authorize()
	{
		return true;
	}

}

login view not blade:

<html><body>
    

        <form method="post" action="loggin">
        <label>userid</label><input type="text" name="userid"><br>
        <label>password</label><input type="password" name="password"><br>
        <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
        <input type="submit">
    </form>
</body></html>

model

<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

	use Authenticatable, CanResetPassword;

	/**
	 * The database table used by the model.
	 *
	 * @var string
	 */
	protected $table = 'users';
        protected $primaryKey = 'pwid';


	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	//protected $fillable = ['name', 'email', 'password'];
        protected $fillable = [
        'pwid',
        'userid',
        'password'
        ];
        
        public $timestamps = [];

	/**
	 * The attributes excluded from the model's JSON form.
	 *
	 * @var array
	 */
	protected $hidden = ['password', 'remember_token'];

}

I hope I didn't leave anything out. The above works 100% I am able to register users and login. I plan on converting the one file to blade later. Make sure you use your field names, and they are in your database.
Remember to hash the password:

$user->password = \Illuminate\Support\Facades\Hash::make($request->input('password'));

Now if this doesn't work, I just don't know.

Last updated 9 years ago.
0

jimgwhit said:

here is my register page:

{!! Form::open(array('url' => 'doregister')) !!}

   <!--Email Form Input-->
   
   
   
   <div class="form-group">
       {!! Form::label('userid', 'userid:') !!}
       {!! Form::text('userid', null, ['class' => 'form-control']) !!}
   </div>

   <!--Password Form Input-->
   <div class="form-group">
       {!! Form::label('password', 'Password:') !!}
       {!! Form::password('password', ['class' => 'form-control']) !!}
   </div>

   <!--Password Confirmation Form Input-->
    <div class="form-group">
       {!! Form::label('password_confirmation', 'Confirm Password:') !!}
       {!! Form::password('password_confirmation', ['class' => 'form-control']) !!}
   </div>
  {!! Form::submit('Register', ['class' => 'btn btn-primary']) !!}
   <!--Register Form Input-->
   <div class="form-group">
      
   </div>
{!! Form::close() !!}

Route

Route::get('login', 'Auth\AuthController@getLogin');
Route::post('loggin', 'Auth\AuthController@postLogin');
Route::get('logout', 'Auth\AuthController@getLogout');
Route::get('register', array('uses' => 'Auth\AuthController@getRegister'));
Route::post('doregister', array('uses' => 'Auth\AuthController@postRegister'));

controller

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests\RegisterRequest;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
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;

  /**
   * Create a new authentication controller instance.
   *
   * @param  \Illuminate\Contracts\Auth\Guard  $auth
   * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
   * @return void
   */
  public function __construct(Guard $auth, Registrar $registrar)
  {
  	$this->auth = $auth;
  	$this->registrar = $registrar;

  	$this->middleware('guest', ['except' => 'getLogout']);
  }
       
       
       public function getRegister()
  {
  	//return view('auth.register');
               return \View::make('auth.register');
  }
       
       
       
       public function postRegister(RegisterRequest $request)
      	{
  	// Registration form is valid, create user...
               
            //$user = \App\User::create($request->all());
           
           //$this->validate($request, [
  		//'userid' => 'required', 'password' => 'required',
  	//]);
               $user = new \App\User(); 
               $user->userid = $request->input('userid');
               $user->password = \Illuminate\Support\Facades\Hash::make($request->input('password'));
               $user->save();

               $this->auth->login($user);

  	return redirect('pets');
  }


       
       
       
       
       
       
       
       
       public function getLogin()
  {
  	//return view('auth.login');
               return view('auth.testview');
  }
       
       public function postLogin(Request $request)
  {
  	$this->validate($request, [
  		'userid' => 'required', 'password' => 'required',
  	]);
               
               //added
               
               echo 'made it here====';
           $tvar = $request->input('userid');
           //echo $tvar;
           $pw = $request->input('password');
           if ($this->auth->attempt(['userid' => $tvar, 'password' => $pw]))
  	{
                   //echo 'logged in========'.$request->user->userid;
                   //echo 'logged in========'.$request->user()->userid;
                   $yourvar = $request->user()->userid;
                   echo $yourvar;
                   echo "====loggin in now";
                   return redirect('pets');
  	}
           else
               {
                   echo ' not logged in';
               }

               //added

  	/*$credentials = $request->only('email', 'password');

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

  	return redirect('/auth/login')
  				->withInput($request->only('email'))
  				->withErrors([
  					'email' => 'These credentials do not match our records.',
  				]);*/
  }
       
       public function getLogout()
  {
  	$this->auth->logout();

  	return redirect('/');
  }



}//end class


A file under \app\Http\Requests named RegisterRequest.php

<?php namespace App\Http\Requests;

class RegisterRequest extends Request {

  /**
   * Get the validation rules that apply to the request.
   *
   * @return array
   */
  public function rules()
  {
  	
           
           /*return [
  		'email' => 'required|email|unique:users',
  		'password' => 'required|confirmed|min:8',
  	];*/
           
           
           return [
  		'userid' => 'required',
  		'password' => 'required',
  	];
  /*$user =  [
  		'email' => 'required|email|unique:users',
  		'password' => 'required|confirmed|min:8',
  	];
           
        return $user; */  
       }

  /**
   * Determine if the user is authorized to make this request.
   *
   * @return bool
   */
  public function authorize()
  {
  	return true;
  }

}

login view not blade:

<html><body>
   

       <form method="post" action="loggin">
       <label>userid</label><input type="text" name="userid"><br>
       <label>password</label><input type="password" name="password"><br>
       <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
       <input type="submit">
   </form>
</body></html>

model

<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

  use Authenticatable, CanResetPassword;

  /**
   * The database table used by the model.
   *
   * @var string
   */
  protected $table = 'users';
       protected $primaryKey = 'pwid';


  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  //protected $fillable = ['name', 'email', 'password'];
       protected $fillable = [
       'pwid',
       'userid',
       'password'
       ];
       
       public $timestamps = [];

  /**
   * The attributes excluded from the model's JSON form.
   *
   * @var array
   */
  protected $hidden = ['password', 'remember_token'];

}

I hope I didn't leave anything out. The above works 100% I am able to register users and login. I plan on converting the one file to blade later. Make sure you use your field names, and they are in your database.
Remember to hash the password:

$user->password = \Illuminate\Support\Facades\Hash::make($request->input('password'));

Now if this doesn't work, I just don't know.

Thanks A lot....i really appreciates your co-operation

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.