示例#1
0
文件: views.py 项目: mulnz/flask-blog
def login_view():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = load_user(form.data['shortname'])
        login_user(user)
        return redirect(url_for('index_view'))
    return render_template_with_models('login.html', form=form)
示例#2
0
def login_view():
    """
    Renders a login page and redirects to the index on completion
    """
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = get_user(form.data['shortname'])
        login_user(user)
        return redirect(url_for('admin.index'))
    return render_template_with_models('login.html', form=form)
示例#3
0
def login_view():
    """
    Renders a login page and redirects to the index on completion
    """
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = get_user(form.data['shortname'])
        login_user(user)
        return redirect(url_for('admin.index'))
    return render_template_with_models('login.html', form=form)
示例#4
0
def login():
    ''' Wraps flask-login's login method. '''
    form = LoginForm(request.form)
    if request.method == 'POST':
        if not form.validate():
            flash('Invalid login information. Please try again.')
        else:
            email, password = request.form['email'], request.form['password']
            if not User_.objects(email=email, password=password):
                flash("Incorrect credentials. Please try again.")
            else:
                admin = User(form.email.data, form.password.data)
                login_user(admin)
                return redirect(url_for('posts.admin'))
    return render_template('login.html', form=form)
示例#5
0
def login():
	''' Wraps flask-login's login method. '''
	form = LoginForm(request.form)
	if request.method == 'POST':
		if not form.validate():
			flash('Invalid login information. Please try again.')
		else:
			email, password = request.form['email'], request.form['password']
			if not User_.objects(email=email, password=password):
				flash("Incorrect credentials. Please try again.")
			else:
				admin = User(form.email.data, form.password.data)
				login_user(admin)
				return redirect(url_for('posts.admin'))
	return render_template('login.html', form=form)
示例#6
0
def login():
    err = ''
    status = 200
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = mongo.db.users.find_one({'username': form.username.data})
        if user and check_password_hash(user["password"], form.password.data):
            session["username"] = user["username"]
            session["authenticated"] = True
            session["isAdmin"] = user["admin"] if 'admin' in user else None
            return redirect(form.redirect.data)
        else:
            err = "Invalid username or password"
    
    if err:
        status = 401

    redirect_url = request.args.get('redirect', '/')
    return make_response(render_template('login.html', err=err, redirect=redirect_url), status)