def register(): if not session.get('name', None): return redirect('/login') if session.get('role') != 'admin': errmsg = "you are not admin, can not register user" return render_template('userlist.html', result=errmsg) if request.method == 'POST': data = {} data = dict((k, v[0]) for k, v in dict(request.form).items()) data["create_time"] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) print data # data = request.get_json() fields = [ 'name', 'name_cn', 'mobile', 'email', 'role', 'status', 'password', 'create_time' ] if not data["name"] or not data["password"] or not data["role"]: errmsg = "name or password or role not null" return render_template("register.html", result=errmsg) if data["password"] != data["repwd"]: errmsg = "The two passwords you typed do not match" return render_template("register.html", result=errmsg) try: user_db.insert(fields, data) return redirect('/userinfo?name=%s' % data['name']) except: errmsg = 'insert error' print traceback.print_exc() return render_template("register.html", result=errmsg) else: return render_template("register.html")
def addidc(): if not session.get('name', None): return redirect('/login') # if session.get('role') != 'admin': # errmsg = "you are not admin, can not register idc" # return json.dumps({'code':1,'errmsg':'you are not admin, can not add idc'}) if request.method == 'POST': data = {} data = dict((k, v[0]) for k, v in dict(request.form).items()) print data # data = request.get_json() fields = ['name', 'isp', 'contact', 'mobile', 'address'] table = 'idc' if not data["name"]: errmsg = "name null" return render_template("idc.html", result=errmsg) try: user_db.insert(fields, data, table) return json.dumps({'code': 0, 'result': 'add idc success'}) except: print traceback.print_exc() return json.dumps({'code': 1, 'errmsg': 'add idc error'}) else: return render_template("addidc.html")
def add_user(): if not session.get('name', None): return redirect('/login') if session.get('role') != 'admin': return json.dumps({ 'code': 0, 'result': 'you are not admin, can not register user' }) if request.method == 'POST': data = {} data = dict((k, v[0]) for k, v in dict(request.form).items()) print data # data = request.get_json() fields = ['name', 'name_cn', 'mobile', 'email', 'role', 'status'] if not data["name"]: return json.dumps({'code': 1, 'result': 'name not null'}) try: table = 'users' user_db.insert(fields, data, table) return json.dumps({'code': 0, 'result': 'add user success'}) except: print traceback.print_exc() return json.dumps({'code': 1, 'result': 'name not null'}) else: return render_template("add.html", info=session)
def register(): if not session.get('name',None): return redirect('/login') if session.get('role') != 'admin': errmsg = "you are not admin, can not register user" return render_template('userlist.html', result = errmsg) if request.method == 'POST': data = {} data = dict((k,v[0]) for k,v in dict(request.form).items()) data["create_time"] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) print data # data = request.get_json() fields = ['name','name_cn','mobile','email','role','status','password','create_time'] if not data["name"] or not data["password"] or not data["role"]: errmsg = "name or password or role not null" return render_template("register.html", result=errmsg) if data["password"] != data["repwd"]: errmsg = "The two passwords you typed do not match" return render_template("register.html", result=errmsg) try: user_db.insert(fields,data) return redirect('/userinfo?name=%s' % data['name']) except: errmsg = 'insert error' print traceback.print_exc() return render_template("register.html", result=errmsg) else: return render_template("register.html")