I'm using Django with django-allauth for social authentication.
I have authentication up and running, but can anyone give simple examples of how to:
For example, on the home page, I've got
{% if user.is_authenticated %}
<li><a href="{% url account_logout %}?next=/">Logout</a></li>
{% endif %}
That's showing the Logout link correctly, but how would I add the user's name and avatar?
Something like (pseudocode):
<p>You're logged in with {{ user.account_provider? }} as {{ user }}.</p>
<img src="{{ user.avatar_url }}" />
Then, if I want to add extra properties to the user's profile, what do I do? Should I be using some other Django user-related app?
Thanks for your help.
A SocialAccount
model instance is available for users who signed up using their social account.
In your template, you can simply write:
Avatar URL: {{ user.socialaccount_set.all.0.get_avatar_url }}
UID: {{ user.socialaccount_set.all.0.uid }}
Date Joined: {{ user.socialaccount_set.all.0.date_joined}}
Last Login: {{ user.socialaccount_set.all.0.last_login}}
And for Full Name: {{ user.socialaccount_set.all.0.extra_data.name }}
For more information: Django allauth source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With