Written with StackEdit.
So i am struggling with understanding this laravel multi-auth concept in laravel 5.2, so i did my research and found this help, it was confusing but appliying gave me more issues, then i had to reaserch agin, to find your package. So now i have installed your package and still more problems so i say to you gues i need help to move on from this stage of my app.
FIRST OF ALL
In the installation of the package these step borders me,
And open config/auth.php file and remove:
'driver' => 'eloquent'
'model' => App\User::class,
'table' => 'users'
and replace it with this array:
'multi-auth' => [
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class
],
'user' => [
'driver' => 'eloquent',
'model' => App\User::class
]
]
My question is will these multi-auth stay inside the array of providers, LIKE THIS
'providers' => [
// using the MultiAuth package by Kbwebs
'multi-auth' => [
'admin' => [
'driver' => 'eloquent',
'model' => App\Wasamar\Admin::class
],
'user' => [
'driver' => 'eloquent',
'model' => App\User::class
]
]
],
Or on its on own in the config/auth.php file
'multi-auth' => [
'admin' => [
'driver' => 'eloquent',
'model' =>App\Wasamar\Admin::class
],
'user' => [
'driver' => 'eloquent',
'model' => App\User::class
]
]
Using the Illuminate\Auth\AuthServiceProvider::class things was fine with my user login until i updated it to this Kbwebs\MultiAuth\AuthServiceProvider::class, So this is my user login controller.
class WsLoginController extends Controller
{
public function login(Request $request){
// return dd(Input::get('_token'));exit;
$wsUserEmail = Input::get('email');
$wsUserPassword = Input::get('password');
$wsRememberMeSwitch = Input::get('remember-me');
$remember = Input::get('_token');
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required'
]);
if ($validator->fails()) {
return redirect('/login')
->withErrors($validator)
->withInput();
}
$credentials = [
'email' => Input::get('email'),
'password' => Input::get('password')
];
if ( isset($wsRememberMeSwitch) ) {
if (Auth::user()->attempt(['email' => $wsUserEmail, 'password' => $wsUserPassword], $remember)) {
// The user is being remembered...
$user = User::where('email', '=', Input::get('email'))->first();
Auth::user()->login($user,$remember);
}
}else{
// check if user is authentic
$valid = Auth::user()->validate($credentials);
if ( ! $valid)
{
return Redirect::back()
->withInput()
->with([
'error_msg' => 'We were unable to sign you in. Incorrect email/password combination!'
]);
}
$user = User::where('email', '=', Input::get('email'))->first();
Auth::user()->login($user);
}
// user is valid, lets check a few things
$user = User::where('email', '=', Input::get('email'))->first();
$user_id = $user->id;
$get_user_id = Userconfirmation::where('user_id', '=', $user_id)->first();
$user_confirm = $get_user_id->confirmed;
// check if user has confirmed their account
if ( $user_confirm != 1 )
{
return Redirect::back()
->withInput()
->with([
'error_msg' => 'You must confirm your account before you can access your box (dashboard).'
]);
}
// Store your session variables
Session::put('ws_user_name',$user->name);
Session::put('ws_user_email',Input::get('email'));
// redirect to the page they were trying to view, or redirect to index
return Redirect::intended('dashboard');
}
}
So i also updated Auth::function() to Auth::user()->function() like you specified in the usage section of the package, but this is the error it gave me.
FatalErrorException in WsLoginController.php line 59:
Call to a member function validate() on null
Then when i tried to logout i get this
FatalErrorException in Authenticate.php line 20:
Call to a member function guest() on null
I have not applied it yet to the admin section of the app, in summary i need to validate two users the
User and the Admin
Please help me God.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire