Wow. This is crazy. I cleared my browser cache, still able to log in. I changed the route to your suggestion and it still logs in. doesn't even echo the message out.
- Then there must be something wrong in the way you handle the check to see if they are verified.
- Or, they are actually verified.
What is currently in your database? Post a screen grab.
ok
took a screen of all 3 of my monitors, so I had to edit it and make sure it was viewable, now I can't figure out where to upload it.
Use imgur and then grab the normal link and place within standard HTML img tags.
Once we've got this sorted, take a look at some Guidelines for posting on Laracasts.com I put together. It will help you with those sorts of things, and for posting on here in general.
Hope this is viewable
There is your problem. You need to add the $casts property to your User model.
protected $casts = [
'is_admin' => 'boolean',
'is_employee' => 'boolean',
];
Where's there? LOL
What does that do?
@dmcglone what is your email address, I'll add you to Slack and we can chat on there.
david.mcglone1972@gmail.com
I tried your suggestion, but it's still logging in. LOL
Ah hah. I logs me out if I try to go to the employee page, but it does let me log in. but logs me out when I hit the employee route
Were you not testing that?!
I forgot a couple times, because it was logging me out right after logging in and wouldn't even let me log in at all.
So it is or isn't working?
but after I experimented with the other suggestion, somehow it either changed or fixed itself.
I think you were checking properly ;)
But happy it is sorted.
Yeah, hitting the employee route does automatically log me out. I was hoping for it to not let a login at all, but what I could do is adjust the login to hit the employee route instead of the home route and it should automatically log the user out..
I can't thank you enough. I have learned something good today. :-)
@mstnorris check out this lil hack I did. Now when logging in, if your admin bit is true, it redirects to /admin, and if your employee bit is true it redirects to /employee, otherwise it redirects back to auth/login. I know it's not as practical as using a role based system, but if one only needs a couple roles, why not. :-)
AuthenticatesAndRegistersUsers
public function getLogout()
{
$this->auth->logout();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/auth/login');
}
public function redirectPath()
{
if (property_exists($this, 'redirectPath'))
{
$this->redirectPath;
}
if ($this->auth->user()->is_admin == true)
{
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/admin';
} else {
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/employee';
}
}
@dmcglone don't edit the AuthenticatesAndRegistersUsers.php file directly as it is part of the Laravel core framework and it's under the _Illuminate\Foundation\Auth_ namespace.
Instead, just put that same method inside AuthController.php which is in your app/Http/Controllers/Auth directory and it will work the same, but it won't be overridden when you update Laravel in the future. The reason why this works is because AuthController uses the AuthenticatesAndRegistersUsers Trait.
<?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;
class AuthController extends Controller {
use AuthenticatesAndRegistersUsers;
public function getLogout() {
$this->auth->logout();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/auth/login');
}
public function redirectPath() {
if ( property_exists($this, 'redirectPath') )
{
$this->redirectPath;
}
if ( $this->auth->user()->is_admin == true ) {
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/admin';
} else {
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/employee';
}
}
Ah Ok. I just skimmed back through my posts because this had come up a while back and others had told me to do it this way also, but I never did figure out why, so this clears it up.
@mstnorris I was playing around more with this code and thought I'd post this in case others come along and have the same problem. Remember in our discussion this worked for me:
public function handle($request, Closure $next)
{
if ($this->auth->check() && $this->auth->user()->is_employee == true)
{
return $next($request);
}
return new RedirectResponse(url('auth/logout'));
}
But this didn't:
public function handle($request, Closure $next)
{
if (Auth::check() && Auth::user()->isEmployee())
{
return $next($request);
}
return new RedirectResponse(url('auth/logout'));
}
Turns out I forgot to include the Auth namespace:
use Illuminate\Support\Facades\Auth;
@dmcglone you can put use Auth; instead. You don't need to include the whole namespace.
Also on that note:
- (a) I'm sure I mentioned that, and if I didn't, I'm sure others would have.
- (b) You should be using an IDE like PhpStorm that will give you a warning when you don't import classes.
Check out Jeffrey's series Be Awesome in PHPStorm.
I'm using PhpStorm, but didn't get a warning or squiggly lines or greyed out lines, so that's weird.
And yeah just using Auth works. :-)
Restricting admin not to access user dashboard .
Please or to participate in this conversation.