def userlist(): if not session.get('name',None): return redirect('/login') users = [] fields = ['id', 'name', 'name_cn', 'email', 'mobile'] try: role = session['role'] if role != 'admin': condition = 'name = "%s"' % session.get('name',None) result = user_db.selectOne(fields,condition) users = [dict((k,result[i]) for i,k in enumerate(fields))] else: result = user_db.selectAll(fields) users = [dict((k,row[i]) for i,k in enumerate(fields)) for row in result] return render_template('userlist.html', users = users) except: errmsg = "select userlist failed" print traceback.print_exc() return render_template("userlist.html",result=errmsg)
def login(): if request.method == 'POST': data = dict((k,v[0]) for k,v in dict(request.form).items()) if not data.get('name',None) or not data.get('password',None): return json.dumps({'code':1,'errmsg':'password error'}) fields = ['name','password','role'] condition = 'name = "%(name)s"' % data res = user_db.selectOne(fields,condition) if not res: return json.dumps({'code':1,'result':'name not exist'}) user = dict((k,res[i]) for i,k in enumerate(fields)) if data['password'] != user['password']: return json.dumps({'code':1, 'result':'password error'}) session['name'] = user['name'] session['role'] = user['role'] return json.dumps({'code':0, 'result':'login success'}) else: return render_template('login.html')
def userlist(): if not session.get('name', None): return redirect('/login') users = [] fields = ['id', 'name', 'name_cn', 'email', 'mobile'] try: role = session['role'] if role != 'admin': condition = 'name = "%s"' % session.get('name', None) result = user_db.selectOne(fields, condition) users = [dict((k, result[i]) for i, k in enumerate(fields))] else: result = user_db.selectAll(fields) users = [ dict((k, row[i]) for i, k in enumerate(fields)) for row in result ] return render_template('userlist.html', users=users) except: errmsg = "select userlist failed" print traceback.print_exc() return render_template("userlist.html", result=errmsg)
def userinfo(): if not session.get('name', None): redirect('/login') where = {} where['id'] = request.args.get('id', None) where['name'] = request.args.get('name', None) if not where['id'] and not where['name']: errmsg = "must hava a where" return render_template('index.html', result=errmsg) if where['id'] and not where['name']: condition = 'id = "%(id)s"' % where if where['name'] and not where['id']: condition = 'name = "%(name)s"' % where fields = ['id', 'name', 'name_cn', 'email', 'mobile'] try: res = user_db.selectOne(fields, condition) user = dict((k, res[i]) for i, k in enumerate(fields)) return render_template('index.html', user=user) except: errmsg = "get one failed" print traceback.print_exc() return render_template("index.html", result=errmsg)
def userinfo(): if not session.get('name',None): redirect('/login') where = {} where['id'] = request.args.get('id',None) where['name'] = request.args.get('name',None) if not where['id'] and not where['name']: errmsg = "must hava a where" return render_template('index.html', result = errmsg ) if where['id'] and not where['name']: condition = 'id = "%(id)s"' % where if where['name'] and not where['id']: condition = 'name = "%(name)s"' % where fields = ['id', 'name', 'name_cn', 'email', 'mobile'] try: res = user_db.selectOne(fields,condition) user = dict((k,res[i]) for i,k in enumerate(fields)) return render_template('index.html', user = user) except: errmsg = "get one failed" print traceback.print_exc() return render_template("index.html",result=errmsg)
def login(): if request.method == 'POST': data = dict((k, v[0]) for k, v in dict(request.form).items()) if not data.get('name', None) or not data.get('password', None): errmsg = "name or password not null" return render_template('login.html', result=errmsg) fields = ['name', 'password', 'role'] condition = 'name = "%(name)s"' % data res = user_db.selectOne(fields, condition) if not res: errmsg = "%s does not exit" % data['name'] return render_template('login.html', result=errmsg) user = dict((k, res[i]) for i, k in enumerate(fields)) if data['password'] != user['password']: errmsg = "password is wrong" return render_template('login.html', result=errmsg) session['name'] = user['name'] session['role'] = user['role'] return redirect('/userlist') else: return render_template('login.html')
def login(): if request.method == 'POST': data = dict((k,v[0]) for k,v in dict(request.form).items()) if not data.get('name',None) or not data.get('password',None): errmsg = "name or password not null" return render_template('login.html', result = errmsg) fields = ['name','password','role'] condition = 'name = "%(name)s"' % data res = user_db.selectOne(fields,condition) if not res: errmsg = "%s does not exit" % data['name'] return render_template('login.html', result = errmsg) user = dict((k,res[i]) for i,k in enumerate(fields)) if data['password'] != user['password']: errmsg = "password is wrong" return render_template('login.html', result = errmsg) session['name'] = user['name'] session['role'] = user['role'] return redirect('/userlist') else: return render_template('login.html')