Showing
1 changed file
with
58 additions
and
0 deletions
1 | +import json | ||
2 | +import uuid | ||
3 | +from django.contrib.auth.hashers import make_password, check_password | ||
4 | +from django.core.exceptions import ValidationError | ||
5 | +from django.core.validators import validate_email | ||
6 | +from django.utils import timezone | ||
7 | +from ..models import File, User | ||
8 | + | ||
9 | + | ||
1 | # 회원가입 | 10 | # 회원가입 |
2 | def create(request): | 11 | def create(request): |
12 | + # Load | ||
13 | + try: | ||
14 | + received = json.loads(request.body.decode('utf-8')) | ||
15 | + except json.decoder.JSONDecodeError: | ||
16 | + return {'result': False, 'error': '입력이 잘못되었습니다.'} | ||
17 | + | ||
18 | + # Validate | ||
19 | + if 'email' not in received \ | ||
20 | + or 'password' not in received \ | ||
21 | + or 'name' not in received: | ||
22 | + return {'result': False, 'error': '입력이 누락되었습니다.'} | ||
23 | + | ||
24 | + # Validate Email | ||
25 | + try: | ||
26 | + validate_email(received['email']) | ||
27 | + except ValidationError: | ||
28 | + return {'result': False, 'error': '이메일 형식이 잘못되었습니다.'} | ||
29 | + | ||
30 | + # Validate Password | ||
31 | + if len(received['password']) < 8: | ||
32 | + return {'result': False, 'error': '비밀번호는 최소 8글자 입니다.'} | ||
33 | + | ||
34 | + # Validate Name | ||
35 | + if len(received['name']) > 50: | ||
36 | + return {'result': False, 'error': '이름은 최대 50글자 입니다.'} | ||
37 | + | ||
38 | + # Check Duplicates | ||
39 | + is_exists = User.objects.filter(email=received['email']) | ||
40 | + if len(is_exists) > 0: | ||
41 | + return {'result': False, 'error': '이미 사용중인 이메일 주소 입니다.'} | ||
42 | + | ||
43 | + # Insert | ||
44 | + root_folder = uuid.uuid4() | ||
45 | + user = User.objects.create( | ||
46 | + email=received['email'], | ||
47 | + password=make_password(received['password']), | ||
48 | + name=received['name'], | ||
49 | + root_folder=root_folder, | ||
50 | + created_at=timezone.now() | ||
51 | + ) | ||
52 | + File.objects.create( | ||
53 | + id=uuid.uuid4(), | ||
54 | + owner_user_id=user.id, | ||
55 | + type='folder', | ||
56 | + name='user_%s' % user.id, | ||
57 | + size=0, | ||
58 | + created_at=timezone.now() | ||
59 | + ) | ||
60 | + | ||
3 | return {'result': True} | 61 | return {'result': True} |
4 | 62 | ||
5 | 63 | ... | ... |
-
Please register or login to post a comment