コード例 #1
0
def login():
    if current_user.is_authenticated:
        flash("Operation already performed", 'info')
        return redirect(url_for('page.home'))

    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        current_app.logger.debug(
            '{0} has tried to log in with ip : {1}'.format(
                form.email.data, request.remote_addr))

        if user is not None and user.verify_password(form.password.data):
            if login_user(user, remember=True) and user.is_active():
                flash('Log in successful', 'success')
                user.track_user_activities(request.remote_addr)
                next_page = request.args.get('next')
                if next_page:
                    return redirect(safe_url(next_page))
                else:
                    return redirect(url_for('page.home'))
            else:
                flash(
                    "Your account has been temporary disable, please visit support for assisstance",
                    'info')
                return redirect(url_for('user.login'))
        elif user is None:
            flash("You need to register in order to access this page", 'info')
        else:
            flash('Incorrect password or email.', 'danger')
    return render_template('user/login.html', form=form)
コード例 #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)
コード例 #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')):
            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)