Exemplo n.º 1
0
def signup():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))

    form = SignupForm()
    if form.validate_on_submit():
        new_user = User(form.username.data, form.email.data, form.password.data)
        mail_activation = UserMailActivation(new_user)

        db.session.add(new_user)
        db.session.add(mail_activation)
        db.session.commit()

        result, message = send_email(
            'Framgia Level Checker - Account Confirmation',
            app.config['MAIL_SENDERS']['admin'],
            [new_user.email],
            'confirm_activation',
            dict(token=mail_activation.token)
        )
        if not result:
            form.email.errors.append('Error: ' + message)
        else:
            return render_template('user/confirm_mail_sent.html', user=new_user)

    return render_template('user/signup.html', form=form)
Exemplo n.º 2
0
def resend_confirm():
    form = ResendMailForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        mail_activation = UserMailActivation.query.filter_by(user_id=user.id).first()
        if not mail_activation:
            mail_activation = UserMailActivation(user)
        else:
            mail_activation.refresh()
        db.session.add(mail_activation)
        db.session.commit()

        result, message = send_email(
            'Framgia Level Checker - Resend Confirmation',
            app.config['MAIL_SENDERS']['admin'],
            [user.email],
            'confirm_activation',
            dict(token=mail_activation.token)
        )
        if not result:
            form.email.errors.append('Error: ' + message)
        else:
            flash('Confirmation mail resent.', category='success')

            return render_template('user/confirm_mail_sent.html', user=user)

    return render_template('user/confirm_mail_resend.html', form=form)
Exemplo n.º 3
0
def forgot_password():
    form = SendForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        user_forgot_password = UserForgotPassword.query.filter_by(user_id=user.id).first()
        if not user_forgot_password:
            user_forgot_password = UserForgotPassword(user)
        else:
            user_forgot_password.refresh()
        db.session.add(user_forgot_password)
        db.session.commit()

        token = user_forgot_password.token.encode('base64').strip().replace('=', '_')
        result, message = send_email(
            'Framgia Level Checker - Reset Password',
            app.config['MAIL_SENDERS']['admin'],
            [user.email],
            'reset_password',
            dict(token=token)
        )
        if not result:
            form.email.errors.append('Error: ' + message)
        else:
            flash('Reset password mail sent.', category='success')
            return render_template('user/reset_password_sent.html', user=user)

    return render_template('user/forgot_password.html', form=form)
Exemplo n.º 4
0
def forgot_password():
    form = SendForgotPasswordForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user.reset_password_token:
            user.refresh_password_token()
        token = user.reset_password_token.encode('base64').strip().replace(
            '=', '_')
        send_email('Framgia Code Contest - Reset Password',
                   app.config['MAIL_SENDERS']['admin'], [user.email],
                   'reset_password', dict(token=token))
        flash('Reset password email sent !', category='success')
        user.log_sent_password_token()
        db.session.add(user)
        db.session.commit()

        return render_template('user/reset_password_sent.html', user=user)

    return render_template('user/forgot_password.html', form=form)
Exemplo n.º 5
0
def forgot_password():
    form = SendForgotPasswordForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user.reset_password_token:
            user.refresh_password_token()
        token = user.reset_password_token.encode('base64').strip().replace('=', '_')
        send_email(
            'Framgia Code Contest - Reset Password',
            app.config['MAIL_SENDERS']['admin'],
            [user.email],
            'reset_password',
            dict(token=token)
        )
        flash('Reset password email sent !', category='success')
        user.log_sent_password_token()
        db.session.add(user)
        db.session.commit()

        return render_template('user/reset_password_sent.html', user=user)

    return render_template('user/forgot_password.html', form=form)