Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b13b6f

Browse files
Merge pull request #62 from pers0n4/feature/custom-user
개인화(회원) 기능 추가
2 parents a6435f6 + e9c982d commit 5b13b6f

File tree

8 files changed

+69
-0
lines changed

8 files changed

+69
-0
lines changed

‎account/__init__.py‎

Whitespace-only changes.

‎account/apps.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "account"

‎account/migrations/__init__.py‎

Whitespace-only changes.

‎account/urls.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.urls import include, path
2+
3+
from .views import GitHubLogin
4+
5+
urlpatterns = [
6+
path("auth/", include("dj_rest_auth.urls")),
7+
path("auth/github/login/", GitHubLogin.as_view(), name="github_login"),
8+
]

‎account/views.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
2+
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
3+
from dj_rest_auth.registration.views import SocialLoginView
4+
from django.conf import settings
5+
6+
7+
class GitHubLogin(SocialLoginView):
8+
adapter_class = GitHubOAuth2Adapter
9+
callback_url = settings.OAUTH_GITHUB_CALLBACK_URL
10+
client_class = OAuth2Client

‎pyconkr/settings.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@
3838
"django.contrib.sessions",
3939
"django.contrib.messages",
4040
"django.contrib.staticfiles",
41+
"django.contrib.sites",
4142
# add-on
4243
"rest_framework",
44+
"rest_framework.authtoken",
45+
"allauth",
46+
"allauth.account",
47+
"allauth.socialaccount",
48+
"allauth.socialaccount.providers.github",
49+
"allauth.socialaccount.providers.google",
50+
"allauth.socialaccount.providers.kakao",
51+
"dj_rest_auth",
4352
"django_summernote",
4453
"constance",
4554
"constance.backends.database",
@@ -96,6 +105,31 @@
96105
}
97106

98107

108+
# https://django-allauth.readthedocs.io/en/latest/providers.html
109+
110+
SOCIALACCOUNT_PROVIDERS = {
111+
"github": {},
112+
"google": {},
113+
"kakao": {},
114+
}
115+
116+
SITE_ID = 1
117+
118+
AUTHENTICATION_BACKENDS = [
119+
# Needed to login by username in Django admin, regardless of `allauth`
120+
"django.contrib.auth.backends.ModelBackend",
121+
# `allauth` specific authentication methods, such as login by e-mail
122+
"allauth.account.auth_backends.AuthenticationBackend",
123+
]
124+
125+
REST_AUTH = {
126+
"USE_JWT": True,
127+
"JWT_AUTH_COOKIE": "access_token",
128+
# "JWT_AUTH_SECURE": True,
129+
"JWT_AUTH_HTTPONLY": False,
130+
}
131+
132+
99133
# Password validation
100134
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
101135

@@ -155,6 +189,10 @@
155189
REST_FRAMEWORK = {
156190
# YOUR SETTINGS
157191
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
192+
"DEFAULT_AUTHENTICATION_CLASSES": (
193+
"rest_framework_simplejwt.authentication.JWTAuthentication",
194+
"dj_rest_auth.jwt_auth.JWTCookieAuthentication",
195+
),
158196
}
159197

160198
SPECTACULAR_SETTINGS = {
@@ -174,3 +212,5 @@
174212
}
175213

176214
CORS_ALLOW_ALL_ORIGINS = True
215+
216+
OAUTH_GITHUB_CALLBACK_URL = "http://localhost:8000/accounts/github/login/callback/"

‎pyconkr/urls.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
path("sponsors", include(sponsor.routers.get_router().urls)),
3333
path("status", include(status.urls)),
3434
path("programs/", include("program.urls")),
35+
path("", include("account.urls")),
3536
]
3637

3738
if settings.DEBUG is True:

‎requirements.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
asgiref==3.6.0
22
boto3==1.26.58
3+
cryptography==39.0.2
4+
dj-rest-auth==3.0.0
35
Django==4.1.5
6+
django-allauth==0.52.0
47
django-storages==1.13.2
58
django-import-export==3.0.2
69
djangorestframework==3.14.0
10+
djangorestframework-simplejwt==5.2.2
711
Markdown==3.4.1
812
mysql-connector-python==8.0.32
913
mysqlclient==2.1.1

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /