A method of controlling login authority

By configuring permission roles and time periods, and combining localStorage, sessionStorage, and cookies, the Token storage method is automatically controlled, solving the problem of poor user login status in the browser, achieving flexible login permission control, and improving user experience.

CN114117369BActive Publication Date: 2025-10-21SHANGHAI EASY SCHOOL INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111208367.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-18
Publication Date
2025-10-21
Estimated Expiration
2041-10-18

AI Technical Summary

Technical Problem

In the front-end and back-end separation mode, different storage methods in the browser lead to a poor user login experience, especially when multiple people share a computer. LocalStorage, sessionStorage and cookies cannot meet the needs of different users.

Method used

By configuring different permission roles and time periods, and combining localStorage, sessionStorage, and cookies, it automatically determines and controls the storage method of Tokens to achieve flexible login permission control.

Benefits of technology

It improves the user experience and allows users to choose the appropriate storage method according to their needs, meeting the login needs of different users in scenarios where multiple people share a computer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114117369B_ABST
    Figure CN114117369B_ABST
Patent Text Reader

Abstract

The application provides a method for controlling login permission. Its features are that: the first level permission, the second level permission and the third level permission roles are configured in the system; the Token storage mode corresponding to the permission is configured in the system; the Token storage mode of different permission roles in different time periods is configured in the system; the first level permission role or the second level permission role decides whether to open the custom storage mode; if the custom storage mode is not opened, the system adopts the default Token storage mode; if the custom storage mode is opened, the system automatically judges the current role permission and controls the login permission according to the Token storage mode corresponding to the current time period of the permission role. The beneficial effects of the application are that: three modes are provided for the storage of the user login state, and the user can select the mode according to the needs, thereby improving the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of user login status authority control, and in particular to a method for controlling login authority. Background Art

[0002] In today's era of rapid internet development, the front-end and back-end separation model has become the preferred development model for most IT companies. This model allows different departments to be responsible for their respective areas, significantly improving development efficiency. With the continued development of this separation model, a new method for storing user login status has emerged: tokens.

[0003] A token is a string of characters generated by the server that serves as a token for client requests. After the first login, the server generates a token and returns it to the client. In the future, the client only needs to bring this token to request data without having to bring the username and password again.

[0004] At present, in some companies, there are situations where several computers are shared in one workshop. Therefore, when different employees use the same computer, storing these different login information becomes a big problem.

[0005] There are generally three places in the browser that can be used to store tokens, one is localStorage (local storage), one is sessionStorage (session storage), and the last one is cookies (data stored on the user's local terminal).

[0006] LocalStorage and cookies generally do not disappear even if the browser is closed, but sessionStorage will disappear when the browser or tab is closed.

[0007] If stored in localStorage or cookies, since it will be permanently saved in the browser, every time you close a tab and reopen it, you will still be the original user and will need to log out before logging into another user's account, resulting in a poor user experience. However, if it is stored in sessionStorage, although each new tab is opened is brand new, if the user wants to open multiple tabs and only log in after closing their own tab, this requirement cannot be met. Summary of the Invention

[0008] In order to solve the above technical problems, the present invention discloses a method for controlling login permissions. The technical solution of the present invention is implemented as follows:

[0009] A method for controlling login permissions includes the following steps:

[0010] Configure level 1, level 2, and level 3 roles within the system;

[0011] Configure the token storage method corresponding to the permissions in the system;

[0012] Configure the token storage method for different permission roles in different time periods within the system;

[0013] The first-level or second-level permission role determines whether to enable custom storage mode;

[0014] If custom storage is not enabled, the system uses the default Token storage method;

[0015] If the custom storage method is enabled, the system automatically determines the current role permissions and controls login permissions based on the Token storage method corresponding to the current time period of the permission role.

[0016] Preferably, the storage methods include localStorage, sessionStorage and cookies.

[0017] Preferably, the third-level authority role follows the configuration of the first-level authority role or the second-level authority role.

[0018] Preferably, the first-level authority role can be added with a second-level authority role.

[0019] Preferably, the first-level authority role and the second-level authority role can modify the token storage method of different authority roles in different time periods.

[0020] Preferably, the default storage method is cookies.

[0021] Preferably, the time period includes work and off-get off work.

[0022] Preferably, the specific steps of permission login control are as follows:

[0023] User opens a tab and logs in;

[0024] The system determines the permissions of the current login role;

[0025] Determine the Token storage method corresponding to the current role permissions in the current time period and call it;

[0026] If the current Token storage method is sessionStorage, start role monitoring;

[0027] When a user opens a new tab, the role listener detects whether the previous tab is closed. If not, the role listener calls the token of the previous tab to the current tab.

[0028] The implementation of the technical solution of the present invention can solve the technical problem in the existing technology that whether it is localStorage, sessionStorage or cookies, it will cause poor user experience; the implementation of the technical solution of the present invention can enable users to flexibly control role login permissions by setting different permission roles, different time periods, and corresponding different modes of storing role login information, thereby improving the technical effect of user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only one embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0030] Identical components are denoted by the same reference numerals. It should be noted that the terms "front," "rear," "left," "right," "upper," and "lower" used in the following description refer to directions in the accompanying drawings, and the terms "bottom," "top," "inner," and "outer" refer to directions toward or away from the geometric center of a particular component, respectively.

