[英]How server-side controllers handle multiple sessions from client?
I come from a JavaScript background and I'm recently learning the server-side. 我来自JavaScript背景,最近正在学习服务器端。 I am under the impression that the controllers in the server-side is a 1 to many ratio in terms of interacting with the client side. 我的印象是,服务器端的控制器与客户端的交互比例为1:1。
And I have this code for logging in: 我有以下代码可用于登录:
@expose('/login/', methods=('GET', 'POST'))
def login_view(self):
if request.method == 'GET':
# Render template
if request.method == 'POST':
# Take email and password from form and check if
# user exists. If he does, log him in.
login.login_user(user)
# Store user_id in session for socketio use
session['user_id'] = login.current_user.id
# Redirect
I understand that the session dictionary is like the localStorage counterpart of JavaScript, so does this mean that there is a unique controller for every unique client? 我知道会话字典就像JavaScript的localStorage一样,这是否意味着每个唯一客户端都有一个唯一控制器? because then multiple clients would overwrite the session.user_id if they shared the same controller right? 因为如果多个客户端共享相同的控制器,那么它们将覆盖session.user_id吗?
Session is created the state is maintained at the client side (in a cookie) after a user has been authenticated. 创建会话后,在对用户进行身份验证后,将在客户端(以cookie形式)维护状态。
So when a user logs in, with a email and password, the server will identify (doing some checking with valid email and password stored in database). 因此,当用户使用电子邮件和密码登录时,服务器将识别(使用存储在数据库中的有效电子邮件和密码进行一些检查)。 The server can now set the cookie with a token( and possible expiry time) in the response. 服务器现在可以在响应中使用令牌(和可能的到期时间)设置cookie。 After that, HTTP request from that particular client will have a token, which will be used by server to identify the user. 之后,来自该特定客户端的HTTP请求将具有一个令牌,服务器将使用该令牌来标识用户。
Basically, every session is maintained at client side and controller check for validity at the server side. 基本上,每个会话都在客户端维护,控制器在服务器端检查有效性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.