def add_user(): navigation = get_navigation_info(title="添加用户", sub_title="新的用户", tag="add_user") form = UserForm() if request.method == 'GET': return render_template('admin/edit_user.html', navigation=navigation, form=form) if request.method == 'POST': user = User(name=form.name.data, password=form.password.data, group_id=form.group_id.data, email=form.email.data, wechat=form.wechat.data, signature=form.signature.data) user.add_one() return redirect(url_for('admin.user'))
def register(): form = RegisterForm() if request.method == "POST": if not form.validate(): return Response(json.dumps({'code': 0, 'msg': form.get_first_error()}), content_type='application/json') if not session['verify_code'].lower() == form.VerifyCode.data.lower(): return Response(json.dumps({'code': 0, 'msg': "验证码不正确"}), content_type='application/json') if not session[form.Email.data].lower() == form.SmsCode.data.lower(): return Response(json.dumps({'code': 0, 'msg': "邮箱验证码不正确"}), content_type='application/json') user = User.query.filter_by(email=form.Email.data).first() if user is not None: return Response(json.dumps({'code': 0, 'msg': "用户已经存在"}), content_type='application/json') else: new_user = User(name=form.Name.data, password=form.Password.data, email=form.Email.data) new_user.add_one() login_user(new_user) session.pop(form.Email.data) return Response(json.dumps({'code': 1, 'msg': '注册成功'}), content_type='application/json')