Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication through Google account #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions cosmos_search/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os

from decouple import config, Csv

#from django.contrib.sites.models import Site
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -53,8 +53,28 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
#'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
#'allauth.socialaccount.providers.twitter',
]

SITE_ID = 2

SOCIALACCOUNT_PROVIDERS = {'facebook': {}, 'google':

{ 'SCOPE': ['email',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/plus.me',],

'AUTH_PARAMS': { 'access_type': 'online' }
}, 'twitter':{}}

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -70,19 +90,32 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, "templates")],
# 'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.i18n',
# Required by allauth template tags
# "django.core.context_processors.request",
# 'allauth.account.context_processors.account',
# 'allauth.socialaccount.context_processors.socialaccount'
],
},
},
]

AUTHENTICATION_BACKENDS = (
# Default backend -- used to login by username in Django admin
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)

WSGI_APPLICATION = 'cosmos_search.wsgi.application'


Expand Down Expand Up @@ -129,6 +162,11 @@

USE_TZ = True

ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = "none"
SOCIALACCOUNT_QUERY_EMAIL = True
LOGIN_REDIRECT_URL = "/"
SOCIALACCOUNT_AUTO_SIGNUP = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
Expand Down
3 changes: 3 additions & 0 deletions cosmos_search/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
url(r'^', include('search.urls')),
url(r'^update/', include('update.urls')),
url(r'^admin/', admin.site.urls),
# url(r'^accounts/', include('django.contrib.auth.urls')),
url(r'^accounts/', include('allauth.urls')),
]

if settings.DEBUG:
Expand All @@ -42,3 +44,4 @@
handler403 = views.error403 # noqa
handler404 = views.error404 # noqa
handler500 = views.error500 # noqa

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ smmap2==2.0.3
urllib3==1.22
pep8==1.7.1
python-decouple==3.1
django-allauth==0.32.0
58 changes: 55 additions & 3 deletions search/templates/cosmos/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css" type="text/css" media="all" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
html {
position: relative;
Expand Down Expand Up @@ -57,6 +58,8 @@
padding-bottom: 0;
}
.bootstrap-iso .form-control{border-width: 2px; border-color: grey;}


</style>
{% block style %}
{% endblock %}
Expand All @@ -71,9 +74,58 @@
<a class="navbar-brand" href="/">cosmos-search</a>
</div>
<div class="col-8">
<a class="btn float-right" href="https://github.com/OpenGenus/cosmos-search">GitHub</a>
<a class="btn float-right" href="https://github.com/OpenGenus/cosmos">cosmos</a>
<a class="btn float-right" href="{% url 'calculator' %}">calculator</a>
{% if user.is_authenticated %}
<div><a id="logout" href="/accounts/logout" class="btn float-right btn-info">Logout</a></div>
<div><a class="btn float-right " href="#"><i class="fa fa-user-circle" style="color:lightblue;font-size:25px" margin-right:"10px;"></i>{{ user.socialaccount_set.all.0.extra_data.name }}</a></div>
{% else %}
<a id="google_login" href="/accounts/google/login" class="btn float-right btn-danger" style="margin-left:10px;">
<i class="fa fa-google-plus"> Sign in</i></a>
<a id="google_login" href="/accounts/google/login" class="btn float-right btn-info" style="margin-left:10px;">
<i class="fa fa-google-plus"> Sign up </i></a>

{% endif %}
<a class="btn float-right" href="https://github.com/OpenGenus/cosmos-search">GitHub</a>
<a class="btn float-right" href="https://github.com/OpenGenus/cosmos">cosmos</a>
<a class="btn float-right" href="{% url 'calculator' %}">calculator</a>

<!--
<div><a id="google_login" href="/accounts/google/login" class="btn btn-success">
Sign in with Google
</a></div>
<div> <a id="logout" href="/accounts/logout" class="btn btn-success">Logout</a>
</div> -->


<!--
<div>
{% if user.is_authenticated %}
<a id="logout" href="/accounts/logout" class="btn btn-success">Logout</a>
<p>as {{ user}} </p>
<p>{{ user.socialaccount_set.all.0.extra_data.name }} </p>

{% else %}
<a id="google_login" href="/accounts/google/login" class="btn btn-success">
Sign in with Google</a>

{% endif %}
</div>

<div class="navbar-collapse collapse">
<div class="navbar-form navbar-right">
{% if user.is_authenticated %}
<a id="logout" href="/accounts/logout" class="btn btn-success">Logout</a>
{% else %}
<a id="google_login" href="/accounts/google/login" class="btn btn-success">
Sign in with Google
</a>
{% endif %}
</div>
</div> -->





</div>
</div></br>
<div class="row">
Expand Down