Skip to content

Commit

Permalink
Merge pull request #11 from Django-Projects-Ls/feature/auth
Browse files Browse the repository at this point in the history
Feature/auth
  • Loading branch information
LopesLs committed Jan 1, 2024
2 parents 5e2bfe6 + c8d5b55 commit 07b0d5e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scheduleManagement/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends 'home.html' %}

{% load socialaccount %}

{% block navbar %} {% endblock %}

{% block title %} <title> Login Page </title> {% endblock %}
Expand All @@ -12,4 +14,5 @@ <h1>Login Page</h1>
<p> Don't have any account? Create one <a href="/sign-up">here</a>!</p>
<button type="submit">Login</button>
</form>
<a href="{% provider_login_url 'google' %}?next=/">Login with google</a>
{% endblock %}
32 changes: 32 additions & 0 deletions schoolschedules/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@

ALLOWED_HOSTS = ['*']

# Site ID

SITE_ID = 2

SOCIAL_ACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
}
}
}

# Application definition

INSTALLED_APPS = [
Expand All @@ -42,6 +58,11 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'scheduleManagement',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
]

MIDDLEWARE = [
Expand All @@ -52,6 +73,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware', # enable allauth
]

ROOT_URLCONF = 'schoolschedules.urls'
Expand Down Expand Up @@ -123,6 +145,16 @@

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# Authentication backends

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)

# Redirect URLs constants

LOGIN_URL = reverse_lazy('login') # redirect to login page if user is not logged in
LOGIN_REDIRECT_URL = reverse_lazy('home') # redirect to home page after login
LOGOUT_REDIRECT_URL = reverse_lazy('login') # redirect to login page after logout

1 change: 1 addition & 0 deletions schoolschedules/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
urlpatterns = [
path('', include('scheduleManagement.urls')),
path('', include('django.contrib.auth.urls')),
path('accounts/', include('allauth.urls')),
path('admin/', admin.site.urls),
]

0 comments on commit 07b0d5e

Please sign in to comment.