def userlist(): if 'username' not in session: return redirect('/login/') msg = sessioninfo() field = [ "id", "username", "name_cn", "password", "mobile", "email", "role", "status" ] result = list('user', field) return render_template('userlist.html', msg=msg, result=result['msg'])
def delete(): if 'username' not in session: return redirect('/login/') msg = sessioninfo() if request.method == 'GET': userid = request.args.get('id') data = {'id': userid} if _delete('user', data): result = {'code': 0, 'msg': "delete user success"} return json.dumps(result)
def chmessageoneself(): if 'username' not in session: return redirect('/login/') msg = sessioninfo() if request.method == 'POST': field = ["username", "name_cn", "mobile", "email"] user = {k: v[0] for k, v in dict(request.form).items()} result = _update('user', field, user) if result['code'] == 0: result = {'code': 0, 'msg': "add user success"} return json.dumps(result)
def center(): if 'username' not in session: return redirect('/login/') msg = sessioninfo() field = [ "id", "username", "name_cn", "password", "mobile", "email", "role", "status" ] data = {'username': session['username']} result = getone('user', data, field) return render_template('center.html', msg=result['msg'])
def chpwdoneself(): if 'username' not in session: return redirect('/login/') msg = sessioninfo() chpwd = {k: v[0] for k, v in dict(request.form).items()} where = {'id': chpwd['id'], 'password': chpwd['oldpasswd']} field = ['id', 'password'] result = check('user', field, where) if result['code'] == 0: data = {'id': chpwd['id'], 'password': chpwd['newpasswd']} result = _update('user', field, data) else: result = { 'code': 1, 'msg': u"The password is rong, please input again." } return json.dumps(result)
def update(): if 'username' not in session: return redirect('/login/') msg = sessioninfo() field = [ "id", "username", "name_cn", "password", "mobile", "email", "role", "status" ] if request.method == 'GET': userid = request.args.get('id') data = {'id': userid} result = getone('user', data, field) return json.dumps(result['msg']) else: field = ["username", "name_cn", "mobile", "email", "role", "status"] user = {k: v[0] for k, v in dict(request.form).items()} result = _update('user', field, user) return json.dumps(result)