-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.html
More file actions
295 lines (246 loc) · 8.82 KB
/
Copy pathsignup.html
File metadata and controls
295 lines (246 loc) · 8.82 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>회원가입</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython_stdlib.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
background-color: #f2f2f2;
}
/* HEADER */
.header {
background-color: #ffffff;
height: 50px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
box-shadow: 0 1px 4px rgba(0,0,0,0.1);
position: fixed;
top: 0;
width: 100%;
z-index: 10;
}
.menu-button {
width: 24px;
height: 18px;
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.menu-button div {
background-color: #333;
height: 3px;
border-radius: 2px;
}
.menu {
background-color: white;
width: 100%;
position: fixed;
top: 50px;
left: 0;
z-index: 9;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.menu.show {
max-height: 300px;
}
.menu-item {
padding: 16px;
border-bottom: 1px solid #ddd;
text-decoration: none;
color: black;
display: block;
}
.header-title {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-weight: bold;
font-size: 14px;
}
.header-title a {
text-decoration: none;
color: #000;
}
.container {
max-width: 480px;
margin: 50px auto 0 auto; /* header 높이 고려 */
padding: 20px;
background-color: white;
min-height: calc(100vh - 50px);
box-sizing: border-box;
}
h2 {
text-align: center;
margin-bottom: 30px;
}
label {
display: block;
margin-top: 16px;
font-weight: bold;
}
input[type="text"],
input[type="url"] {
width: 100%;
padding: 10px;
margin-top: 6px;
border-radius: 6px;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
margin-top: 24px;
width: 100%;
padding: 12px;
background-color: #555;
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
}
button:hover {
background-color: #333;
}
</style>
</head>
<body onload="brython()">
<!-- HEADER -->
<div class="header">
<div class="menu-button" id="hamburger">
<div></div>
<div></div>
<div></div>
</div>
<div class="header-title">
<a href="index.html">성격기반 랜덤여행</a>
</div>
</div>
<!-- DROPDOWN MENU -->
<div class="menu" id="menu">
<!-- 여기에 Brython이 동적으로 삽입할 내용이 들어감 -->
</div>
<!-- FORM -->
<div class="container">
<h2>회원가입</h2>
<form id="signup-form">
<label for="student-id">학번</label>
<input type="text" id="student-id" name="student-id" required>
<label for="name">이름</label>
<input type="text" id="name" name="name" required>
<label for="major">학과</label>
<input type="text" id="major" name="major" required>
<label for="kakao">1대1 카카오톡 오픈 프로필 주소</label>
<input type="url" id="kakao" name="kakao" placeholder="https://open.kakao.com/..." required>
<label for="major">MBTI(선택)</label>
<input type="text" id="mbti" name="mbti">
<button type="submit">가입하기</button>
</form>
</div>
<script type="text/python">
from browser import document, alert, timer, window, html, ajax
import json
def setup_menu():
menu = document["menu"]
menu.clear()
user_info_str = window.sessionStorage.getItem("userInfo")
if user_info_str is None:
# 로그인 안 된 경우
menu <= html.A("회원가입", href="signup.html", Class="menu-item")
menu <= html.A("로그인", href="login.html", Class="menu-item")
else:
try:
user_info = json.loads(user_info_str)
name = user_info.get("name", "회원")
# 인사말 (텍스트만, 클릭 안 됨)
greet = html.SPAN(f"{name}님 반가워요", Class="menu-item")
greet.style.cursor = "default"
greet.style.marginRight = "10px"
menu <= greet
# 로그아웃 버튼
logout = html.A("로그아웃", href="#", Class="menu-item")
logout.bind("click", on_logout)
menu <= logout
except:
# 파싱 실패 시 강제 로그아웃
on_logout(None)
def on_logout(ev):
window.sessionStorage.removeItem("userInfo")
window.location.href = "index.html" # 메인 페이지로 이동
setup_menu()
def toggle_menu(event):
menu = document["menu"]
menu.classList.toggle("show")
document["hamburger"].bind("click", toggle_menu)
def validate_student_id(sid):
return sid.startswith("202") and len(sid) == 9 and sid.isdigit()
def validate_name(name):
return 2 <= len(name) <= 5
def validate_kakao_link(link):
return link.startswith("https://")
def validate_mbti(mbti):
return len(mbti) == 4 and mbti.isupper()
def on_submit(ev):
ev.preventDefault()
sid = document["student-id"].value
name = document["name"].value
major = document["major"].value
kakao = document["kakao"].value
mbti = document["mbti"].value.strip()
if not validate_student_id(sid):
alert("학번은 '202'로 시작하고 총 9자리여야 합니다.")
return
if not validate_name(name):
alert("이름은 2자 이상 5자 이하이어야 합니다.")
return
if mbti and not validate_mbti(mbti):
alert("MBTI는 대문자 영어 4글자이어야 합니다다")
return
if not validate_kakao_link(kakao):
alert("카카오톡 링크는 https://로 시작해야 합니다.")
return
new_user = {
"studentNumber": sid,
"name": name,
"lesson": major,
"kakaoProfileLink": kakao,
"mbti": mbti
}
user = {
"studentNumber": sid,
"name": name,
"lesson": major,
"kakaoProfileLink": kakao,
"mbti": mbti
}
req = ajax.ajax()
req.bind("complete", on_success)
req.open("POST", "http://3.106.164.28:5000/add_user", True) # EC2 IP 수정
req.set_header("Content-Type", "application/json")
req.send(json.dumps(user))
def on_success(req):
# 서버 응답이 200번대일 때 실행
# req.text 또는 req.json()으로 서버 응답 내용을 확인할 수 있습니다.
window.alert("회원가입이 완료되었습니다. \n로그인 후 서비스를 이용해주시길 바랍니다.")
window.location.href = "index.html"
def setup():
try:
form = document["signup-form"]
form.bind("submit", on_submit)
except KeyError:
alert("폼 요소를 찾을 수 없습니다. HTML에 id='signup-form'이 있는지 확인하세요.")
# 브라우저가 DOM을 모두 로드한 후 실행
timer.set_timeout(setup, 100)
</script>
</body>
</html>