Пример #1
0
def add_user(username, password, age, phone, email):
	_count, _rt_list = checkUser(username=username)
	if _count:
		return False
	else:
		_sql = 'insert into user(username, password, age, phone, email) value (%s, md5(%s), %s, %s, %s)'
		args = (username, password, age, phone, email)
		excute_mysql(_sql, args, fetch=False)
		return True
Пример #2
0
def add_user(username, password, age, phone, email):
    _count, _rt_list = checkUser(username=username)
    if _count:
        return False
    else:
        _sql = 'insert into user(username, password, age, phone, email) value (%s, md5(%s), %s, %s, %s)'
        args = (username, password, age, phone, email)
        excute_mysql(_sql, args, fetch=False)
        return True
Пример #3
0
def get_user():
	_cols = ('uid', 'username', 'password', 'age', 'phone', 'email')
	sql = 'select * from user'
	_rt = []
	_count, _rt_list = excute_mysql(sql)
	for i in _rt_list:
		_rt.append(dict(zip(_cols, i)))
	return _rt
Пример #4
0
def validate_login(username, password):
	#_sql = 'select * from user where username="******" and password=md5("{password}")'.format(username=username, password=password)
	#为了预防SQL注入,SQL语句写成如下:
	sql1 = 'select * from user where username=%s and password=md5(%s)'
	args = (username, password)
	print args
	_count, _rt_list = excute_mysql(sql1, args)
	return _count != 0
Пример #5
0
def get_user():
    _cols = ('uid', 'username', 'password', 'age', 'phone', 'email')
    sql = 'select * from user'
    _rt = []
    _count, _rt_list = excute_mysql(sql)
    for i in _rt_list:
        _rt.append(dict(zip(_cols, i)))
    return _rt
Пример #6
0
def validate_login(username, password):
    #_sql = 'select * from user where username="******" and password=md5("{password}")'.format(username=username, password=password)
    #为了预防SQL注入,SQL语句写成如下:
    sql1 = 'select * from user where username=%s and password=md5(%s)'
    args = (username, password)
    print args
    _count, _rt_list = excute_mysql(sql1, args)
    return _count != 0
Пример #7
0
def logTop(number):
	_rt = []
	count = 1
	#_sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip, url, status  order by cnt desc limit %s'
	_sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip ,url, status  order by cnt desc limit %s'
	args=(int(number),)
	_count, _rt_list = dbutils.excute_mysql(_sql, args)
	cols = ('number', 'ip', 'url', 'status', 'count')
	for i in _rt_list:
		_rt.append(dict(zip(cols,(count,i[0], i[1], i[2], i[3]))))
		count += 1
	#print _rt
	return _rt
Пример #8
0
def logTop(number):
    _rt = []
    count = 1
    #_sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip, url, status  order by cnt desc limit %s'
    _sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip ,url, status  order by cnt desc limit %s'
    args = (int(number), )
    _count, _rt_list = dbutils.excute_mysql(_sql, args)
    cols = ('number', 'ip', 'url', 'status', 'count')
    for i in _rt_list:
        _rt.append(dict(zip(cols, (count, i[0], i[1], i[2], i[3]))))
        count += 1
    #print _rt
    return _rt
Пример #9
0
def upToDb(uid, username, password, age, phone, email):
	sql = 'update user set password=md5(%s),age=%s,phone=%s,email=%s where id=%s and username=%s'
	args = (password, age, phone, email, uid, username)
	excute_mysql(sql, args, fetch=False)
	return True
Пример #10
0
def delUser(uid):
	sql = 'delete from user where id=%s'
	args = (uid, )
	excute_mysql(sql, args, fetch=False)
	return True
Пример #11
0
def checkUser(username=None, uid=None):
	_cols = ('uid', 'username', 'password', 'age', 'phone', 'email')
	sql = 'select * from user where username=%s or id=%s'
	args = (username,uid)
	_count, _rt_list = excute_mysql(sql, args)
	return _count, _rt_list
Пример #12
0
def upToDb(uid, username, password, age, phone, email):
    sql = 'update user set password=md5(%s),age=%s,phone=%s,email=%s where id=%s and username=%s'
    args = (password, age, phone, email, uid, username)
    excute_mysql(sql, args, fetch=False)
    return True
Пример #13
0
def delUser(uid):
    sql = 'delete from user where id=%s'
    args = (uid, )
    excute_mysql(sql, args, fetch=False)
    return True
Пример #14
0
def checkUser(username=None, uid=None):
    _cols = ('uid', 'username', 'password', 'age', 'phone', 'email')
    sql = 'select * from user where username=%s or id=%s'
    args = (username, uid)
    _count, _rt_list = excute_mysql(sql, args)
    return _count, _rt_list
Пример #15
0
def add_user(username, password, age, phone, email):
	userlist = get_user()
	userinfo = {'username': username, 'password': password, 'age': age, 'phone': phone, 'email': email}
	_sql = 'insert into user(username, password, age, phone, email) value (%s, md5(%s), %s, %s, %s)'
	args = (username, password, age, phone, email)
	excute_mysql(_sql, args, fetch=False)
Пример #16
0
def upToDb(uid, username, password, age, phone, email):
	sql = 'update user set age=%s,phone=%s,email=%s where id=%s and username=%s'
	args = (age, phone, email, uid, username)
	_count, _rt_list = excute_mysql(sql, args, fetch=False)