This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
forked from haohy/TDOA
/
data.py
159 lines (136 loc) · 4.86 KB
/
data.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
# -*- coding: utf-8 -*-
import os
import MySQLdb
import re
import random, md5, datetime, StringIO
from PIL import Image, ImageFont, ImageDraw, ImageColor
def SQLconn():
#SQL连接参数
#conn = {"host":"localhost", "user":"root", "passwd":"1234", "charset":"utf8", "db":"tdoa"}
conn = {"host":"https://qdm157632221.my3w.com", "user":"qdm157632221", "passwd":"hongyan0408", "charset":"utf8", "db":"qdm157632221_db"}
return conn
def checkin(user):
#校验密码
c = SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
print "connect mysql"
cursor.execute("SELECT account_password,account_name FROM account WHERE account_username='%s';"%user)
print "select passwd in mysql"
passwd = cursor.fetchall()
conn.close()
return passwd
def md5(passwd):
import hashlib
m = hashlib.md5()
m.update(passwd)
return m.hexdigest()
def get_calendar_data(arg):
c = SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
# print "connect mysql"
print arg.account, arg.start, arg.end
cursor.execute("SELECT mission.mission_name, mission.mission_id, mission.mission_starttime,\
mission.mission_plan_end_time\
FROM mission JOIN missions_doers\
ON mission.mission_id=missions_doers.mission_id\
WHERE missions_doers.mission_doer = '%s'\
AND (mission.mission_starttime BETWEEN '%s' AND '%s'\
OR mission.mission_plan_end_time BETWEEN '%s' AND '%s')"\
%(arg.account, arg.start, arg.end, arg.start, arg.end))
calendar_data = cursor.fetchall()
cursor.execute("SELECT mission_name, mission_id, mission_starttime, mission_endtime\
FROM history_mission\
WHERE mission_doer = '%s'\
AND (mission_starttime BETWEEN '%s' AND '%s'\
OR mission_endtime BETWEEN '%s' AND '%s')"\
%(arg.account, arg.start, arg.end, arg.start, arg.end))
calendar_data += cursor.fetchall()
calendar_list = list(calendar_data)
conn.close()
# print calendar_list
return calendar_data
def permission_check(user, account, type):
''' user:当前操作用户
account:要查看的用户
type:类型
如果允许,返回True,不允许,返回False
'''
if user == account:
return True
c = SQLconn()
conn = MySQLdb.connect(host=c["host"], user=c["user"], passwd=c["passwd"], charset=c["charset"], db=c["db"])
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
cursor.execute(
"SELECT account_department, account_power\
FROM ACCOUNT WHERE account_username = '%s'" % user
)
user_power = list(cursor.fetchall())
cursor.execute(
"SELECT account_department FROM account WHERE account_username = '%s'" % account
)
account_department = list(cursor.fetchall())
if type == 'mission':
#account_power1 == account_power/1000
if user_power[0]['account_power']/1000 == 2:
return True
if user_power[0]['account_department'] == account_department:
return true
else:
return False
if type == 'calendar':
#account_power2 == account_power%1000/100
if user_power[0]['account_power']%1000/100 == 2:
return True
if user_power[0]['account_department'] == account_department:
return True
else:
return False
if type == 'history_mission_modify':
#account_power3 == account_power%100/10
if user_power[0]['account_power']%100/10 == 1:
return True
return False
if type == 'file_manage':
#account_power4 == account_power%10
if user_power[0]['account_power']%10 == 1:
return True
return False
# get random color
def get_color():
colors = ['Black','Orange','Red','Brown','DarkBlue','Purple','DarkCyan','DarkBlue']
return ImageColor.getrgb(colors[random.randrange(1,9)-1])
# get random font-size
def get_font():
return ImageFont.truetype("arial.ttf", random.randrange(15,25,5))
# make code image
def make_check_code_image(image=''):
color = ImageColor.getrgb('white')
#im = Image.open(image)
im = Image.new('RGB',(60,20), color)
draw = ImageDraw.Draw(im)
import hashlib
mp = hashlib.md5()
mp_src = mp.update(str(datetime.datetime.now()))
mp_src = mp.hexdigest()
rand_str = mp_src[0:4]
#print rand_str
color = ImageColor.getrgb('LightGray')
for i in range(200):
x = random.randrange(1,60)
y = random.randrange(1,20)
draw.point((x, y), fill=color)
draw.text((5,1), rand_str[0], fill=get_color(), font=get_font())
draw.text((15,1), rand_str[1], fill=get_color(), font=get_font())
draw.text((30,1), rand_str[2], fill=get_color(), font=get_font())
draw.text((45,1), rand_str[3], fill=get_color(), font=get_font())
draw.line((0,10,60,15), fill=get_color())
del draw
# session['checkcode'] = rand_str
#print request.session['checkcode']
buf = StringIO.StringIO()
im.save(buf, 'gif')
buf.closed
if image: im.save(image)
return rand_str, buf.getvalue()