Skip to content

Commit

Permalink
Adding a fast sign-in with google
Browse files Browse the repository at this point in the history
- adding routing [urls.py][1] and auth-all of django in the [settings.py][2] file
- made some minor changes in the [base.html][3]

Fast sign in with google for test users (in production adding gmail
email for testing the feature)
closes # 64
  • Loading branch information
maayanhd committed Apr 29, 2021
1 parent 6fab8f0 commit c636702
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 26 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ black = "*"
django = "*"
django-crispy-forms = "*"
pillow = "*"
django-allauth = "*"

[requires]
python_version = "3.8"
154 changes: 150 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ cd /vagrant
# Install dependencies with Pipenv
pipenv sync --dev

#installing package for google fast signing
pipenv install django-allauth

# Run database migrations
pipenv run python manage.py migrate

Expand Down
40 changes: 32 additions & 8 deletions picATrip/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

Expand All @@ -28,7 +27,6 @@

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand All @@ -43,6 +41,11 @@
'crispy_forms',
'Post.apps.PostConfig',
'commenting_system.apps.CommentingSystemConfig',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
]

MIDDLEWARE = [
Expand All @@ -60,7 +63,8 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
# Defining templates location
'DIRS': [str(BASE_DIR.joinpath("templates"))],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -75,7 +79,6 @@

WSGI_APPLICATION = 'picATrip.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

Expand All @@ -86,7 +89,6 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

Expand All @@ -105,7 +107,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

Expand All @@ -119,7 +120,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

Expand All @@ -130,7 +130,31 @@

CRISPY_TEMPLATE_PACK = 'bootstrap4'

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Django all auth settings
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)

SITE_ID = 1
# Turns off verification emails.
ACCOUNT_EMAIL_VERIFICATION = 'none'
LOGIN_REDIRECT_URL = 'homepage'
LOGIN_URL = 'login'
# Skips logout page
ACCOUNT_LOGOUT_ON_GET = True

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {'access_type': 'online'},
}
}
15 changes: 12 additions & 3 deletions picATrip/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from pickATrip_django_apps import views
from django.views.generic import TemplateView
from users import views as user_views


urlpatterns = [
path('admin/', admin.site.urls),
path('', views.homepage, name='homepage'),
path('about/', views.about, name='about'),
path(
'',
TemplateView.as_view(template_name="pickATrip_django_apps/homepage.html"),
name='homepage',
),
path(
'about/',
TemplateView.as_view(template_name="pickATrip_django_apps/about.html"),
name='about',
),
path('register/', user_views.register, name='register'),
path(
'login/',
Expand All @@ -39,6 +47,7 @@
),
path('profile/', user_views.profile, name='profile'),
path('postList/', include('Post.urls'), name='postList'),
path('accounts/', include('allauth.urls')),
]

if settings.DEBUG:
Expand Down
19 changes: 15 additions & 4 deletions pickATrip_django_apps/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ def __init__(self, general_model, admin_site):
super(ListAdminMixin, self).__init__(general_model, admin_site)


def is_related_to_social_signing(suspected_model):
return (
suspected_model._meta.model.__name__ == "Site"
or suspected_model._meta.model.__name__ == "EmailAddress"
or suspected_model._meta.model.__name__ == "SocialApp"
or suspected_model._meta.model.__name__ == "SocialToken"
or suspected_model._meta.model.__name__ == "SocialAccount"
)


# Register all other models automatically - should stay last in file.
models = apps.get_models()
for model in models:
admin_class = type('AdminClass', (ListAdminMixin, admin.ModelAdmin), {})
try:
admin.site.register(model, admin_class)
except admin.sites.AlreadyRegistered:
pass
if not is_related_to_social_signing(model):
try:
admin.site.register(model, admin_class)
except admin.sites.AlreadyRegistered:
pass
Loading

0 comments on commit c636702

Please sign in to comment.