Beispiel #1
0
def register():
    user_count = db.session.query(User).count()

    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    form = RegistrationForm()
    form.country.choices = [(i['name'], i['name']) for i in countries]

    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    country=form.country.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        send_confirmation_email(user)
        flash('A confirmation email has been sent to you by email.', 'info')
        # flash('Your account has been created! You are now able to log in',
        #     'success')  # messages that pop up, 'success' is used for bootstrap
        subscribe_user(user.email, "*****@*****.**",
                       app.config['MAIL_API_KEY'])
        return redirect(url_for('users.login'))
    return render_template('register.html',
                           title='Register',
                           form=form,
                           user_count=user_count)
Beispiel #2
0
    def confirm(self):
        link = request.url_root[0:-1] + url_for(
            "users.confirmation",
            confirmation_id=self.most_recent_confirmation.id)
        subject = "Registration confirmation."
        text = f"Please click link to confirm your registration {link}"
        html = f'<html>Please click link to confirm your registration: <a href="{link}">{link}</a></html>'

        return send_confirmation_email(self.email, subject, text, html)
Beispiel #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        try:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(username=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
            db.session.add(user)
            db.session.commit()
            flash(
                f'Your have successfully registered. Please confirm your email to login',
                'success')
            send_confirmation_email(user)
            return redirect(url_for('users.login'))
        except Exception as e:
            db.session.rollback()
            flash(
                f'Registration is unsuccessful due to some server error. Try Again',
                'Danger')
    return render_template('register.html', title="Register", form=form)
Beispiel #4
0
def resend_confirmation():
    send_confirmation_email(current_user)
    flash('A new confirmation email has been sent to you by email.', 'success')
    return redirect(url_for('users.login'))