-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
__pycache__/ | ||
*.pyc | ||
|
||
# Django | ||
migrations/ | ||
|
||
# Docker | ||
docker/*/data/* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |