How to create an additional authenticatable model in Laravel - laravel

Okay so I know there are a ton of tutorials out there talking about changing the authentication to your liking, but I couldn't find one for my specific case. So here it goes:
In one of my projects I've been using the standard authentication system that comes with Laravel. I have a user model, and each user has an email and a password. They also have roles and permissions and everything works as expected.
I also have a client model. There are projects and each project belongs to a client. Now there is a new requirement for the app, where clients should be able to login and see all of their projects.
Clients should login with a username (not email) and a password.
My question is: What steps are necessary to completely get this going. All I can find online are some pieces of the puzzle, but unfortunately I'm not able to put this together on my own. I know it involves creating a user provider, but that is only part of it. How do I hook up routes/controllers for this, how do I use the custom user provider, how can I use the Auth facade in addition to the standard "user" authentication (I will need to use both side by side)?
If someone knows of a comprehensive tutorial I will be happy to read that and apologize for this question ;-) Otherwise I will be very thankful for a little checklist of all the things I have to consider.
PS: There a many reasons why I can't just use my user model with a special role or something like that. I need to use the client model for authentication.

I found this tutorial which contains the gist of what you're looking for. The basics come down to something along these lines:
Create a new Authenticatable model
Adjust auth.php with new guards and providers
Adjust routing to take both models in account
I'm not sure how the Auth facades plays its role in this, but it might require some additional configuration.

Related

What is the difference between Authentication and Authorisation in Laravel (7 or above)?

I am trying to make a login and registration page using Laravel, but I came across two concepts in the official Laravel Documentation - Authentication and Authorization. I am unsure as to which one to use to check login details with the ones in the database, since they sound very similar. If I use one of them to login users, then what is the use of the other one. Please explain with some examples and codes.
Authentication is a process of making sure your user is authenticated/logged in to do stuffs in your app.
Authorization is a process of making sure your authenticated user have access to any stuffs in your app.
I will try to explain it as a short story so you can understand better and easier. It going to be a bit longer but you will get the idea.
Imagine those are the guards of a military base, you want to get in to the base. "Mr. Authentication" stops you in front of the gate and said "Hey, who are you? Only registered users are allowed to get in the base. Please fill this form to verify that you have already registered. Otherwise, please register yourself as new user and show me the form you've filled".
You do register yourself and are allowed to get in. Now you are authenticated. Inside the base, you found a room with hazard symbol near the barracks. You are curious and decided to get in but then you met "Mr. Authorization".
He said.. "Good morning sir, I've never seen you yet before. This is our laboratory, only Professor have rights to get in here. Otherwise, I will need to get you out of here. Can I see your authentication pass, please?."
You shows your pass, he looks at it and realize you are a new member of that base and your role were limited to Temporary Member.
He holds your hand and drags you outside the room, and he said "Apologize sir, you have no rights to access this room, please explore the base wherever you like but not this place. If you are keep going back, I might drags you out like this again".
Back to topic
Laravel has built in authentication stuffs you can get by using php artisan:make auth command and you're probably no need to make it your own at some cases. This will do an Authentication stuffs like Logging in the user or Register a new one for you out of the box.
So, if you want to check login details with the ones in the database, this is exactly what you need. After the user can login, you might want to limit their access at some pages. Here is when the Authorization comes for the job.

Single User authentication in Laravel 5

I'm trying to build an internal admin system to get to grips with creating a Laravel app from scratch. Currently everything is public so I'm looking at implementing a very simple login system.
There will be no DB connection needed as we want a single user. We'll store the relevant username and password in the .env file most likely.
I feel like I've looked everywhere and haven't been able to find any tutorials covering this requirement! From everything I've read it seems I have to use a 'custom authentication driver' or possibly build my own user provider class but I have no idea how to go about this task.
The idea is that if the app is expanded in future we'd like to be able to just go back to using Laravel's built in db auth functionality. For this reason it would be nice to retain all the common methods relating to checking the current user, using auth middleware on my routes and managing login tokens etc.
Thanks in advance for any help offered.

Laravel 5.1: Eloquent Authentication Using Two Distinct User Models/Tables

My app needs to support two types of users:
regular users , these are those who are subscribers (restaurants
that use my app for managing their business). For these users, I
have the out of box authentication (Laravel 5.1) set up. email and
password are the fields I authenticate on. I maintain information
about such users in my users table.
guests, these are people who
visit the restaurants above, register to earn loyalty points, check
their score, leave feedback, etc. I maintain information about such
users in my guests table. Authentication, in this case, is simple.
I just use a mobile_number to authenticate them into the app.
I get that I can implement guest's authentication in a subdomain of my app, with different Controllers and Views.
What I don't get is, how can I use the eloquent database driver with the two distinct models? I see that we specify the model eloquent would be using through config.auth.model. So, I'm assuming that we can only have one single model implementing authentication.
Is, what I trying to achieve, possible without implementing a custom driver?
Short answer: No.
You need a custom driver for this. But that shouldn't be too hard to implement, as you can easily get inspiration from/or extend the current EloquentUserProvider. You can also check out the answer to this other question:
Custom user authentication base on the response of an API call
The context is different than yours, but it may help getting a better grasp on the implementation approach (that is if you haven't done this before).

Is there a codeigniter library user manager based on Ion_Auth?

I implemented codeigniter Ion_Auth library for user registration and etc. I noticed it does not have a built-in user manager such as edit user accounts. Does a user manager such as edit user accounts exist? I can always code one, but I rather not reinvent the wheel.
I use Ion Auth too, it is pretty well coded I and I like writing code with it.
I also needed users editing, but I find it quite easy, because I needed only one simple form, because the library has update_user() and you need only to pass an array with your new data.
Download a CMS because it looks to me you have little or no experience with codeigniter or php for that matter. I dont mean that in a rude way by any means but if you cant perform simple CRUD operations, install a pre-built system as it will save you lots of headaches.
I've just started using CI and am also using Ion Auth for authentication. I'm handling user signup/authentication exclusively with ion auth and extending public profiles using Grocery CRUD. All public info can be viewed globally, but only edited by the user that owns it (as defined by linking the ion auth user table to the extended profile table). I don't know if this is the best way to do it, but it is what I'm doing so far.

Padrino basic user authentication

I was wondering if anyone can shed some light on setting up basic user authentication. I've installed the admin app into my project and it works great. But I need a basic user role that can have it's own registration page etc.
I need to see something like
domain.com/users/user.slug
would take them to their profile page
I'm also going to have nested resources, so a user can have a project associated to them.
domain.com/users/user.slug/projects/project.slug
or
domain.com/users/user.slug/project.slug
The admin piece worked great, but I have no idea how to setup registration etc for a user model?
I've used devise in the past with Rails and I'm wondering if anything like it currently exists? I've seen some discussion around warden. Is there a defacto solution that people are using or am I able to implement the admin app to handle this? Right now /accounts is protected and can only be accessed by the admin role.. so I can't have users go to accounts/new
Thanks
For now I basically just copied the admin app.. into my own Users app while using my own User model.
The user model is basically a direct port of the account model.. as is the session controller etc. Just switched the model names around.
I'm still not sure if this is the best approach or if I'm able to leverage the admin app to handle this also?
This solution is working, though again, I'm not sure if it's the optimal approach.

Resources