-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
115 lines (101 loc) · 3.9 KB
/
admin.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
from flask import *
from flask_mysqldb import MySQL
import database as database
import re, hashlib
import os
import uuid
from ocr_core import ocr_core
from flask import request
import myModule as myModule
from werkzeug.utils import secure_filename
from datetime import datetime
import json as json
admin = Blueprint('admin', __name__)
@admin.route('/admin')
def adminIndex():
if session.get('admin'):
adminId = session.get('admin')
userData = database.select("SELECT * FROM admin where id='%s'" % (adminId))
history = database.select("SELECT t.*, u.* FROM `text` t INNER JOIN `user` u ON t.user_id = u.user_id;")
return render_template('admin/adminIndex.html', userData = userData, history = history)
else:
return redirect('/index')
@admin.route('/admin/updateText', methods = ["POST", "GET"])
def updateText():
if session.get('admin'):
if request.method == 'POST':
textId = request.form.get('textId')
textContent = request.form.get('textContent')
database.update("UPDATE text SET new_text='%s', last_edited=NOW() WHERE text_id='%s'" % (textContent, textId))
return 'success'
else:
return redirect('/index')
else:
return redirect('/index')
@admin.route('/admin/user')
def user():
if session.get('admin'):
usersData = database.select("SELECT * FROM user")
return render_template('admin/user.html', usersData = usersData)
else:
return redirect('/index')
@admin.route('/admin/deleteUser', methods = ['POST', 'GET'])
def deleteUser():
if session.get('admin'):
userId = request.form.get('userId')
database.delete("DELETE FROM user WHERE user_id='%s'" % (userId))
return 'success'
else:
return redirect('/index')
@admin.route('/admin/deleteDeo', methods = ['POST', 'GET'])
def deleteDeo():
if session.get('admin'):
deoId = request.form.get('deoId')
database.delete("DELETE FROM deo WHERE id='%s'" % (deoId))
return 'success'
else:
return redirect('/index')
@admin.route('/admin/blockDeo', methods = ['POST', 'GET'])
def blockDeo():
if session.get('admin'):
deoId = request.form.get('deoId')
database.update("UPDATE deo SET block = NOT block WHERE id='%s'" % (deoId))
return 'success'
else:
return redirect('/index')
@admin.route('/admin/verifyDeo', methods = ['POST', 'GET'])
def verifyDeo():
if session.get('admin'):
deoId = request.form.get('deoId')
database.update("UPDATE deo SET status = NOT status WHERE id='%s'" % (deoId))
return 'success'
else:
return redirect('/index')
@admin.route('/admin/deo')
def deo():
if session.get('admin') :
deoData = database.select("SELECT * FROM deo WHERE status='1'")
return render_template('admin/deo.html', deoData = deoData)
else:
return redirect('/index')
@admin.route('/admin/req')
def req():
if session.get('admin') :
deoData = database.select("SELECT * FROM deo WHERE status='0'")
return render_template('admin/request.html', deoData = deoData)
else:
return redirect('/index')
@admin.route('/admin/feedback')
def feedback():
if session.get('admin'):
feedbacks = database.select("SELECT f.*, u.name, u.username FROM feedback f JOIN user u ON f.user_id = u.user_id AND f.user_type = 'user' UNION SELECT f.*, d.name, d.username FROM feedback f JOIN deo d ON f.user_id = d.id AND f.user_type = 'deo'")
return render_template('admin/feedback.html', feedbacks = feedbacks)
else:
return redirect('/index')
@admin.route('/admin/logout')
def ocrResults():
if session.get('admin') :
session['admin'] = None
return 'success'
else:
return redirect('/index')