Skip to content

Commit

Permalink
'FEAT:01-01'
Browse files Browse the repository at this point in the history
  • Loading branch information
jelee2555 committed Aug 15, 2023
1 parent 54fc683 commit 5cbaca0
Show file tree
Hide file tree
Showing 39 changed files with 359 additions and 28 deletions.
Empty file added .idea/.idea/.gitignore
Empty file.
8 changes: 8 additions & 0 deletions .idea/.idea/.idea.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions .idea/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .idea/.vs/.idea/v16/.suo
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/.vs/ProjectSettings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.vs/VSWorkspaceState.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .idea/.vs/slnx.sqlite
Binary file not shown.
16 changes: 16 additions & 0 deletions .idea/main.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified accounts/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/serializers.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added accounts/__pycache__/views.cpython-311.pyc
Binary file not shown.
35 changes: 35 additions & 0 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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,
},
),
]
Binary file not shown.
Binary file modified accounts/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
109 changes: 85 additions & 24 deletions accounts/models.py
Original file line number Diff line number Diff line change
@@ -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 = '사용자 정보'

# 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 = '사용자 정보'
10 changes: 10 additions & 0 deletions accounts/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from rest_framework import serializers

from accounts.models import User


class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = '__all__'

9 changes: 9 additions & 0 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -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())
]
36 changes: 34 additions & 2 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file modified broccoli/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified broccoli/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Loading

0 comments on commit 5cbaca0

Please sign in to comment.