Exemplo n.º 1
0
def login():
    form = LoginForm(next=request.args.get('next'))

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

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

            print(" YOU MADE IT")
            login_user(u)

            #handle optional redirecting
            next_url = request.form.get('next')

            print(next_url)

            #caution checking path of url
            if next_url:
                return redirect(safe_next_url(next_url))

            return redirect(url_for('core.index'))

        else:
            flash("Email or password is incorrect.", "warning")
            print("error")

    return render_template('users/login.html', form=form)
Exemplo n.º 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 u.is_active() and login_user(u, remember=True):
                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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def login():
    form = LoginForm(next=request.args.get('next'))
    if form.validate_on_submit():
        u = Usuarios.find_by_identity(request.form.get('identidad'))
        if u and u.authenticated(password=request.form.get('contrasena')):
            if login_user(u, remember=True) and u.is_active():
                next_url = request.form.get('next')
                if next_url:
                    return redirect(safe_next_url(next_url))
                return redirect(url_for('sistemas.inicio'))
            else:
                flash(u'Esta cuenta está inactiva', 'error')
        else:
            flash(u'Usuario o contraseña incorrectos.', 'error')
    return render_template('usuarios/login.html', form=form)
Exemplo n.º 5
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')):

            if login_user(u, remember=request.form.get('remember_me')) and u.is_active():
                next_url = request.form.get('next')
                print(">>redirect next_url: {}".format(next_url))
                if next_url:
                    return redirect(safe_next_url(next_url))
                return redirect(url_for('admin.index'))
            else:
                flash('This account has been disabled.', 'error')
        else:
            flash('Identity or password is incorrect.', 'error')

    return render_template('user/login.html', form=form)
Exemplo n.º 6
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')):

            if login_user(u, remember=request.form.get(
                    'remember_me')) and u.is_active():
                next_url = request.form.get('next')
                print(">>redirect next_url: {}".format(next_url))
                if next_url:
                    return redirect(safe_next_url(next_url))
                return redirect(url_for('admin.index'))
            else:
                flash('This account has been disabled.', 'error')
        else:
            flash('Identity or password is incorrect.', 'error')

    return render_template('user/login.html', form=form)
Exemplo n.º 7
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')):
            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.', 'danger')
        else:
            flash('Identity or password is incorrect.', 'danger')

    return render_template('user/login.html', form=form)
Exemplo n.º 8
0
def login():
    form = LoginForm(next=request.args.get('next'))

    if form.validate_on_submit():

        try:
            u = User.objects.get(email=request.form.get('identity'))
        except User.DoesNotExist:
            u = None

        if u and u.authenticated(False, request.form.get('password')):
            if login_user(u, remember=True):
                #  u.update_activity_tracking(request.remote_addr)

                next_url = request.form.get('next')
                if next_url:
                    return redirect(safe_next_url(next_url))
                #  return redirect(url_for('user.settings'))
                return redirect("/")
        else:
            flash('Identity or password is incorect.', 'error')

    return render_template('user/login.html', form=form)
Exemplo n.º 9
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)