|
11 | 11 | """ |
12 | 12 |
|
13 | 13 | import os |
| 14 | +from decouple import config |
14 | 15 |
|
15 | 16 | from django.contrib.messages import constants as messages |
16 | 17 |
|
|
22 | 23 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ |
23 | 24 |
|
24 | 25 | # 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') |
26 | 27 |
|
27 | 28 | # SECURITY WARNING: don't run with debug turned on in production! |
28 | 29 | DEBUG = True |
|
42 | 43 | 'django.contrib.humanize', |
43 | 44 |
|
44 | 45 | 'crispy_forms', |
45 | | - |
| 46 | + 'social_django', |
46 | 47 | 'classroom', |
47 | 48 | ] |
48 | 49 |
|
|
54 | 55 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
55 | 56 | 'django.contrib.messages.middleware.MessageMiddleware', |
56 | 57 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 58 | + |
| 59 | + 'social_django.middleware.SocialAuthExceptionMiddleware', |
57 | 60 | ] |
58 | 61 |
|
59 | 62 | ROOT_URLCONF = 'django_school.urls' |
|
71 | 74 | 'django.template.context_processors.request', |
72 | 75 | 'django.contrib.auth.context_processors.auth', |
73 | 76 | 'django.contrib.messages.context_processors.messages', |
| 77 | + |
| 78 | + 'social_django.context_processors.backends', # <-- |
| 79 | + 'social_django.context_processors.login_redirect', # <-- |
74 | 80 | ], |
75 | 81 | }, |
76 | 82 | }, |
|
123 | 129 | ] |
124 | 130 |
|
125 | 131 |
|
126 | | -# Custom Django auth settings |
| 132 | +AUTHENTICATION_BACKENDS = [ |
| 133 | + 'social_core.backends.github.GithubOAuth2', |
| 134 | + # 'social_core.backends.twitter.TwitterOAuth', |
| 135 | + # 'social_core.backends.facebook.FacebookOAuth2', |
| 136 | + |
| 137 | + 'django.contrib.auth.backends.ModelBackend', |
| 138 | +] |
| 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') |
127 | 154 |
|
| 155 | +# Custom Django auth settings |
128 | 156 | AUTH_USER_MODEL = 'classroom.User' |
129 | 157 |
|
130 | 158 | LOGIN_URL = 'login' |
131 | | - |
132 | 159 | LOGOUT_URL = 'logout' |
133 | | - |
134 | 160 | LOGIN_REDIRECT_URL = 'home' |
135 | | - |
136 | 161 | LOGOUT_REDIRECT_URL = 'home' |
137 | 162 |
|
138 | 163 |
|
139 | 164 | # Messages built-in framework |
140 | | - |
141 | 165 | MESSAGE_TAGS = { |
142 | 166 | messages.DEBUG: 'alert-secondary', |
143 | 167 | messages.INFO: 'alert-info', |
|
148 | 172 |
|
149 | 173 |
|
150 | 174 | # Third party apps configuration |
151 | | - |
152 | 175 | CRISPY_TEMPLATE_PACK = 'bootstrap4' |
0 commit comments