Custom registration with Laravel 5.1 - laravel

I am new to Laravel. I have two different user types: teachers and students. Teachers register accounts in registration form in website but student registration is provided by a windows application. So I must provide an API to this application. Default Laravel auth is enough for teacher registration but can I use same AuthController for API registration? I don't need a view or redirect to website.

You have two options actually
create a method on your auth controller and apply a middleware to the controller method which would only be available for api calls so a student doesnt create himself/herself as a teacher, you can read more about same here http://laravel.com/docs/5.0/middleware
which I would suggest is to create another auth controller for your api calls that only serves for creating student accounts that way its clean, easier to manage and concept of separation of concerns is put into practice.

Related

Integrate custom API authentication in Laravel

I want to create a webapp using Laravel framework with a sort of custom authentication system.
I 've an external API like this
https://xxx.xxx.xxx.xx/subscribers/v1/?source=XXX&licenseplate=AB123AS
and to use this api i need to generate a token that after some period expires.
To generate this token i need to consume this service
https://xxx.xxx.xxx.xx/oauth/v2/accesstoken?grant_type=client_credentials
This Api tells me if the customer is covered or not and has as input parameters: source and license plate.
So my goal is to create a login form with these 2 parameters (source and license plate) input by customer that consume that API and only if it returns covered, customer can access a reserved area and do some stuff.
How can i do this in Laravel?
I have to create a new service provider, new user model and guard? How? :S or use in some way auth2.0 integration?
Thanks

Custom Registration process to onboard other users in Laravel

I am building a Laravel webapp, where I need to implement a custom registration process. Now I am not sure, whether I can/should use the built-in Authentication features from Laravel or not.
I have three types of users:
Admin users: My colleagues in my company who talk to clients, onboard them, etc.
Clients: Users who create certain tasks, that need to be done. They could more or less use a "standard registration" process
Service Providers: Users who fulfill tasks for clients. They need to be onboarded by our company. So our admin users would create their user profile and send them an invitation link.
Especially the Service Providers are giving me a headache. Is this kind of custom registration flow possible in Laravel or do I have to build my own custom athentication to accomplish this?
Thank you for posting your question. I have implemented Laravel Authentication with custom features before, I would recommend you to take the following steps:
Install Laravel Authentication.
Update users table with a column name type that will distinguish between users.
Create middleware for each user. Middleware helps you which user can access or perform which tasks.
If you have different elements for each user then you can also implement policies or gates to show specific elements on your blade template according to user type.
I would not recommend creating custom Authentication for this scenario, as you have to implement proper session handling throttling, forgot password, verify the process along with emails and notifications. which is built-in by default in Laravel.
If you want to edit the register and login function you can do that. ;)

Register using Facebook and create user profile in Django-Rest

I am using django-allauth and dj-rest-auth in my django-rest project to register users and allow them to sign in to my react-native app. The problem I am having is that when the user is registered, it creates the particular user in a social accounts table. However, I want to also create a user profile for each member who registers via Facebook and store additional data (name, email, picture). I have had a look at docs, blogs, stack-overflow but just can't seem to figure out how I can do this.
So far, I have a social_login app which manages the login and has a view which has the following:
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from dj_rest_auth.registration.views import SocialLoginView
class FacebookLogin(SocialLoginView):
adapter_class = FacebookOAuth2Adapter
How can I edit the social accounts model? and how can I create a user profile in my users app once a user has registered using Facebook?
Update:
I have realised that I can only have one user auth table in Django which manages user, regardless of whether they are customers or staff. I have now migrated to using a custom user model using the AbstractUser from Django. I could potentially create another table for user profiles which could then hold additional details or extend the model I have now. I will extend the User model I have created as I think created an extra model would be overkill for my current needs.
This blog post helped me migrate to using a custom user model mid-project.
I also realised that I am able to make use of allauth signals (user_signed_up in particular for my case) in order to trigger a function. I'm fairly new to Python/Django so didn't even know what a signal was till about 30 mins ago. It's fair to say you learn something new everyday :)

Access to Auth or Request in Laravel Model

I have a shop-store project. This project starts with basic functionality and grow up on each software life-cycle. Recently tendency to deploy some customization for user and analytics grow. I wanted to add favorite capability to project. The project has guest mode which unauthenticated user can see products.
Each user may choose to add a product to his/her favorites(after Auth). so far so good. I decide to append favorite attribute to products.
Trouble comes when i try to return products from controller as response. If i use Auth middleware unauthenticated users redirected to login. If i use custom code, every API with product should be changed accordingly. If i try to append filed in product model, i don't have access to Auth class nor requestin product model.
What's the way to handle such a situation? I appreciate your help.
UPDATE:
There are many models in my project. Order, OrderProduct, Product, User, Payment, Category, Delivery, ....
I want to have a new table named Bookmark which has two column: user_id and product_id.
Product == One Many == Bookmark
User == One Many == Bookmark
You can use the blade #auth directive to check for user authentication.
Then for templating
{{auth()-> user -> bookmark -> all()}}
This should work if you have established a one to may relationship between user and bookmark in your model.

Add invitation functionality to Laravels authentication controller

I am using Laravels normal authentication functionality with RegisterController and the default views that are included. I have modified the RegisterController#create method to create a related model called Home to the User. Although a Home can have several User relations.
After signup, the User automatically have a Home related to them. The user should now be able to invite new users to join their Home. All the logic around the invites are solved, but I was wondering what the best solution for registering the invited user is.
Currently I have created a InviteController with a acceptInvite method that registers the new User related to the existing Home. But I really want to reuse the RegisterController#create method instead of having to maintain two registration processes.
Any ideas?
Your question is not clear... The user you want to invite to HOME are they registered users? if yes
All you need is a many to many relationship using a pivot table.
If the user you want to add to HOME is a new user and not already register on your app, just send them a mail with link to your register page, and let then use the RegisterController#create
Hope this help:)

Resources