def signup(): form = SignupForm(request.form) if request.method == 'POST' and form.validate(): flash('Signup requested for {}'.format(form.name.data)) # Code to add the student to the database goes here return redirect(url_for('main.index')) return render_template('signup.html', form=form)
def signup(): form = SignupForm(request.form) if request.method == 'POST' and form.validate(): users = User(username=form.username.data, email=form.email.data) try: db.session.add(users) db.session.commit() flash('You are now a registered user!') return redirect(url_for('main.index')) except IntegrityError: db.session.rollback() flash('ERROR! Unable to register {}. Please check your details are correct and resubmit'.format(form.email.data), 'error') return render_template('signup.html', form=form)
def signup(): form = SignupForm(request.form) if request.method == 'POST' and form.validate(): if form.role.data == "student": user = Student(name=form.name.data, email=form.email.data, student_ref=form.uni_id.data) else: user = Teacher(name=form.name.data, title=form.title.data, teacher_ref=form.uni_id.data, email=form.email.data) user.set_password(form.password.data) try: db.session.add(user) db.session.commit() flash('You are now a registered user!') return redirect(url_for('main.index')) except IntegrityError: db.session.rollback() flash( 'ERROR! Unable to register {}. Please check your details are correct and resubmit' .format(form.email.data), 'error') return render_template('signup.html', form=form)