[0031] Figure 1 A flowchart of role assignment for an embodiment;

[0032] Figure 2 This is a role login flow chart of an embodiment;

[0033] Figure 3 This is a flowchart of role monitoring in an embodiment. DETAILED DESCRIPTION

[0034] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0035] Example

[0036] In a specific embodiment, Figure 1 、 Figure 2 and Figure 3As shown, a method for controlling login permissions includes the following steps:

[0037] The system configures level 1, level 2, and level 3 roles. In this embodiment, the level 1 role is the super administrator, the level 2 role is the sub-administrator, and the level 3 role is the ordinary user. The super administrator can add sub-administrators.

[0038] Configure the corresponding permission token storage method in the system; the token storage method in this embodiment is sessionStorage and cookies;

[0039] The system configures the token storage method for different permission roles in different time periods; the time periods in this embodiment are divided into working hours and off-duty hours.

[0040] Super administrators and sub-administrators have the right to enable time management storage and custom storage, while ordinary members will follow the administrator's configuration;

[0041] If custom storage is not enabled, the system uses the default Token storage method; in this embodiment, the default Token storage method is cookie.

[0042] If the custom storage method is enabled, the system automatically determines the current role permissions and controls login permissions based on the Token storage method corresponding to the current time period of the permission role.

[0043] The specific steps for permission login control are as follows:

[0044] User opens a tab and logs in;

[0045] The system determines the permissions of the current login role;

[0046] Determine the Token storage method corresponding to the current role permissions in the current time period and call it;

[0047] If the current Token storage method is sessionStorage, start role monitoring;

[0048] When a user opens a new tab, the role listener detects whether the previous tab is closed. If not, the role listener calls the token of the previous tab to the current tab.

[0049] Next, this embodiment will be described in detail.

[0050] First, create three roles in the system: super administrator, sub-administrator, and regular member. Super administrators can add multiple sub-administrators. Both super administrators and sub-administrators have the right to enable time management storage and custom storage, while regular members will follow the administrator's configuration.

[0051] Since employees usually log into their computers during working hours, and only on-duty personnel use computers during non-working hours, if the administrator enables time-based storage management, the system will switch storage methods according to different time periods.

[0052] The default working hours are 9:00 AM to 6:00 PM. Calling new Date().getHours() and new Date().getMinutes() retrieves the current hour and minute. When a user logs in, the system checks whether they fall within this time period. If the user's login status continues from working hours to non-working hours, the storage method is automatically switched.

