def register():
    form = RegisterForm()
    if request.method == 'POST':
        if form.validate_on_submit():

            if User.query.filter(User.email == form.email.data).count() > 0:
                form.email.errors.append("Email address already in use.")
                return view('register', form)

            user = User(
                    name=form.name.data,
                    email=form.email.data,
                    password=form.password.data,
                    phone_number="+{0}{1}".format(form.country_code.data, form.phone_number.data),
                    area_code=str(form.phone_number.data)[0:3])

            db.session.add(user)
            db.session.commit()
            login_user(user, remember=True)

            return redirect_to('home')
        else:
            return view('register', form)

    return view('register', form)
Esempio n. 2
0
def register():
    form = RegisterForm()
    if request.method == "POST":
        if form.validate_on_submit():

            if User.query.filter(User.email == form.email.data).count() > 0:
                form.email.errors.append("Email address already in use.")
                return view("register", form)

            user = User(
                name=form.name.data,
                email=form.email.data,
                password=form.password.data,
                phone_number="+{0}{1}".format(form.country_code.data, form.phone_number.data),
            )
            db.session.add(user)
            db.session.commit()
            login_user(user, remember=True)

            return redirect_to("home")
        else:
            return view("register", form)

    return view("register", form)
Esempio n. 3
0
    def test_populate_register_form_with_missing_params_should_produce_error(
            self):
        form = RegisterForm(name='Name')

        assert form.validate() is False
Esempio n. 4
0
    def test_populate_register_form_with_missing_params_should_produce_error(self):
        form = RegisterForm(name='Name')

        assert form.validate() is False