forked from kmswin1/InterviewNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
314 lines (265 loc) · 8.83 KB
/
run.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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
from flask import Flask
from flask import render_template, request, redirect, url_for, session, escape
from flask_cors import CORS
import json
import pymysql
import os
import smtplib
from email.mime.text import MIMEText
PWD = os.path.dirname(os.path.realpath(__file__))
app = Flask(__name__, template_folder="static/templates", static_folder="static")
id = {}
# <------ error hander---------->
@app.errorhandler(500)
def internal_error(error):
return "500 error"
@app.errorhandler(404)
def not_found(error):
return "404 error",404
#<------------------------------>
#<--------cors permission settins----------->
cors = CORS(app, resources={
r"/*": {"origin": "*"},
})
#<------------------------------------------>
def getConnection():
return pymysql.connect(host='54.244.72.128', user='root', password='1234',
db='InterviewNet', charset='utf8')
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' # session key
@app.route('/index')
def index():
return render_template("index.html")
@app.route('/signIn')
def signIn():
return render_template('signin.html')
@app.route('/logIn', methods=['GET','POST'])
def logIn():
if request.method == 'POST':
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
sql = "select userpw from Member where userid = %s"
curs.execute(sql, (jsonObj["userid"]))
result = curs.fetchone()
result = int(result["userpw"])
conn.commit()
print("getUserPW success")
print (result)
print (jsonObj["userpw"])
if result == int(jsonObj["userpw"]):
session['userid'] = jsonObj["userid"]
print ("login Success!!")
return redirect(url_for('index'))
print ("login failed")
return redirect(url_for('index'))
@app.route('/logOut')
def logOut():
# remove the username from the session if its there
session.pop('userid', None)
return redirect(url_for('index'))
@app.route('/idExist', methods=['POST'])
def idExist():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
getId = jsonObj["userid"]
print (jsonObj)
sql = "select userid from Member where userid = %s"
curs.execute(sql,(getId))
id = curs.fetchall()
print (len(id))
result = 1 # true
if len(id) == 0:
result = 0 # false
result = json.dumps(result)
return result
conn.commit()
conn.close()
result = json.dumps(result)
return result
@app.route('/nickExist', methods=['POST'])
def nickExist():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
getNickname = jsonObj["nickname"]
print (jsonObj)
sql = "select nickname from Member where nickname = %s"
curs.execute(sql,(getNickname))
nickname = curs.fetchall()
print (len(nickname))
result = 1 # true
if len(nickname) == 0:
result = 0 # false
result = json.dumps(result)
return result
conn.commit()
conn.close()
result = json.dumps(result)
return result
@app.route('/setSignUp', methods=['POST'])
def setSignUp():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "insert into Member(userid, userpw, city, college, major, town, nickname, username, point, birth, randNum) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
curs.execute(sql,(jsonObj["userid"], jsonObj["userpw"], jsonObj["city"], jsonObj["college"], jsonObj["major"], jsonObj["town"], jsonObj["nickname"], jsonObj["username"], jsonObj["point"], jsonObj["birth"], jsonObj["randNum"]))
conn.commit()
print ("setSignUp success")
conn.close()
return redirect(url_for('index'))
@app.route('/sign_up')
def sign_up():
return render_template("signup.html")
@app.route('/')
def main():
if 'userid' in session:
return 'Logged in as %s' % escape(session['userid'])
return render_template("main.html")
@app.route('/record')
def record():
return render_template('record.html')
@app.route('/sendQuestionOption', methods = ['PUT'])
def getQuestion():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print(jsonObj)
sql = "SELECT * FROM Question WHERE major=%s and company=%s"
curs.execute(sql, (jsonObj["occupation"], jsonObj["company"]))
results = {}
results = curs.fetchall()
jsonObj = json.dumps(results)
conn.commit()
print (jsonObj)
print("getQuestion success.")
conn.close()
return jsonObj
@app.route('/question')
def question():
return render_template("question.html")
@app.route('/matching')
def matching():
return render_template("matching.html")
@app.route('/getMemberInfo', methods=['PUT'])
def getMemberInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "select * from Matching where company = %s and city = %s and town = %s and major = %s"
curs.execute(sql,(jsonObj["company"], jsonObj["city"], jsonObj["town"], jsonObj["major"]))
results = curs.fetchall()
jsonObj = json.dumps(results)
conn.commit()
print (jsonObj)
print ("getMemberInfo success")
conn.close()
return jsonObj
@app.route('/setMember', methods=['POST'])
def setMember():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "insert into Matching(username, city, town, company, major, userInfo) values(%s, %s, %s, %s, %s, %s)"
curs.execute(sql,(jsonObj["username"], jsonObj["city"], jsonObj["town"], jsonObj["company"], jsonObj["major"], jsonObj["userInfo"]))
conn.commit()
print ("setMember success")
conn.close()
return redirect(url_for('matching'))
@app.route('/studyroom')
def studyroom():
return render_template("studyroom.html")
@app.route('/community')
def community():
return render_template("community.html")
@app.route('/write')
def write():
return render_template("write.html")
@app.route('/mypage')
def mypage():
return render_template("mypage.html")
@app.route('/post')
def post():
return render_template("post.html")
@app.route('/getPostInfo', methods=['GET'])
def getPostInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
sql = "select * from Info where id = %s"
global id
curs.execute(sql, (id))
results = curs.fetchone()
jsonObj = json.dumps(results)
conn.commit()
print ("getPostInfo success")
conn.close()
return jsonObj
@app.route('/getInfo', methods=['GET'])
def getInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
sql = "select * from Info order by id desc"
curs.execute(sql)
results = curs.fetchall()
jsonObj = json.dumps(results)
conn.commit()
print (jsonObj)
print ("getInfo success")
conn.close()
return jsonObj
@app.route('/writeInfo', methods=['POST'])
def writeInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "insert into Info(author, title, text, time, hit) values(%s, %s, %s, %s, %s)"
curs.execute(sql, (jsonObj["sid"], jsonObj["stitle"], jsonObj["stext"], jsonObj["stime"], jsonObj["sview"]))
conn.commit()
print ("writeInfo success")
conn.close()
return redirect(url_for('community'))
@app.route('/clickInfo', methods=['PUT'])
def clickInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "select hit from Info where id = %s"
curs.execute(sql, (jsonObj["id"]))
sql = "update Info set hit = %s where id = %s"
curs.execute(sql, (jsonObj["sview"], jsonObj["id"]))
conn.commit()
print ("clickInfo success")
global id
id = jsonObj["id"]
conn.close()
return redirect(url_for('post'))
@app.route('/reviseInfo', methods=['PUT'])
def reviseInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
return 1
@app.route('/delInfo', methods=['DELETE'])
def delInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
return 1
@app.route('/sendEmail', methods=['POST'])
def sendEmail():
smtp = smtplib.SMTP('smtp.live.com', 587)
smtp.ehlo() # say Hello
smtp.starttls() # TLS 사용시 필요
collegeMail = ''
id = ''
smtp.login('kmswin7@gmail.com', '1234')
msg = MIMEText('본문 테스트 메시지')
msg['Subject'] = '테스트'
msg['To'] = id+'@'+collegeMail
smtp.sendmail('kmswin7@gmail.com', id+'@'+collegeMail , msg.as_string())
smtp.quit()
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)