示例#1
0
def login():
    """Public login view"""

    if current_user.is_authenticated:
        return redirect(url_for("main.index"))

    form = LoginForm()

    if request.method == "POST" and form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user is None or not user.verify_pass(form.password.data):
            flash("Invalid username or password")
            return redirect(url_for("auth.login"))
        elif not user.active:
            flash("You're banned!")
            return redirect(url_for("auth.login"))

        login_user(user, remember=True)

        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("auth/login.html", title="Sign In", form=form)
示例#2
0
文件: views.py 项目: jh-lau/Flasky
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('Invalid username or password')
    return render_template('auth/login.html', form=form)
def login():
    form = LoginForm()
    next_page = request.args.get('next', '/')
    form_error_message = None
    if request.method == 'POST' and form.validate_on_submit():
        user = check_user(form.data['username'], form.data['password'])
        if user:
            session['user_id'] = user['id']
            session['loginned'] = True
            return redirect(next_page)
        else:
            form_error_message = 'User Not Found'
    context = {'form': form, 'form_error_message': form_error_message}
    return render_template('auth/login.html', **context)
示例#4
0
文件: views.py 项目: computmaxer/blog
    def post(self):
        form = LoginForm(request.form)

        if form.validate():

            try:
                user = User.objects.get(username=form.username.data)
            except DoesNotExist, e:
                user = None

            if user and user.check_password(form.password.data):
                flask_login.login_user(user)
                return redirect(url_for("admin.index"))

            flash("Invalid Username or Password")
示例#5
0
def login():
    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('auth.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('auth/login.html', title='Sign In', form=form)
示例#6
0
def sign_in():
    forms = LoginForm()
    next_page = request.args.get('next', '/')
    if request.method == 'POST' and forms.validate_on_submit():
        user = User.query.filter_by(username=forms.username.data).first()
        if user and user.check_password(forms.password.data):
            login_user(user)
            flash('Logged in succesfully.')
            return redirect(next_page)
        else:
            flash('User not found.')
    context = {
        'forms': forms,
    }
    return render_template('auth/sign.html', **context)
示例#7
0
def login_page():
    if current_user.is_authenticated:
        return redirect(url_for('home.homepage'))

    form = LoginForm()
    if form.validate_on_submit():
        user = UserModel.query.filter_by(email=form.email.data).first()
        if user and user.verify_password(form.password.data):
            login_user(user, remember=form.remember_me.data)
            next_url = request.args.get('next')
            return redirect(next_url) if next_url else redirect(
                url_for('home.homepage'))

        flash("Login unsuccessful. Please check your email and password",
              'danger')
    return render_template('auth/login.html', title="Login", form=form)
示例#8
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.blog'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            # login_user takes user and remember as arg
            login_user(user, remember=form.remember.data)
            flash('You have been logged in.', 'success')
            next_page = request.args.get('next')
            return redirect(
                url_for('auth.account')) if next_page else redirect(
                    url_for('main.blog'))
        else:
            flash('Login Unsucessful. Please check email and password',
                  'danger')
    return render_template('auth/login.html', form=form)