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

Feature/auth #11

Merged
merged 2 commits into from
Jan 1, 2024
Merged
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
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),
]