-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsignup.py
83 lines (67 loc) · 2.62 KB
/
signup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from secrets import token_hex
from django.contrib.auth.models import User
from apps.core.backends.token import token_issue_email_auth
from apps.core.backends.util import validate_email
from apps.core.forms import UserForm
from apps.core.models import UserProfile
# signup using email
def signup_email(post):
user_f = UserForm(post)
raw_email = post.get('email', '')
if not user_f.is_valid() or not validate_email(raw_email):
return None
email = user_f.cleaned_data['email']
password = user_f.cleaned_data['password']
first_name = user_f.cleaned_data['first_name']
last_name = user_f.cleaned_data['last_name']
while True:
username = token_hex(10)
if not User.objects.filter(username=username).count():
break
user = User.objects.create_user(username=username,
first_name=first_name,
last_name=last_name,
email=email,
password=password)
user.save()
UserProfile(user=user, gender='*H').save()
token_issue_email_auth(user, newbie=True)
return user
# signup using social
def signup_social(typ, profile):
while True:
username = token_hex(10)
if not User.objects.filter(username=username).count():
break
first_name = profile.get('first_name', '')
last_name = profile.get('last_name', '')
email = profile.get('email', '')
if not email:
email = f'random-{token_hex(6)}@sso.sparcs.org'
while True:
if not User.objects.filter(email=email).count():
break
email = f'random-{token_hex(6)}@sso.sparcs.org'
user = User.objects.create_user(username=username,
first_name=first_name,
last_name=last_name,
email=email)
user.save()
user.profile = UserProfile(gender=profile.get('gender', '*H'))
if 'birthday' in profile:
if profile['birthday'].strip() == "":
user.profile.birthday = None
else:
user.profile.birthday = profile['birthday']
if typ == 'FB':
user.profile.facebook_id = profile['userid']
elif typ == 'TW':
user.profile.twitter_id = profile['userid']
elif typ == 'KAIST':
user.profile.email_authed = email.endswith('@kaist.ac.kr')
user.profile.save_kaist_info(profile)
elif typ == 'KAISTV2':
user.profile.email_authed = email.endswith('@kaist.ac.kr')
user.profile.save_kaist_v2_info(profile)
user.profile.save()
return user