问题描述
我已经使用flask-login实现了一个工具,用户可以使用其凭据(电子邮件和密码)进行注册和登录,这是我的代码:
@app.route("/login",methods=['GET','POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('index'))
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(user,remember=form.remember.data)
next_page = request.args.get('next')
return redirect(next_page) if next_page else redirect(url_for('index'))
else:
flash('Login Unsuccessful. Please check email and password','danger')
return render_template('login.html',title='Login',form=form)
@app.route("/index")
@login_required
def index():
return render_template('index.html')
我想确保如果用户已经在浏览器(例如Chrome)中登录并从新浏览器(例如Firefox)登录或从新设备登录,则所有其他会话都将被销毁并将其注销,以使用户不再能够与旧页面进行交互。
我想要此功能的原因是:1.我需要存储来自用户提交的一些数据,并且我不想弄乱来自同一用户但不同会话的数据。 2.两个人不能使用相同的凭据登录。
总而言之,实际上每个用户只能通过一个设备和一个浏览器仅提交数据,而同一用户的所有其他用户都应该注销。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)