def chagepasswd(): if request.method == "POST": userdict = dict(request.form) if userdict['def_passwd'][0] == db.get_by_id( request.form.get('id'))['password']: if userdict['rep_passwd'][0] == userdict['password'][0]: new_password = [ "%s='%s'" % (k, v[0]) for k, v in userdict.items() ][1] db.update_user_data(new_password, userdict['id'][0]) else: return render_template('chage_passwd.html', user=db.get_by_id( request.form.get('id')), info='Two different Password') else: return render_template('chage_passwd.html', user=db.get_by_id(request.form.get('id')), info='error password!') return render_template('chage_passwd.html', user=db.get_by_id(request.form.get('id')), info='chage complete!!!') else: return render_template('chage_passwd.html', user=db.get_by_id(request.args.get('id')))
def userchagepasswd(): if not session.get('name', None) or session.get('role', None) != 'user': return redirect('/login') if request.method == "POST": userdict = dict(request.form) if userdict['def_passwd'][0] != get_by_id( request.form.get('id'))['password']: errmsg = "password error!" return json.dumps({'code': '1', 'errmsg': errmsg}) if userdict['rep_passwd'][0] != userdict['password'][0]: errmsg = "the two passwords don't match" return json.dumps({'code': '1', 'errmsg': errmsg}) else: new_password = [ "%s='%s'" % (k, v[0]) for k, v in userdict.items() ][1] update_user_data(new_password, userdict['id'][0]) return json.dumps({'code': '0', 'errmsg': "chage password sucess"}) else: roles = session.get('role', None) names = session.get('name', None) return render_template('user_passwd.html', user=get_by_id(request.args.get('id')), name=names, role=roles)
def update(): if request.method == "POST": userdict = dict(request.form) userlist = ["%s='%s'" % (k,v[0]) for k,v in userdict.items()] db.update_user_data(','.join(userlist),userdict['id'][0]) return redirect('/admin') else: return render_template('update.html',user=db.get_by_id(request.args.get('id')))
def update(): if not session.get('name',None) or session.get('role',None) != 'admin': return redirect('/login') if request.method == "POST": userdict = dict(request.form) userlist = ["%s='%s'" % (k,v[0]) for k,v in userdict.items()] update_user_data(','.join(userlist),userdict['id'][0]) return json.dumps({'code':'0','errmsg':"update sucess"}) else: return render_template('update.html',user=get_by_id(request.args.get('id')))
def chagepasswd(): if not session.get('name', None) or session.get('role', None) != 'admin': return redirect('/login') if request.method == "POST": userdict = dict(request.form) new_password = ["%s='%s'" % (k, v[0]) for k, v in userdict.items()][1] update_user_data(new_password, userdict['id'][0]) return json.dumps({'code': '0', 'errmsg': "chage password sucess"}) else: roles = session.get('role', None) names = session.get('name', None) return render_template('admin_passwd.html', user=get_by_id(request.args.get('id')), name=names, role=roles)
def update(): print(request.headers) print(type(request.get_json())) data = request.form update_user_data(request.get_json()) return "Done"