Django social app integration, auth namespace is not recognised? - django

I am having problem with facebook login app integration the problem is
'auth' is not a registered namespace
the problematic part is the:
<p>
{% if user and not user.is_anonymous %}
Hello {{ user.get_full_name|default:user.username }}!
{% else %}
I don't think we've met before
{% endif %}
</p>
Login
Logout
I got that auth is not recognized but in the tutorial there were no problem with that. I am using django versio 1.9.5.

Related

Django request.user.first_name not working in Safari

the code {{ request.user.first_name }} used on a HTML page with Django works perfectly in Chrome. However, it is not working in Safari and just displays nothing.
Is there any alternative way of getting this or how can I fix this?
Not using Safari is not an option as people with Safari will use this web-app.
EDIT:
Minimum reusable example:
base.html
<span class="user">
{% if request.user.is_authenticated %}
Hello {{ request.user.first_name }},
Logout
{% else %}
Log-in
{% endif %}
</span>
How it looks on Chrome:
Safari:
I assume that you are logged in with a different user in Safari, which this user doesn't have a value in first_name.
Please double check that your are logged in with a user have a valid first_name.

check if the user has logged in with social account - Django

in the web site that i'm working on , I have an authetication system and I'm using django allauth at the same time so the user can login with his gmail or facebook account if he wants . how can I check in the template if the user has logged in with his facebook/gmail account ?
i want somthing like this
{% if user not 'use his facebook or gmail' %}
<a href="{% some url %}">
<button type="button" class="btn btn-primary" data-dismiss="modal">somthing </button>
</a>
{% endif %}
i've found this and it has done what I needed
{% load socialaccount %}
{% get_social_accounts user as accounts %}
{% if accounts %} "if the user has logged in using his facebook account or his google account"
"do somthing here"
{% endif %}
for more details check the documentation of django-allauth
for future readers, in view.py you do can something like this to detect if user is a social user or not
is_social = user.socialaccount_set.exists()
it returns True if your logged in with facebook/google/...
else it return False

How to create a User via django-allauth social login

I have problems making actual User instance when using django-allauth.
I let users to login with other SNS account, and then It creates sociall accounts, not User instance on server.
And this 'all-auth' is also a problem. I read many lines of official docs and code but I can't even guess how it works.
{% load socialaccount %}
<ul>
{% for provider in providers %}
<li>
{% if provider.social_app %}
{{provider.name}}
{% else %}
<a>Provider {{ provider.name }} is not ready yet</a>
{% endif %}
</li>
{% endfor %}
</ul>
It's all I typed. (beside starting setups).
I click that provider_login_url, it goes to social login, my social account is authorized and I get logged in to may service.
I want to know how it works internally.
And how to make User instance that I can see and manage on my admin page.

django-allauth socialaccount "full" logout?

I am working on what might become a sort-of kiosk app. I am new to python and django but it is rolling along. My allauth flow for signup uses either a social login (Google for the moment) or a "local" email address & password.
If I login with a Google account then logout I am redirected to the sign-in page, cool. The thing is I have not really been logged out of the Google account. If I click the social login link then I am back in the user area with no password challenge.
Does allauth have a way to logout and have the social auth token removed? Do I need to catch the logout signal and find/delete the token myself?
Looks like there is a built-in solution. There is an action parameter that can be given the value "reauthenticate". Being new to this stuff I am not positive that I have added it in the python/django way but I have edited the template:
myProject/templates/allauth/socialaccount/snippets/provider_list.html
and added action=reauthenticate" to the social auth href line a la:
{% load socialaccount %}
{% get_providers as socialaccount_providers %}
{% for provider in socialaccount_providers %}
{% if provider.id == "openid" %}
{% for brand in provider.get_brands %}
<li>
<a title="{{brand.name}}"
class="socialaccount_provider {{provider.id}} {{brand.id}}"
href="{% provider_login_url provider.id openid=brand.openid_url process=process action='reauthenticate' %}"
>{{brand.name}}</a>
</li>
{% endfor %}
{% endif %}
<li>
<a title="{{provider.name}}" class="socialaccount_provider {{provider.id}}"
href="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}">{{provider.name}}</a>
</li>
{% endfor %}
That seems to do the trick.

Django user.is_authenticated reversed

In my template if user is anonymous,it would show Register button. So I use
{% if user.is_authenticated %}
Log out
{% else %}
Log in
But when I test it. It reversed.
I am sorry I login into admin site and I forgot to logout.