Skip to content

Commit 297959f

Browse files
committed
added github authentication
1 parent 0281fdd commit 297959f

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

django_school/classroom/views/classroom.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.shortcuts import redirect, render
22
from django.views.generic import TemplateView
3-
3+
from ..models import Student
44

55
class SignUpView(TemplateView):
66
template_name = 'registration/signup.html'
@@ -13,3 +13,13 @@ def home(request):
1313
else:
1414
return redirect('students:quiz_list')
1515
return render(request, 'classroom/home.html')
16+
17+
18+
def save_github_user(backend, user, response, *args, **kwargs):
19+
if backend.name == 'github':
20+
if not user.is_student:
21+
user.is_student = True
22+
user.save()
23+
student = Student.objects.create(user=user)
24+
# avatar_url = response.get('avatar_url')
25+
# print(user, response)

django_school/django_school/settings.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import os
14+
from decouple import config
1415

1516
from django.contrib.messages import constants as messages
1617

@@ -22,7 +23,7 @@
2223
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
2324

2425
# SECURITY WARNING: keep the secret key used in production secret!
25-
SECRET_KEY = 'd$pxg6fisc4iwzk&vz^s_d0lkf&k63l5a8f!obktw!jg#4zvp3'
26+
SECRET_KEY = config('SECRET_KEY')
2627

2728
# SECURITY WARNING: don't run with debug turned on in production!
2829
DEBUG = True
@@ -135,9 +136,21 @@
135136

136137
'django.contrib.auth.backends.ModelBackend',
137138
]
138-
139-
SOCIAL_AUTH_GITHUB_KEY = '19c198d4322457e5917e'
140-
SOCIAL_AUTH_GITHUB_SECRET = '1bd51b62009a516e2071cb5b9c851f4cde89c8a3'
139+
SOCIAL_AUTH_PIPELINE = (
140+
'social_core.pipeline.social_auth.social_details',
141+
'social_core.pipeline.social_auth.social_uid',
142+
'social_core.pipeline.social_auth.auth_allowed',
143+
'social_core.pipeline.social_auth.social_user',
144+
'social_core.pipeline.user.get_username',
145+
'social_core.pipeline.user.create_user',
146+
'classroom.views.classroom.save_github_user', # <--- set the path to the function
147+
'social_core.pipeline.social_auth.associate_user',
148+
'social_core.pipeline.social_auth.load_extra_data',
149+
'social_core.pipeline.user.user_details',
150+
)
151+
152+
SOCIAL_AUTH_GITHUB_KEY = config('SOCIAL_AUTH_GITHUB_KEY')
153+
SOCIAL_AUTH_GITHUB_SECRET = config('SOCIAL_AUTH_GITHUB_SECRET')
141154

142155
# Custom Django auth settings
143156
AUTH_USER_MODEL = 'classroom.User'

django_school/django_school/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
urlpatterns = [
77
path('admin/', admin.site.urls),
88
path('', include('classroom.urls')),
9-
path('accounts/login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
9+
# path('accounts/login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
1010
path('accounts/', include('django.contrib.auth.urls')),
1111
path('accounts/signup/', classroom.SignUpView.as_view(), name='signup'),
1212
path('accounts/signup/student/', students.StudentSignUpView.as_view(), name='student_signup'),

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Django==3.0.4
22
django-crispy-forms==1.9.0
33
social-auth-app-django==3.1.0
4+
5+
python-decouple

0 commit comments

Comments
 (0)