Ejemplo n.º 1
0
def login():
    if current_user.is_authenticated:
        flash("You are already logged in", "info")
        return redirect(url_for("main.home"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user.confirmed:
            token = generate_confirmation_token(user.email)
            confirm_url = url_for("users.confirm_email",
                                  token=token,
                                  _external=True)
            send_confirm_email(user, token, confirm_url)
            flash("An email has been sent to confirm your email", "info")
            return redirect(url_for("main.home"))
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get("next")
            flash("Login Successful. You have been logged in.", "success")
            return redirect(next_page) if next_page else redirect(
                url_for("main.home"))
        else:
            flash("Login Unsuccessful. Please check email and password",
                  "danger")
    return render_template("login.html", title="Login", form=form)
Ejemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    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, password=hashed_password,
                    confirmed=False, confirmed_on=None)
        db.session.add(user)
        db.session.commit()
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('users.confirm_email', token=token, _external=True)
        html = render_template('main/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        login_user(user)

        flash('A confirmation email has been sent via email.', 'success')
        return redirect(url_for("main.home"))
    return render_template('main/register.html', title='Register', form=form)
Ejemplo n.º 3
0
def register():
    if current_user.is_authenticated and current_user.confirmed:
        return redirect(url_for('home'))
    form=RegistrationForm()
    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,password=hashed_password)
        db.session.add(user)
        db.session.commit()

        token = generate_confirmation_token(user.email)
        confirm_url = url_for('confirm_email', token=token, _external=True)
        send_email(user.email,confirm_url=confirm_url)

        flash('A confirmation email has been sent to your mail. Please verify your email', 'success')
        return redirect('register')
        if current_user.confirmed:
            login_user(user)
            return redirect('home')
        flash('Please confirm your account!', 'warning')
        return render_template('unconfirmed.html')
    return render_template('register.html',title='register',form=form)
Ejemplo n.º 4
0
def register():
    if current_user.is_authenticated:
        flash("You are already logged in", "info")
        return redirect(url_for("main.home"))
    form = RegistrationForm()
    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,
            password=hashed_password,
            confirmed=False,
        )
        db.session.add(user)
        db.session.commit()
        token = generate_confirmation_token(user.email)
        confirm_url = url_for("users.confirm_email",
                              token=token,
                              _external=True)
        send_confirm_email(user, token, confirm_url)
        flash("An email has been sent to confirm your email", "info")
        return redirect(url_for("home"))
    return render_template("register.html", title="Register", form=form)
Ejemplo n.º 5
0
def resend_confirmation():
    token = generate_confirmation_token(current_user.email)
    confirm_url = url_for('user.confirm_email', token=token, _external=True)
    send_email(current_user.email, confirm_url)
    flash('A new confirmation email has been sent.', 'success')
    return redirect(url_for('unconfirmed'))