Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/web/thisdb/user.py

113 lines
3.4 KiB

6 months ago
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
import core.mw as mw
6 months ago
__field = 'id,name,password,login_ip,login_time,phone,email,add_time,update_time'
6 months ago
# 初始化用户信息
def initAdminUser():
6 months ago
data = mw.M('users').field(__field).where('id=?', (1,)).find()
6 months ago
if data is None:
name = mw.getRandomString(8).lower()
password = mw.getRandomString(8).lower()
5 months ago
now_time = mw.formatDate()
6 months ago
login_ip = '127.0.0.1'
add_user = {
'name':name,
'password':mw.md5(password),
'login_ip':login_ip,
5 months ago
'login_time':now_time,
6 months ago
'phone':'',
'email':'',
5 months ago
'add_time':now_time,
'update_time':now_time
6 months ago
}
file_pass_pl = mw.getPanelDataDir() + '/default.pl'
mw.writeFile(file_pass_pl, password)
mw.M('users').insert(add_user)
return True
5 months ago
def getUserByName(name) -> None:
6 months ago
'''
获取用户信息通过用户名
'''
6 months ago
data = mw.M('users').field(__field).where('name=?', (name,)).find()
6 months ago
if data is None:
6 months ago
return None
row = {}
6 months ago
row['id'] = data['id']
row['name'] = data['name']
row['password'] = data['password']
row['login_ip'] = data['login_ip']
row['login_time'] = data['login_time']
row['phone'] = data['phone']
row['email'] = data['email']
row['add_time'] = data['add_time']
row['update_time'] = data['update_time']
6 months ago
return row
6 months ago
5 months ago
def getUserById(id) -> None:
6 months ago
'''
获取用户信息通过用户名
'''
6 months ago
data = mw.M('users').field(__field).where('id=?', (1,)).find()
6 months ago
if data is None:
6 months ago
return None
row = {}
6 months ago
row['id'] = data['id']
row['name'] = data['name']
row['password'] = data['password']
row['login_ip'] = data['login_ip']
row['login_time'] = data['login_time']
row['phone'] = data['phone']
row['email'] = data['email']
row['add_time'] = data['add_time']
row['update_time'] = data['update_time']
6 months ago
return row
def getUserByRoot() -> None:
'''
获取用户信息通过用户名
'''
return getUserById(1)
6 months ago
def updateUserLoginTime():
now_time = mw.formatDate()
6 months ago
mw.M('users').field(__field).where('id=?', (1,)).update({'login_time':now_time})
6 months ago
return True
6 months ago
def setUserByName(name, new_name):
return mw.M('users').where("name=?", (name,)).setField('name', new_name.strip())
def setUserPwdByName(name, password):
pwd = mw.md5(password)
return mw.M('users').where("name=?", (name,)).setField('password', pwd)
5 months ago
def setUserByRoot(name = None,password = None) -> bool:
6 months ago
'''
设置配置的值
:name -> str 名称 (必填)
:value -> object值 (必填)
:type -> str 类型 (可选|默认common)
'''
data = {}
if name is not None:
5 months ago
mw.M('users').where('id=?', (1,)).setField('name', name)
6 months ago
if password is not None:
pwd = mw.md5(password)
mw.M('users').where('id=?', (1,)).setField('password', pwd)
if not data:
return False
return True