Register using Facebook and create user profile in Django-Rest - django-rest-framework

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 :)

Related

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. ;)

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:)

Where to put logic for auto-login and creating members

Im new to Umbraco development, but im plenty familiar with ASP.Net & MVC etc. So Im getting to grips with the object model and terminology used, but Im not sure where to start. I need to use windows authentication on my Umbraco site, which will be for internal use only.
What I envision:
- When a domain user hits any area of the website, grab the user identity
- Lookup to see if matching user(or member) exists and if not create it
- Login this user to Umbraco
- By default all new visitors, if their user identity doesnt match a current member, then create that member and log them in.
Sounds like I need to create my own controller that overrides the base controller (RenderMvcController ?) and check the user identity on each and every request? Maybe do this by overriding the Index action method? Or could I do this with a macro - or as ive seen mentioned, are macros loosing favor with the new version of Umbraco?
Also, Im not sure how to deal with members vs users? As I understand it, members are who have access to the front part of the website, whereas users are those that have access to the back office area and can create/manage content.
Are all users also members?
There will be some that I want to give access to create/manage content, so when Im auto-creating users, its actually members that I need to create, not users?
[ update ]
Actually, I think I will need to create my own membership provider if I want every request routed through the check for a valid domain user? In my research, I keep coming across this example http://thegrayzone.co.uk/blog/2012/07/combined-authentication-with-umbraco/
I have overridden the default RenderMvcController in numerous projects with success, you could of course use the built in Umbraco auth to redirect to an authentication page for users that do not have a valid Umbraco Auth token and set it only only on that page based on their windows identity.
RE: Are users also members?
No. Users & Members are entirely independent of one another; users being back office users & members being front end users. You will need to create 2 accounts.

Headstart needed for re-using the register functionality in Laravel 5.0

I am building a Laravel 5.0 project. With this the admin section is only accessible for registered users. I have added for example a user type to the User model and want to create and edit users using an admin module instead of the standard registration form in /auth/register.
But I cannot seem to find how to disable /auth/register for the outside world, but also cannot create my own CRUD for managing users.
So my main two questions are:
How can I reuse the password encryption in my own create and update functionality
How can I disable /auth/register for the not logged in users?
Thanx in advance

Integrate a facebook c# sdk login system into an existing login system based on Microsoft Membership Api

I'm trying to figure out how should I integrate facebook login system in my existing application through facebook c# sdk.
I have a web forms application and I'm authenticating users by standard Login control.
I'm using MembershipProvider, RoleProvider and ProfileProvider.
I'm thinking I should persist FacebookUniqueID and put it into relation with existing informations on my Membership Users table.
I'm wondering wich is a correct approach to this.
Considering I have a custom Profile Provider that uses a custom sql table, it would be fast to add a FacebookUniqueID property to my user profiles and use it in my login workflow:
Login through facebook;
retrieve facebookUniqueID;
retrieve userName for the user that
have this specific facebookUniqueID,
then
FormsAuthentication.SetAuthCookie(userName, bool);
What about providing an overload for the previous method taking facebookUniqueID as parameter?
Please let me know what do you think about this from any perspective and if anyone knows a simple working example
I think you are on the right track. We implement a similar solution (though we have rolled our own custom membership/role/profile etc and don't use the built in approach.)
You also will have to handle the situations that occur when a new user (without an existing account) logs into your site via Facebook.

Resources