Beispiel #1
0
def login():
    form = LoginForm(next=request.args.get('next'))

    if form.validate_on_submit():
        u = User.find_by_identity(request.form.get('identity'))

        if u and u.authenicate_password(password=request.form.get('password')):
            # As you can see remember me is always enabled, this was a design
            # decision I made because more often than not users want this
            # enabled. This allows for a less complicated login form.
            #
            # If however you want them to be able to select whether or not they
            # should remain logged in then perform the following 3 steps:
            # 1) Replace 'True' below with: request.form.get('remember', False)
            # 2) Uncomment the 'remember' field in user/forms.py#LoginForm
            # 3) Add a checkbox to the login form with the id/name 'remember'

            if login_user(u, remember=True) and u.is_active:
                u.update_activity_tracking(request.remote_addr)

                # Handle optionally redirecting to the next URL safely.
                next_url = request.form.get('next')
                if next_url:
                    return redirect(safe_next_url(next_url))

                return redirect(url_for('user.settings'))
            else:
                flash('This account has been disabled.', 'error')
        else:
            flash('Identity or password is incorrect.', 'error')

    return render_template('user/login.html', form=form)
Beispiel #2
0
def login():

    form = LoginForm(next=request.args.get('next'))

    if form.validate_on_submit():
        u = User.find_by_identity(request.form.get('identity'))

        if u and u.authenticated(password=request.form.get('password')):
            # As you can see remember me is always enabled, this was a design
            # decision I made because more often than not users want this
            # enabled. This allows for a less complicated login form.
            #
            # If however you want them to be able to select whether or not they
            # should remain logged in then perform the following 3 steps:
            # 1) Replace 'True' below with: request.form.get('remember', False)
            # 2) Uncomment the 'remember' field in user/forms.py#LoginForm
            # 3) Add a checkbox to the login form with the id/name 'remember'
            if login_user(u, remember=True) and u.is_active():
                u.update_activity_tracking(request.remote_addr)

                # Handle optionally redirecting to the next URL safely.
                next_url = request.form.get('next')
                if next_url:
                    return redirect(safe_next_url(next_url))

                if current_user.role == 'admin':
                    return redirect(url_for('admin.dashboard'))

                if current_user.role == 'member':

                    if not cache.get(current_user.mailbox_id):
                        from app.blueprints.user.tasks import get_emails, get_rules, set_cache

                        emails = get_emails.delay(current_user.mailbox_id)

                        set_cache.delay(current_user.mailbox_id, emails.id)

                    if current_user.trial:
                        trial_days_left = 14 - (
                            datetime.datetime.now() -
                            current_user.created_on.replace(tzinfo=None)).days
                        if trial_days_left < 0:
                            current_user.trial = False
                            current_user.save()

                return redirect(url_for('user.settings'))
            else:
                flash('This account has been disabled.', 'error')
        else:
            flash('Your username/email or password is incorrect.', 'error')

    return render_template('user/login.html', form=form)
Beispiel #3
0
def login():
    ''' Log in a user '''
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('user.login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('main.index')
        return redirect(next_page)
    return render_template('user/login.html', title='Sign In', form=form)
def login():
    if current_user.is_authenticated:
        return redirect(url_for('bp_dashboard.dashboard'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.find_by_username(username=form.username.data)

        if user is None:
            flash('User does not exist.', 'alert alert-danger')
            return redirect(url_for('bp_user.login'))

        # may raise problem if database does not handle binary well
        if user.verify_password(form.password.data):
            login_user(user)
            flash('Welcome, {}!'.format(user.username), 'alert alert-success')
            # safe url check?
            return redirect(url_for('bp_dashboard.dashboard'))
        else:
            flash('Wrong password, please try agin.',
                  'alert alert-danger')
            return redirect(url_for('bp_user.login'))

    return render_template('login.html', form=form)
Beispiel #5
0
def login():
    production = current_app.config.get('PRODUCTION')
    form = LoginForm(next=request.args.get('next'))

    if form.validate_on_submit():
        u = User.find_by_identity(request.form.get('identity'))

        if u and u.is_active() and u.authenticated(password=request.form.get('password')):

            if login_user(u, remember=True) and u.is_active():
                if current_user.role == 'admin':
                    return redirect(url_for('admin.dashboard'))

                u.update_activity_tracking(request.remote_addr)

                next_url = request.form.get('next')

                if next_url == url_for('user.login') or next_url == '' or next_url is None:
                    # Take them to the settings page
                    next_url = url_for('user.calendar')

                if next_url:
                    return redirect(safe_next_url(next_url), code=307)

                if current_user.role == 'admin':
                    return redirect(url_for('admin.dashboard'))
            else:
                flash('This account has been disabled.', 'danger')
        else:
            flash('Your username/email or password is incorrect.', 'danger')

    else:
        if len(form.errors) > 0:
            print(form.errors)

    return render_template('user/login.html', form=form)
Beispiel #6
0
def login():
    form = LoginForm()
    remember = True
    if current_user.is_authenticated:
        return redirect(url_for('user.imoveis'))

    if request.method == "POST":
        if form.validate_on_submit():
            userp = form.senha.data
            usero = form.usuario.data
            user = session.query(Vendedores).filter_by(USUARIO=usero).first()
            users = session.query(
                Vendedores.SENHA).filter_by(USUARIO=usero).first()
            if users:
                users0 = users[0]

            if not user or not sha256_crypt.verify(userp, users0):
                flash('Verifique seus dados e tente novamente.')
                return redirect(url_for('user.login'))
            else:
                login_user(user, remember=remember)
                return redirect(url_for('user.imoveis'))

    return render_template('login.html', form=form)