Example #1
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.current_password.data):
            current_user.password = form.new_password.data
            db_session.add(current_user)
            db_session.commit()
            flash(_('Password changed'), 'success')
            return redirect(url_for('main.account'))
        else:
            flash(_('Current password is invalid!'), 'error')
    display_errors_with_flash(form)
    return render_template('password_change.html', form=form)
Example #2
0
def reset_password(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        if User.reset_password(token, form.password.data):
            db_session.commit()
            flash(_('Your password has been updated'), 'success')
            return redirect(url_for('main.index'))
        else:
            flash(_('The reset link is invalid or has expired'), 'warning')
            return redirect(url_for('main.index'))
    display_errors_with_flash(form)
    return render_template('password_reset.html', form=form)
Example #3
0
def reset_password_request():
    form = ResetPasswordEmailForm()
    if form.validate_on_submit():
        user = db_session.query(User).filter_by(email=form.email.data).first()
        if user is not None:
            token = user.generate_reset_token()
            send_email(user.email,
                       _('Reset Password'),
                       'reset_password',
                       token=token)
            flash(_('Email with instructions to reset password was sent'),
                  'success')
            return redirect(url_for('auth.login'))
        else:
            flash(_('This email address is not registered!'), 'error')
    display_errors_with_flash(form)
    return render_template('password_reset_request.html', form=form)
Example #4
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data.lower(), password=form.password.data)
        db_session.add(user)
        db_session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email,
                   _('Account Confirmation'),
                   'confirmation',
                   token=token)
        flash(_('Register success! Please confirm your email before logging'),
              'success')

        if add_anonymous_pack_to_user(user):
            flash(_('Pack was added to your account!'), 'success')

        return redirect(url_for('auth.login'))
    display_errors_with_flash(form)
    return render_template('register.html', form=form)
Example #5
0
def contact():
    form = ContactForm()

    if form.validate_on_submit():
        message = Message(sender=form.email.data,
                          topic=form.topic.data,
                          content=form.content.data,
                          language=str(get_locale()))
        db_session.add(message)
        db_session.commit()

        send_email(config.MAIL_USERNAME, _('Message'), 'contact', form=form)
        flash(_('Message was sent'), 'success')
        return redirect(url_for('main.contact'))

    if current_user.is_authenticated:
        form.email.data = current_user.email

    display_errors_with_flash(form)
    return render_template('contact.html', form=form)
Example #6
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        user = db_session.query(User).filter_by(email=form.email.data).first()

        # Niepotwierdzony mail
        if user is not None and not user.confirmed:
            url = url_for('auth.resend', email=form.email.data)
            flash(
                _('Please confirm this email first! Click %(start)shere%(end)s to resend confirmation',
                  start='<a href="%s">' % url,
                  end='</a>'), 'warning')
            return render_template('login.html', form=form)

        # Poprawne logowanie
        if user is not None and user.verify_password(form.password.data):
            login_user(user, remember=form.remember_me.data)

            if add_anonymous_pack_to_user(user):
                flash(_('Pack was added to your account!'), 'success')

            next = request.args.get('next')
            if next is None or not next.startswith('/'):
                if user.is_admin():
                    next = url_for('admin.panel')
                else:
                    next = url_for('main.account')
            return redirect(next)

        # Niepoprawne dane do logowania
        flash(_('Invalid login or password'), 'error')
        return render_template('login.html', form=form)

    # Wyƛwietlenie formularza
    display_errors_with_flash(form)
    return render_template('login.html', form=form)