diff --git a/.idea/.idea/.gitignore b/.idea/.idea/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/.idea/.idea.iml b/.idea/.idea/.idea.iml
new file mode 100644
index 0000000..d0876a7
--- /dev/null
+++ b/.idea/.idea/.idea.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea/inspectionProfiles/Project_Default.xml b/.idea/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..5204d19
--- /dev/null
+++ b/.idea/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea/inspectionProfiles/profiles_settings.xml b/.idea/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea/misc.xml b/.idea/.idea/misc.xml
new file mode 100644
index 0000000..50dc922
--- /dev/null
+++ b/.idea/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea/modules.xml b/.idea/.idea/modules.xml
new file mode 100644
index 0000000..08f54a6
--- /dev/null
+++ b/.idea/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea/workspace.xml b/.idea/.idea/workspace.xml
new file mode 100644
index 0000000..0b98e2e
--- /dev/null
+++ b/.idea/.idea/workspace.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1691050027413
+
+
+ 1691050027413
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/main.py
+ 8
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.vs/.idea/v16/.suo b/.idea/.vs/.idea/v16/.suo
new file mode 100644
index 0000000..8208ead
Binary files /dev/null and b/.idea/.vs/.idea/v16/.suo differ
diff --git a/.idea/.vs/ProjectSettings.json b/.idea/.vs/ProjectSettings.json
new file mode 100644
index 0000000..f8b4888
--- /dev/null
+++ b/.idea/.vs/ProjectSettings.json
@@ -0,0 +1,3 @@
+{
+ "CurrentProjectSetting": null
+}
\ No newline at end of file
diff --git a/.idea/.vs/VSWorkspaceState.json b/.idea/.vs/VSWorkspaceState.json
new file mode 100644
index 0000000..6b61141
--- /dev/null
+++ b/.idea/.vs/VSWorkspaceState.json
@@ -0,0 +1,6 @@
+{
+ "ExpandedNodes": [
+ ""
+ ],
+ "PreviewInSolutionExplorer": false
+}
\ No newline at end of file
diff --git a/.idea/.vs/slnx.sqlite b/.idea/.vs/slnx.sqlite
new file mode 100644
index 0000000..fde3847
Binary files /dev/null and b/.idea/.vs/slnx.sqlite differ
diff --git a/.idea/main.py b/.idea/main.py
new file mode 100644
index 0000000..5596b44
--- /dev/null
+++ b/.idea/main.py
@@ -0,0 +1,16 @@
+# This is a sample Python script.
+
+# Press Shift+F10 to execute it or replace it with your code.
+# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
+
+
+def print_hi(name):
+ # Use a breakpoint in the code line below to debug your script.
+ print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
+
+
+# Press the green button in the gutter to run the script.
+if __name__ == '__main__':
+ print_hi('PyCharm')
+
+# See PyCharm help at https://www.jetbrains.com/help/pycharm/
diff --git a/accounts/__pycache__/__init__.cpython-311.pyc b/accounts/__pycache__/__init__.cpython-311.pyc
index 0fa8d19..3c2bb83 100644
Binary files a/accounts/__pycache__/__init__.cpython-311.pyc and b/accounts/__pycache__/__init__.cpython-311.pyc differ
diff --git a/accounts/__pycache__/admin.cpython-311.pyc b/accounts/__pycache__/admin.cpython-311.pyc
index 6ae62fb..4fee80e 100644
Binary files a/accounts/__pycache__/admin.cpython-311.pyc and b/accounts/__pycache__/admin.cpython-311.pyc differ
diff --git a/accounts/__pycache__/apps.cpython-311.pyc b/accounts/__pycache__/apps.cpython-311.pyc
index c4fcda8..4e3c658 100644
Binary files a/accounts/__pycache__/apps.cpython-311.pyc and b/accounts/__pycache__/apps.cpython-311.pyc differ
diff --git a/accounts/__pycache__/models.cpython-311.pyc b/accounts/__pycache__/models.cpython-311.pyc
index 7be3c70..1836ea1 100644
Binary files a/accounts/__pycache__/models.cpython-311.pyc and b/accounts/__pycache__/models.cpython-311.pyc differ
diff --git a/accounts/__pycache__/serializers.cpython-311.pyc b/accounts/__pycache__/serializers.cpython-311.pyc
new file mode 100644
index 0000000..90f2c87
Binary files /dev/null and b/accounts/__pycache__/serializers.cpython-311.pyc differ
diff --git a/accounts/__pycache__/urls.cpython-311.pyc b/accounts/__pycache__/urls.cpython-311.pyc
new file mode 100644
index 0000000..4e69a5c
Binary files /dev/null and b/accounts/__pycache__/urls.cpython-311.pyc differ
diff --git a/accounts/__pycache__/views.cpython-311.pyc b/accounts/__pycache__/views.cpython-311.pyc
new file mode 100644
index 0000000..409ba8b
Binary files /dev/null and b/accounts/__pycache__/views.cpython-311.pyc differ
diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py
new file mode 100644
index 0000000..3d97d95
--- /dev/null
+++ b/accounts/migrations/0001_initial.py
@@ -0,0 +1,35 @@
+# Generated by Django 4.2.3 on 2023-08-15 16:59
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ('auth', '0012_alter_user_first_name_max_length'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='User',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('password', models.CharField(max_length=128, verbose_name='password')),
+ ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
+ ('email', models.EmailField(blank=True, max_length=100, unique=True)),
+ ('nickname', models.CharField(blank=True, max_length=20, unique=True)),
+ ('is_superuser', models.BooleanField(default=False)),
+ ('is_active', models.BooleanField(default=True)),
+ ('is_staff', models.BooleanField(default=False)),
+ ('created_at', models.DateTimeField(auto_now_add=True)),
+ ('updated_at', models.DateTimeField(auto_now=True)),
+ ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
+ ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ ]
diff --git a/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc b/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc
new file mode 100644
index 0000000..7c5533a
Binary files /dev/null and b/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc differ
diff --git a/accounts/migrations/__pycache__/__init__.cpython-311.pyc b/accounts/migrations/__pycache__/__init__.cpython-311.pyc
index 33b3d36..351ad5e 100644
Binary files a/accounts/migrations/__pycache__/__init__.cpython-311.pyc and b/accounts/migrations/__pycache__/__init__.cpython-311.pyc differ
diff --git a/accounts/models.py b/accounts/models.py
index d511048..b4a31e9 100644
--- a/accounts/models.py
+++ b/accounts/models.py
@@ -1,26 +1,87 @@
+from django.contrib.auth.base_user import BaseUserManager
from django.db import models
+from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
-# Create your models here.
-class User(models.Model):
- user_id = models.IntegerField(primary_key=True)
- nickname = models.CharField(max_length=10, blank=True, null=True)
- password = models.CharField(max_length=20, blank=True, null=True)
- email = models.CharField(max_length=100, blank=True, null=True)
-
- class Meta:
- managed = False
- db_table = 'user'
- db_table_comment = '사용자 데이터'
-
-class Userinfo(models.Model):
- user = models.ForeignKey(User, models.DO_NOTHING, blank=True, null=True)
- height = models.IntegerField(blank=True, null=True)
- weight = models.FloatField(blank=True, null=True)
- bmi = models.FloatField(blank=True, null=True)
- info = models.CharField(max_length=100, blank=True, null=True)
- accvisibility = models.IntegerField(db_column='accVisibility', blank=True, null=True) # Field name made lowercase.
-
- class Meta:
- managed = False
- db_table = 'userinfo'
- db_table_comment = '사용자 정보'
\ No newline at end of file
+
+# class User(models.Model):
+# user_id = models.IntegerField(primary_key=True)
+# nickname = models.CharField(max_length=10, blank=True, null=True)
+# password = models.CharField(max_length=20, blank=True, null=True)
+# email = models.CharField(max_length=100, blank=True, null=True)
+#
+# # USERNAME_FIELD = 'email'
+# # REQUIRED_FIELDS = ['username']
+#
+# class Meta:
+# managed = False
+# db_table = 'user'
+# db_table_comment = '사용자 데이터'
+
+# class User(AbstractBaseUser):
+# user_id = models.AutoField(primary_key=True)
+# nickname = models.CharField(max_length=10, blank=True, null=True)
+# password = models.CharField(max_length=20, blank=True, null=True)
+# email = models.CharField(max_length=100, blank=True, null=True, unique=True)
+#
+# USERNAME_FIELD = 'email'
+# REQUIRED_FIELDS = ['username']
+#
+# class Meta:
+# managed = False
+# db_table = 'user'
+# db_table_comment = '사용자 데이터'
+
+
+class UserManager(BaseUserManager):
+ def create_user(self, email, nickname, password, **kwargs):
+ if not email:
+ raise ValueError('Users must have an email address')
+
+ user = self.model(
+ email=self.normalize_email(email),
+ # email=email,
+ nickname=nickname
+ )
+ user.set_password(password)
+ user.save(using=self._db)
+ return user
+
+ def create_superuser(self, email=None, nickname=None, password=None):
+ superuser = self.create_user(
+ email=email,
+ nickname=nickname,
+ password=password,
+ )
+ superuser.is_staff = True
+ superuser.is_superuser = True
+ superuser.is_active = True
+ superuser.save(using=self._db)
+ return superuser
+
+class User(AbstractBaseUser, PermissionsMixin):
+ objects = UserManager()
+
+ email = models.EmailField(max_length=100, blank=True, null=False, unique=True)
+ nickname = models.CharField(max_length=20, blank=True, null=False, unique=True)
+
+ is_superuser = models.BooleanField(default=False)
+ is_active = models.BooleanField(default=True)
+ is_staff = models.BooleanField(default=False)
+ created_at = models.DateTimeField(auto_now_add=True)
+ updated_at = models.DateTimeField(auto_now=True)
+
+ USERNAME_FIELD = 'nickname'
+ REQUIRED_FIELDS = ['email']
+
+# class Userinfo(models.Model):
+# user = models.ForeignKey(User, models.DO_NOTHING, blank=True, null=True)
+# height = models.IntegerField(blank=True, null=True)
+# weight = models.FloatField(blank=True, null=True)
+# bmi = models.FloatField(blank=True, null=True)
+# info = models.CharField(max_length=100, blank=True, null=True)
+# accvisibility = models.IntegerField(db_column='accVisibility', blank=True, null=True) # Field name made lowercase.
+#
+# class Meta:
+# managed = False
+# db_table = 'userinfo'
+# db_table_comment = '사용자 정보'
diff --git a/accounts/serializers.py b/accounts/serializers.py
index e69de29..b4e7a4c 100644
--- a/accounts/serializers.py
+++ b/accounts/serializers.py
@@ -0,0 +1,10 @@
+from rest_framework import serializers
+
+from accounts.models import User
+
+
+class UserSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = User
+ fields = '__all__'
+
diff --git a/accounts/urls.py b/accounts/urls.py
new file mode 100644
index 0000000..cd1cc95
--- /dev/null
+++ b/accounts/urls.py
@@ -0,0 +1,9 @@
+from django.urls import path, include
+
+from accounts.views import SigninAPIView
+
+urlpatterns = [
+ # path('', include('dj_rest_auth.urls')),
+ # path('signin/', include('dj_rest_auth.registration.urls')),
+ path('signin/', SigninAPIView.as_view())
+]
\ No newline at end of file
diff --git a/accounts/views.py b/accounts/views.py
index 91ea44a..f9e66ea 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -1,3 +1,35 @@
-from django.shortcuts import render
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
-# Create your views here.
+from accounts.serializers import UserSerializer
+
+#01-01 이메일 회원가입
+#로그인 시 이메일인지 닉네임인지 확인 필요
+class SigninAPIView(APIView):
+ def post(self, request):
+ serializer = UserSerializer(data=request.data)
+ if serializer.is_valid():
+ user = serializer.save()
+
+ token = TokenObtainPairSerializer.get_token(user)
+ refresh_token = str(token)
+ access_token = str(token.access_token)
+ res = Response(
+ {
+ "user": serializer.data,
+ "message": "Signin Success",
+ "token": {
+ "access": access_token,
+ "refresh": refresh_token,
+ },
+ },
+ status=status.HTTP_200_OK
+ )
+
+ res.set_cookie("access", access_token, httponly=True)
+ res.set_cookie("refresh", refresh_token, httponly=True)
+
+ return res
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
diff --git a/broccoli/__pycache__/settings.cpython-311.pyc b/broccoli/__pycache__/settings.cpython-311.pyc
index b6b7875..ab29415 100644
Binary files a/broccoli/__pycache__/settings.cpython-311.pyc and b/broccoli/__pycache__/settings.cpython-311.pyc differ
diff --git a/broccoli/__pycache__/urls.cpython-311.pyc b/broccoli/__pycache__/urls.cpython-311.pyc
index 6a7a49e..5581181 100644
Binary files a/broccoli/__pycache__/urls.cpython-311.pyc and b/broccoli/__pycache__/urls.cpython-311.pyc differ
diff --git a/broccoli/settings.py b/broccoli/settings.py
index 682d223..5af0a4c 100644
--- a/broccoli/settings.py
+++ b/broccoli/settings.py
@@ -9,7 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
-
+from datetime import timedelta
from pathlib import Path
import my_settings
@@ -33,6 +33,9 @@
# Application definition
+#user 설정
+AUTH_USER_MODEL = 'accounts.User'
+
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
@@ -40,7 +43,21 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
+
+ #라이브러리
'rest_framework',
+ 'rest_framework_simplejwt',
+ # 'dj_rest_auth',
+ # 'dj_rest_auth.registration',
+
+
+ # 'allauth',
+ # 'allauth.socialaccount',
+ # 'allauth.account',
+ 'rest_framework.authtoken',
+ # 'rest_auth.registration',
+
+ #앱
'usebody.apps.UsebodyConfig',
'accounts.apps.AccountsConfig',
]
@@ -55,6 +72,32 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
+# SITE_ID = 1
+# REST_USE_JWT = True
+
+#이메일 인증 안함
+# ACCOUNT_EMAIL_VERIFICATION = "none"
+# ACCOUNT_USER_MODEL_USERNAME_FIELD = None
+# ACCOUNT_EMAIL_REQUIRED = True
+# ACCOUNT_USERNAME_REQUIRED = False
+# ACCOUNT_AUTHENTICATION_METHOD = 'email'
+
+
+REST_FRAMEWORK = {
+ 'DEFAULT_AUTHENTICATION_CLASSES': (
+ 'rest_framework_simplejwt.authentication.JWTAuthentication',
+ )
+}
+
+#JWT 설정
+SIMPLE_JWT = {
+ 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=30),
+ 'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
+ 'ALGORITHM': 'HS256',
+ 'SIGNING_KEY': SECRET_KEY,
+ 'AUTH_HEADER_TYPES': ('JWT',),
+}
+
ROOT_URLCONF = 'broccoli.urls'
TEMPLATES = [
diff --git a/broccoli/urls.py b/broccoli/urls.py
index a84e6cc..599e790 100644
--- a/broccoli/urls.py
+++ b/broccoli/urls.py
@@ -19,5 +19,7 @@
urlpatterns = [
path('admin/', admin.site.urls),
- path('usebody/', include('usebody.urls'))
+ path('usebody/', include('usebody.urls')),
+ path('accounts/', include('accounts.urls')),
+
]
diff --git a/usebody/__pycache__/__init__.cpython-311.pyc b/usebody/__pycache__/__init__.cpython-311.pyc
index 011c09e..06e5fcb 100644
Binary files a/usebody/__pycache__/__init__.cpython-311.pyc and b/usebody/__pycache__/__init__.cpython-311.pyc differ
diff --git a/usebody/__pycache__/admin.cpython-311.pyc b/usebody/__pycache__/admin.cpython-311.pyc
index 663961d..61e8cd9 100644
Binary files a/usebody/__pycache__/admin.cpython-311.pyc and b/usebody/__pycache__/admin.cpython-311.pyc differ
diff --git a/usebody/__pycache__/apps.cpython-311.pyc b/usebody/__pycache__/apps.cpython-311.pyc
index e8f946e..c2e3984 100644
Binary files a/usebody/__pycache__/apps.cpython-311.pyc and b/usebody/__pycache__/apps.cpython-311.pyc differ
diff --git a/usebody/__pycache__/models.cpython-311.pyc b/usebody/__pycache__/models.cpython-311.pyc
index 8dcfda5..9174511 100644
Binary files a/usebody/__pycache__/models.cpython-311.pyc and b/usebody/__pycache__/models.cpython-311.pyc differ
diff --git a/usebody/__pycache__/serializers.cpython-311.pyc b/usebody/__pycache__/serializers.cpython-311.pyc
index 8ec2747..ffac50c 100644
Binary files a/usebody/__pycache__/serializers.cpython-311.pyc and b/usebody/__pycache__/serializers.cpython-311.pyc differ
diff --git a/usebody/__pycache__/urls.cpython-311.pyc b/usebody/__pycache__/urls.cpython-311.pyc
index b8339aa..49c6604 100644
Binary files a/usebody/__pycache__/urls.cpython-311.pyc and b/usebody/__pycache__/urls.cpython-311.pyc differ
diff --git a/usebody/__pycache__/views.cpython-311.pyc b/usebody/__pycache__/views.cpython-311.pyc
index 2701fca..fe0fa3e 100644
Binary files a/usebody/__pycache__/views.cpython-311.pyc and b/usebody/__pycache__/views.cpython-311.pyc differ
diff --git a/usebody/migrations/__pycache__/0001_initial.cpython-311.pyc b/usebody/migrations/__pycache__/0001_initial.cpython-311.pyc
index 3b507b2..5687138 100644
Binary files a/usebody/migrations/__pycache__/0001_initial.cpython-311.pyc and b/usebody/migrations/__pycache__/0001_initial.cpython-311.pyc differ
diff --git a/usebody/migrations/__pycache__/__init__.cpython-311.pyc b/usebody/migrations/__pycache__/__init__.cpython-311.pyc
index 3fa9a23..a8565dd 100644
Binary files a/usebody/migrations/__pycache__/__init__.cpython-311.pyc and b/usebody/migrations/__pycache__/__init__.cpython-311.pyc differ