def setting(): """设置用户信息方法 """ g.user = user = User.is_login() form = SettingForm() u = User() if request.method == "POST": if not u.has_username(form.username.data) or session["username"] == form.username.data: """如果修改后的用户名不存在数据库或者和当前登录的用户名相同则更新数据库中对应的记录""" if form.username.data == "": flash(u"用户名不能为空", "error") return render_template("/user/setting.html", form=form, title=u"修改设置") if form.password.data == "": flash(u"密码不能为空", "error") return render_template("/user/setting.html", form=form, title=u"修改设置") if form.email.data == "": flash(u"邮箱不能为空", "error") return render_template("/user/setting.html", form=form, title=u"修改设置") if not u.edit(user, form.username.data, form.password.data, form.email.data): """写入数据库""" flash(u"修改失败", "error") return render_template("/user/setting.html", form=form, title=u"修改设置") user.dologin() flash(u"用户信息修改成功") return redirect(url_for("index")) else: flash(u"用户已存在", "warning") return render_template("/user/setting.html", form=form, title=u"修改设置") else: form.username = user.username form.password = user.password form.email = user.email return render_template("/user/setting.html", form=form, title=u"修改设置")
def info(): """显示用户信息方法 """ g.user = User() form = SettingForm() g.user.is_login() form.username = g.user.username form.password = g.user.password form.email = g.user.email return render_template("/user/info.html", form=form, title=u"用户信息")