Exemplo n.º 1
0
    def post(self):
        form = RegisterForm(request.form)
        email = form.email.data
        username = form.username.data
        password = form.password.data
        schoolname = form.schoolname.data
        grade = form.grade.data
        userage = form.userage .data
        usergender = form.usergender .data
        #print(email)
        #print('数据获取')
        #print(form.validate())
        """
        context = {
            'oldusername': username,
            'email': email,
            'password': password,
            'grade': grade,
            'userage': userage,
            'usergender': usergender,
            'schoolname': schoolname
        }"""
        if form.validate():

            user = User(username=username,
                        parent_id=2,
                        email=email,
                        password=password,
                        role_permission=3,
                        grade=grade,
                        userage=userage,
                        usergender=usergender,
                        schoolname=schoolname)
            if not User.query.filter_by(email=email).first():
                db.session.add(user)
                db.session.commit()
                # print('注册正常')
                # flash('添加用户'+username+'成功')
                # message = '注册成功,请登录'
                return redirect(url_for('/'))
            else:
                flash("该邮箱已被注册!请更换邮箱!")
                message = "该邮箱已被注册!请更换邮箱!"
                return render_template('login.html',message =message)
        else:
            flash(form.get_error())
            message = form.get_error()
            return self.get(message=message)
Exemplo n.º 2
0
    def post(self):
        form = RegisterForm(request.form)
        if form.validate():
            username = form.username.data
            email = form.email.data
            password = form.password.data
            member = form.member.data
            school = form.school.data
            district = form.district.data
            print(district)

            if not User.query.filter_by(email=email).first():
                user = User(username=username,
                            email=email,
                            password=password,
                            role_id=member,
                            parent_id=g.user.id,
                            school_name=school,
                            district_name=district)
                db.session.add(user)
                db.session.commit()

                return restful.success()
            else:
                return restful.params_error("该邮箱已被注册!请更换邮箱!")
        else:
            return restful.params_error(form.get_error())