I would like to check if a user is logged in via social authentication or using the django default authentication.
something like
if user.social_auth = true?
Ok after doing some research i came up with this solution to make sure if a user is authenticated using any social provider or just the default django auth. Check here for moreinfo..
{% if user.is_authenticated and not backends.associated %}
#Do or show something if user is not authenticated with social provider but default auth
{% elif user.is_authenticated and backends.associated %}
#Do or show something if user is authenticated with social provider
{% else %}
#Do or show something if none of both
{% endif %}
from social_auth.models import UserSocialAuth
try:
UserSocialAuth.objects.get(user_id=user.id)
except UserSocialAuth.DoesNotExist:
print "user is logged in using the django default authentication"
else:
print "user is logged in via social authentication"
You may to add a method to User model.
i was searching on that and the solution is user.social_auth.exists() it will return True if the user exists in the database else it will return false.
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