-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
75 lines (56 loc) · 1.98 KB
/
app.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
from flask import Flask, render_template, request, redirect, jsonify
from pymongo import MongoClient
import certifi
app = Flask(__name__, static_url_path='/static')
ca = certifi.where()
# 회원 정보를 저장할 변수
client = MongoClient('mongodb+srv://doyoung:[email protected]/?retryWrites=true&w=majority', tlsCAFile=ca)
db = client['dbsparta']
@app.route('/')
def index():
return render_template('index.html')
@app.route('/mainpage')
def mainpage():
return render_template('mainpage.html')
@app.route('/mypage')
def mypage():
return render_template('mypage.html')
@app.route('/blockgame')
def blockgame():
return render_template('blockgame.html')
@app.route('/dinosaur')
def dinosaur():
return render_template('dinosaur.html')
@app.route('/typing')
def typing():
return render_template('typing.html')
@app.route('/api/register', methods=['POST'])
def register():
username = request.form['username']
userId = request.form['userId']
password = request.form['password']
print("=========")
print(username, userId, password)
print("=========")
# 회원 정보를 MongoDB에 저장
user = {'username': username, 'id': userId, 'password': password}
try:
db.users.insert_one(user)
return jsonify({"status" : "success", "msg" : "회원 가입 성공."})
except:
return jsonify({"status" : "error","msg" : "에러가 발생했습니다."})
@app.route('/api/login', methods=['POST'])
def login():
userId = request.form['userId']
password = request.form['password']
# 회원 정보를 MongoDB에 저장
user = db.users.find_one({'id': userId, 'password': password})
if user is not None:
return jsonify({"status" : "success", "msg" : "로그인 성공."})
else :
return jsonify({"status" : "error","msg" : "로그인 실패."})
@app.route('/signIn')
def signIn():
return redirect('/')
if __name__ == '__main__':
app.run('0.0.0.0', port=5001, debug=True)