[0053] If the time period is exceeded, the current Token storage method will be queried first. For example, if sessionStorage storage is selected during working hours and cookie storage is selected during non-working hours, then during non-working hours, the information stored in sessionStorage will be automatically deleted and stored in the cookie.

[0054] After the administrator configures custom storage, they can choose how to store tokens. Generally, if localStorage or cookies are selected, the browser will save the login status, and users will not need to log in after closing and reopening the browser. This scenario is more suitable for managers, as managers and supervisors usually have their own computers and do not need to log in every time.

[0055] When the administrator selects sessionStorage storage, we first optimize the sessionStorage storage token. If sessionStorage is used directly, each new tab opening requires a new login. While this is suitable for multiple employees sharing the same computer, if an employee needs to open multiple tabs to perform operations, they will need to log in again each time they open a new tab, which provides a poor user experience. Therefore, the best solution is to automatically log in when a user is already logged in. If you want to switch to another user, close all tabs that belong to that user. The next new tab you open will be in a non-logged-in state.

[0056] To implement this type of sessionStorage storage, we must use a storage event provided by the browser's top-level window object. First, let's understand what an event is. An event is an action or interaction that occurs in the browser. It can be triggered by the user, such as a click event, or by the browser itself, such as a load event, which is triggered when a resource is loaded. Therefore, we can listen for this storage event in different tabs. When a tab triggers this event, other tabs can also listen for the triggering of this event.

[0057] Each time a new tab is opened, it checks to see if the session storage has a token. If not, it triggers a storage event using the localStorage.setItem method. If a previously logged-in tab is already logged in, it will listen for this trigger and then trigger the localStorage.setItem method again, this time with the currently logged-in token. The new tab also listens for the storage event and receives the passed token, which it then stores in the new tab.

[0058] In summary, this embodiment provides three methods for storing user login status, allowing users to choose the method they need. This solves the technical issue of poor user experience resulting from using localStorage, sessionStorage, or cookies. By setting different permission roles, time periods, and corresponding modes for storing role login information, users can flexibly control role login permissions, thereby improving the user experience.

[0059] It should be pointed out that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for controlling login permissions, characterized by: The steps are as follows: Configure level 1, level 2, and level 3 roles within the system; Configure the corresponding permission token storage method in the system, including localStorage, sessionStorage and cookies; Configure the token storage method for different permission roles in different time periods in the system; the time periods include working and leaving get off work; If the user's login status continues from working hours to non-working hours, the current token storage method will be queried first, and the token storage method will be automatically switched according to the current setting. The first-level or second-level permission role determines whether to enable custom storage mode; If custom storage is not enabled, the system uses the default Token storage method; If the custom storage method is enabled, the system automatically determines the current role permissions and controls login permissions based on the token storage method corresponding to the current time period of the permission role. The specific steps for permission login control are as follows: User opens a tab and logs in; The system determines the permissions of the current login role; Determine the Token storage method corresponding to the current role permissions in the current time period and call it; If the current Token storage method is sessionStorage, start role monitoring; When a user opens a new tab, the role listener detects whether the previous tab is closed. If not, the role listener calls the token of the previous tab to the current tab.

2. A method for controlling login permissions according to claim 1, characterized in that: The third-level permission role follows the configuration of the first-level permission role or the second-level permission role.

3. A method for controlling login permissions according to claim 2, characterized in that: The first-level authority role can add a second-level authority role.

4. A method for controlling login permissions according to claim 3, characterized in that: The first-level authority role and the second-level authority role can modify the token storage method of different authority roles in different time periods.

5. A method for controlling login authority according to claim 4, characterized in that: The default storage method is cookies.

Citation Information

Patent Citations

  • Single sign-on method for protecting enterprise information assets

    CN111245795A

  • Authentication processing method for multiple application systems under same main domain name

    CN113014588A