I want to display a picture of the current_user in my template. How can I access the user's facebook id when I'm using django-allauth?
For each user that is signed up via a social account a SocialAccount instance is available. This model has a foreign key to User. Note that a user can connect multiple social networking accounts to his local account, so in practice there may be more than one SocialAccount instances available.
How you want to deal with this is project dependent. I can imagine one would want to copy the profile image locally, or perhaps you would want to give preference to the Google+ profile picture above the Facebook one, and so on.
The SocialAccount model has some helper methods that give you access to account basics such as the profile picture. All in all, this is a quick & dirty way to access first available profile picture:
{{user.socialaccount_set.all.0.get_avatar_url}}
The ID is also available:
{{user.socialaccount_set.all.0.uid}}
See also: https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py#L72
Related
I added authorization through social networks to my site. How can I find out that the user used exactly this authorization?
In the process of authorizing a user through a social network, I need to change the verified value in the database table, as well as add his photo to this table.
Note: I didn't rewrite the default user model, but extended it by creating a ForeignKey in the Profile table. This table stores information about the user (phone number, gender, etc.)
Note2: I'm using social-auth-app-django
It seems to me that I should implement a separate View for authorization on social networks in order to catch all the data I need. But what should it look like? I am new to this matter.
I am building a django application in which user will be able to sign up or sign in only via their EBay account, no email/username or password required. I couldn't find any authentication library for EBay though there are many for google, facebook, twitter etc.
So I got the EBay part working. EBay basically returns (on consent of user) Email and a IEFS token which is unique to that user and wont change. I want to use those two fields only to create a authenticate user across whole application. I don't want username, emails, firstname, lastname or password that ships with django User model. The documentation is quite big and I am confused where to start, any proper suggestion will be big help. Thank you.
Here is a bit of insight, the code is yours to make :
You can extend the user model from Django and decide which field to use, you could for example create a Ebay ID field Abstract User
Once this is done you want to add the ebay ID to an user, just create an account with email and ID, the user won't need any more info
Finally allow user to connect only by email, either by overriding custom login from Django or using a package like Django Allauth
Please note that unless your site is accessible only by Ebay users, allowing user to connect with email/password is recommended.
It is perfectly doable, just make good use of the documentation
I know that in the API users must allow the app permissions to use their specific user data.
But as a user, I have friends which have their own likes. Is there a possible way to query another user or my friend's profile (using their user id) to get a list of their likes via the Graph API.
Ie. because they've decided to friend me, they've given me their permission on a user basis to access their data in Facebook, so can I query this via the graph api as myself instead of an external app?
No, that is not possible.
What is visible/accessible to you as a user on facebook.com or in their official apps, has litte correlation to what you can see via API.
If you want to access anyone’s likes via API – then they have to login to your app first, and grant it appropriate permission.
I am trying to build a django app with two types of users, public users that log in with facebook and enterprise users who log in with email/password. I currently am using allauth with a custom user model that lets public users log in with facebook but I am lost as to what approach I should take with creating this new enterprise user type.
There have been suggestions that I should subtype the custom user model such as in http://michalcodes4life.wordpress.com/2014/02/08/multiple-user-types-in-django-1-6/ however, this example does a poor job of showing how to integrate this with socialauth. How do I tell if the users logged in from the main page, which suggests I should make a public user, versus from the corporate log in, in which case I should make an enterprise user. How do I even specific two different reroutes depending on signup/login from different starting pages?
Other options like creating different UserProfile models seem to defeat the point of me making the custom user model to begin with. Also doesn't having a separate UserProfile model slow down DB searches? Also, I would still have to have two separate UserProfile types for public and enterprise users so I would still run into the same problem as with the first option so I might as well just subtype the custom users instead of adding to the mess with UserProfiles. Again, the problem of how to specify different redirects after signup and specify which type of user to create still exists.
The last option seems to be to use the admin system in Django for enterprise accounts. However, wouldn't this mean I would have to make the admin system UI presentable? Also, these enterprise accounts should not have access to the ability to edit users fields, so their permissions would be restricted to solely viewing public users on the site.
I'm building a web application where I have 2 sets of users (students and teachers). Teachers should be able to create their account, create a page of their content. Students should be able to create an account to sign up for this content. I am currently using django-registration to handle registration but I am wondering what's the best way to handle these 2 sets of users and still be able to use the Django authentication framework? I have heard about having multiple profiles but would like some opinions.
Thanks!
You could use permissions. When they sign up if they're a Teacher give them content creation permissions. If they're a student they don't get the permissions.
In the user profile I would just have a field that says which type they are. Unless a lot of the data is different I wouldn't have two user profiles.