如果 @login_required 与我在烧瓶上的 IP 匹配,则绕过它

时间:2021-03-09 17:17:31

标签: python authentication flask flask-login

寻求帮助我一直在绞尽脑汁让这个工作,经过大量阅读研究后,我不确定我制作烧瓶的方式是否可行

我需要的是一种在找到我的 ip 时绕过登录的方法

@app.route("/account")
@login_required
def account():
    return render_template('account.html', title='Account')
if request.remote_addr == '127.0.0.1': 

以上我都试过了 app.config['LOGIN_DISABLED'] = True 我已将此应用于登录

我还在 #!/usr/bin/perl use strict; use warnings; open my $in, '<', 'first5.txt' or die $!; open my $out, '>', 'first5.new' or die $!; while (<$in>) { chomp; my @columns = split /\t/; ++$columns[1]; print {$out} join "\t", @columns; print {$out} "\n"; } close $out; rename 'first5.new', 'first5.txt' or die $!; 上添加了一个案例,但这改变了整体,因此安全性不起作用

我的主要问题是如何绕过@login_required

pip flask_login 不是最好的方法

如果有人能指出我正确的方向,那就太好了

2 个答案:

答案 0 :(得分:0)

在用户模型部分添加IP部分,使用数据库存储所有用户的IP地址。您可以在数据库中找到您的 IP 地址,然后尝试授予该当前用户的访问权限,尝试“if user.ip == 192.168.0.x”重定向到主页。

答案 1 :(得分:0)

感谢爱立信

工作解决方案

try and except 确实需要清理,但希望这可以帮助其他人

@app.route("/login", methods=['GET', 'POST'])
def login():
    if current_user.is_authenticated:
        print('is_authenticated')
        return redirect('home')
    form = LoginForm()
    if current_user.is_authenticated == False:
        try:
            print(request.remote_addr)
            user = User.query.filter_by(ip=request.remote_addr).first()
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect('home')
        except:
            ''
    if form.validate_on_submit():
        print(ip)
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect('home')
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')
    return render_template('login.html', title='Login', form=form)
相关问题