def auth_sign_up(): if request.method == "GET": return render_template("auth/signup.html", form=SignUpForm()) form = SignUpForm(request.form) if request.method == "POST" and not form.validate_on_submit(): return render_template("auth/signup.html", form=form) name = form.name.data username = form.username.data password = form.password.data new_user = User(name, username, password) existing_user = User.query.filter_by(username=username).first() if existing_user is not None: return render_template( "auth/signup.html", form=form, extra_error="Käyttäjänimi varattu" ) db.session().add(new_user) db.session().commit() return redirect(url_for("auth_login"))
def signup(): form = SignUpForm() if form.validate_on_submit(): person = Person() person.username = form.username.data person.email = form.email.data person.password = form.password.data db.session.add(person) db.session.commit() login_user(person, remember=True) return redirect(url_for('index')) return templating.render_template('signup.j2', form=form)