-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
179 lines (145 loc) · 4.19 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
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
from logging import debug
from dotenv import load_dotenv
from flask.globals import session
load_dotenv()
from flask import Flask,render_template,request, make_response,jsonify
from flask_session import Session
from flask_migrate import Migrate
from flask_socketio import SocketIO,emit,join_room,send,leave_room
import os
from config import Config
from model.models import db
from utils.confirm_mail import *
from cache import cache
from utils.auth_wrap import login_auth,confirm_auth
app = Flask(__name__)
app.config.from_object(Config)
socketio = SocketIO(cors_allowed_origins="*") #cors for dns
Session(app)
cache.init_app(app)
mail.init_app(app)
db.init_app(app)
socketio.init_app(app)
migrate = Migrate(app,db,compare_type=True)
@app.route('/')
@cache.cached(timeout=60*60)
def home():
return render_template('home.html')
@app.route('/product/<id>')
@cache.cached(timeout=60*60)
def product(id):
return render_template('product.html')
@app.route('/purchase_set/')
@cache.cached(timeout=60*60)
@login_auth
@confirm_auth
def purchaseSet():
return render_template('merchandisePost.html')
@app.route('/sign_up')
@cache.cached(timeout=60*60)
def sign_up():
return render_template('sign_up.html')
@app.route('/sign_in')
@cache.cached(timeout=60*60)
def sign_in():
return render_template('sign_in.html',client_id=os.getenv('google_oauth_client_id'),client_password=os.getenv('google_oauth_client_password'))
@app.route('/board')
@cache.cached(timeout=60*60)
@login_auth
def board():
return render_template('board.html')
@app.route('/checkout')
@cache.cached(timeout=60*60)
def cart():
return render_template('checkout.html')
@app.route('/profile')
@cache.cached(timeout=60*60)
@login_auth
def profile():
return render_template('profile.html')
@app.route('/booking')
@cache.cached(timeout=60*60)
@login_auth
def group():
return render_template('booking.html')
@app.route('/message')
@cache.cached(timeout=60*60)
@login_auth
def message():
return render_template('message.html')
@app.route('/seller')
@cache.cached(timeout=60*60)
@login_auth
def seller():
return render_template('seller.html')
@app.route('/seller/product/<p_id>')
@cache.cached(timeout=60*60)
@login_auth
def seller_product(p_id):
return render_template('seller_product.html')
@app.route('/details')
@cache.cached(timeout=60*60)
@login_auth
def detail():
return render_template('detail.html')
@app.route('/ledger')
@cache.cached(timeout=60*60)
@login_auth
def ledger():
if session['admin']!=True:
data = {'error': True}
return make_response(jsonify(data), 403)
return render_template('ledger.html')
@app.route('/test')
@cache.cached(timeout=60*60)
def test():
send_email(['[email protected]'],'測試','abc')
return{
'ok':True
}
# @socketio.on('connect')
# def test_connect():
# print('what')
@socketio.on('join')
def on_join(data):
username = data['username']
room = data['room']
join_room(room)
#send(username + f' has entered the room{room}.', room=room)
@socketio.on('leave')
def on_leave(data):
username = data['username']
room = data['room']
leave_room(room)
#send(username + ' has left the room.', to=room)
@socketio.on('receive message')
def handle_my_custom_event(msg):
print(msg['message'])
send(msg,room=msg['room'])
@socketio.on('json')
def handle_json(json):
print('received json: ' + str(json))
from api.user import user_api
from api.product import product
from api.message_api import message_api
from api.sub_message_api import sub_message_api
from api.cart import cart
from api.chat_room import chat_room
from api.chat_message import chat_message
from api.order import order
from api.ledger import ledger
from api.notify import notify
from api.confirm import confirm
app.register_blueprint(user_api)
app.register_blueprint(product)
app.register_blueprint(message_api)
app.register_blueprint(sub_message_api)
app.register_blueprint(cart)
app.register_blueprint(chat_room)
app.register_blueprint(chat_message)
app.register_blueprint(order)
app.register_blueprint(ledger)
app.register_blueprint(notify)
app.register_blueprint(confirm)
if __name__ =='__main__':
socketio.run(app, host="0.0.0.0",port=5000,debug=True)