Пример #1
0
def register():
    title = 'REGISTER'
    form = UserInfoForm()
    if request.method == 'POST' and form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        password = form.password.data
        # print(username, email, password)
        # Check if username/email already exists
        existing_user = User.query.filter((User.username == username)
                                          | (User.email == email)).all()
        if existing_user:
            flash('That username or email already exists. Please try again',
                  'danger')
            return redirect(url_for('register'))

        new_user = User(username, email, password)
        db.session.add(new_user)
        db.session.commit()

        flash(f'Thank you {username} for registering!', 'success')
        return redirect(url_for('index'))

        login_user(user)
    return render_template('register.html', title=title, form=form)
Пример #2
0
def manage_registration():

    # It's a bit ugly to catch 'Other' affiliation here, but this mean not having to overwite
    # any of Flask-User's code for managing users
    # Note - user can ONLY set the temp_custom_affiliation from the register form
    # So this should only happen once
    if current_user.temp_custom_affiliation:
        current_user.affiliation = current_user.temp_custom_affiliation
        current_user.temp_custom_affiliation = None
        db.session.add(current_user)
        db.session.commit()

    form = UserInfoForm(obj=current_user)

    if form.validate_on_submit():
        form.populate_obj(current_user)
        db.session.add(current_user)
        db.session.commit()
        flash('Changes saved', 'success')
        return redirect(url_for('manage_registration'))

    u = User.query.all()
    n_dinner = [x.intends_dinner for x in u].count(True)
    return render_template('manage_registration.html',
                           form=form,
                           n_dinner=n_dinner)
def register():
    title = 'REGISTER'
    form = UserInfoForm()
    if request.method == 'POST' and form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        password = form.password.data
        existing_user = User.query.filter((User.username == username)
                                          | (User.email == email)).all()
        if existing_user:
            flash('That username or email already exists. Please try again',
                  'danger')
            return redirect(url_for('register'))

        new_user = User(username, email, password)
        db.session.add(new_user)
        db.session.commit()

        flash(f'Thank you {username} for registering!', 'success')

        msg = Message(f'Thank you, {username}', recipients=[email])
        msg.body = f'Dear {username}, thank you so much for signing up for this super cool app. I hope you enjoy and also you look super good today!'
        mail.send(msg)

        return redirect(url_for('index'))

    return render_template('register.html', title=title, form=form)