简体   繁体   English

服务器端控制器如何处理来自客户端的多个会话?

[英]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.

相关问题 在服务器端禁用aspxgridviews,如何在客户端处理? - Disabling aspxgridviews on server-side, how to handle on client-side? 如何识别cookie来自客户端还是服务器端? - how to identify a cookie is from client-side or server-side? 渲染服务器端时如何处理多个相互依赖的sagas? - How to handle multiple interdependent sagas when rendering server-side? 服务器端JavaScript会话 - Server-Side JavaScript Sessions 使用 express 和 mongoose,如何使用 POST 路由将多个 ID 的数组从客户端发送到服务器端? - Using express and mongoose, how do I send an array of multiple IDs from the client-side to server-side using a POST route? 从服务器端到客户端的多个PartialViews异步发送(不确定的延迟) - Sending from server-side to client-side multiple PartialViews asynchronously with an undefined delay 如何处理服务器端模拟的大型数据集 - >客户端浏览器 - How to handle large data sets for server-side simulation --> client browser 从服务器端向客户端发送“消息” - Sending a “message” from server-side to client-side 从服务器端到客户端的密码确认(表单验证) - Password confirmation(form validation) from server-side to client side 从服务器端NodeJ编辑客户端jQuery - Edit client-side jQuery from server-side NodeJs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM