Skip to content

Commit

Permalink
WIP-001: 사용자(User) 등록 과정 가안 작성 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rapsealk committed Feb 11, 2021
1 parent 4e3ed75 commit 636db45
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
__pycache__/
*.pyc

# Django
migrations/

# Docker
docker/*/data/*

Expand Down
3 changes: 2 additions & 1 deletion mercy/mercy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path

urlpatterns = [
path('kids/', include('mercykids.urls')),
path('admin/', admin.site.urls),
]
26 changes: 26 additions & 0 deletions mercy/mercykids/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.1.6 on 2021-02-04 11:12

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uid', models.CharField(max_length=200)),
('email', models.CharField(max_length=32)),
('password', models.CharField(max_length=64)),
('name', models.CharField(max_length=10)),
('nickname', models.CharField(max_length=10)),
('registered_at', models.DateTimeField()),
],
),
]
33 changes: 33 additions & 0 deletions mercy/mercykids/migrations/0002_auto_20210211_2040.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.1.6 on 2021-02-11 11:40

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mercykids', '0001_initial'),
]

operations = [
migrations.RemoveField(
model_name='user',
name='uid',
),
migrations.AddField(
model_name='user',
name='birthdate',
field=models.DateTimeField(default=datetime.datetime(1970, 1, 1, 9, 0)),
),
migrations.AlterField(
model_name='user',
name='id',
field=models.AutoField(primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='user',
name='registered_at',
field=models.DateTimeField(default=datetime.datetime(2021, 2, 11, 20, 40, 34, 953546)),
),
]
9 changes: 9 additions & 0 deletions mercy/mercykids/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name='index'),
path('auth/register', views.register_user, name='register_user'),
path('auth/verify', views.auth_verify_email, name='auth_verify_email')
]
67 changes: 66 additions & 1 deletion mercy/mercykids/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
from django.shortcuts import render
import json
from datetime import datetime

# from django.shortcuts import render
from django.http import JsonResponse

from mercykids.models import User

HTTP_OK = 200
HTTP_BAD_REQUEST = 400


class BooleanJsonResponse(JsonResponse):
def __init__(self, data: bool, status=HTTP_OK):
assert type(data) is bool
data = {"value": data}
super(BooleanJsonResponse, self).__init__(data, status=status)


# Create your views here.
def index(request):
# token = request.headers.get('Authorization', None)
# body = json.loads(request.body)
return JsonResponse({})


def auth_verify_email(request):
email = request.POST.get('email', None)
if email is None:
return JsonResponse({
"message": "이메일(email)이 입력되지 않았습니다."
},
status=HTTP_BAD_REQUEST,
json_dumps_params={'ensure_ascii': True})
is_email_registered = _is_email_registered(email)
return BooleanJsonResponse(is_email_registered)


def register_user(request):
# TODO: 1) 이메일 형태 검증 (regex)
# TODO: 2) 이메일 중복 확인
# TODO: 3) 비밀번호 해싱
email = request.POST.get('email', None)
password = request.POST.get('password', None)
name = request.POST.get('name', None)
nickname = request.POST.get('nickname', None)
birthdate = request.POST.get('birthdate', None)
user = User(
email=email,
password=password,
name=name,
nickname=nickname,
birthdate=datetime(*map(int, birthdate.split('-')))
)
user.save()

return BooleanJsonResponse(True)


def _is_email_registered(email: str) -> bool:
query = User.objects.filter(email=email)
try:
_ = query.get()
return True
except User.DoesNotExist:
return False
except Exception:
return False

0 comments on commit 636db45

Please sign in to comment.