def register(): username = request.form.get('user') email=request.form.get('email') password = request.form.get('pwd') cpassword = request.form.get('cpwd') if username==u"": return render_template('new_register.html', error=u'用户名不能为空') if email==u"": return render_template('new_register.html', error=u'邮箱不能为空') if password==u"": return render_template('new_register.html', error=u'密码不符合规则') user = users.query.filter_by(username=username).first() if user: return render_template('new_register.html', error=u'用户名已存在') if password != cpassword: return render_template('new_register.html', error=u'密码不一致') new_user = users() new_user.username = username new_user.set_password(password) db.session.add(new_user) db.session.commit() new_user_role = users_roles() new_user_role.user_name = username new_user_role.permissions = 3 db.session.add(new_user_role) db.session.commit() new_person=personal() new_person.username=username new_person.mail=email db.session.add(new_person) db.session.commit() return redirect(url_for('main.index'))
def register(): register_form = RegisterForm() if register_form.validate_on_submit(): new_user = users() new_user.username = register_form.username.data new_user.set_password(register_form.password.data) db.session.add(new_user) db.session.commit() flash("注册成功!请登录", category="success") return redirect(url_for('.login')) else: return redirect(url_for('.login'))
def register_phone(): phone_number = request.args.get('phone_number') password = request.args.get('password') confirm_password = request.args.get('confirm_password') Verification_code = request.args.get('Verification_code') data = {} if Verification_code_list[phone_number] == Verification_code: new_user = users() new_user.username = phone_number new_user.set_password(password) db.session.add(new_user) db.session.commit() new_user_role = users_roles() new_user_role.user_name = phone_number new_user_role.permissions = 3 db.session.add(new_user_role) db.session.commit() data['msg'] = 'success' return jsonify(data) data['msg'] = 'failure' return jsonify(data)