An agile development practice of amateur project

Time:2020-4-2

This time, a user login permission control module is added to the original apitemplate project to verify how to abstract and support future expansion when facing some simple problems. The user login authority control module looks very simple, but its spare time is always limited. So take advantage of this opportunity to practice a user agile development. First of all, split the module. This time, only user login and logout are realized.

Apitemplate project address: https://github.com/cqhaibin/apitemplate

1、 Summary put forward

Minimize task scope

  • This task is only limited to the task of “user name + password login”, and does not contain data persistence. In this way, you can check yourself repeatedly and do not let yourself go beyond the scope. therefore
  • Query user registration information, online user storage interface only for definition and simulation implementation, not for specific storage implementation
  • Considering that the business logic is stable and the storage is variable, the database entity object is separated from the business entity object

Give the task a deadline

For example, this time, only the deadline of the task is listed, but not the deadline of each sub stage. For example, a requirement must go through the stages of requirement analysis, module design, code implementation, etc. Specific deadlines are also required for these sub phases.

Step by step from the outside to the inside

  • Define UI / service layer interface
    Because there are many ways to provide UI interface (such as rest API, RPC, etc.), the service layer interface is basically the standard, and UI interface layer only makes a simple transformation and call. The moddel of input / output parameters of UI / service layer interface is also defined (shared model of two layers)
  • Implement service layer interface
    This step implements the service layer interface. You will find that you need to rely on the online user management module and the database layer (query registered user information). Here I only define the interface to query registered user information, but I will not do the specific implementation temporarily. Then go to step three
  • Define the interface of the online user module
    This step includes: online user management entity interface, online user entity interface. Defined before not implemented. Improve the dependency call of this module in the service layer implementation. Here you may repeatedly adjust the model of the method input / output parameters of the online user module to achieve the integration with the service layer
  • Realize the interface of online user module
    This step realizes online user management entity interface and online user entity interface. At this point, we find that we also need to rely on the online user storage interface (only defined, not implemented)

2、 User requirements

Implement the login and logout interface according to the user name.

3、 Demand analysis

  • User name: English, number, Chinese character and special characters are supported; user name is not case sensitive
  • Password: English, number, special character, case sensitive
  • Prompt: user does not exist and password error should be distinguished
  • Data persistence is not considered at this stage, because the feasibility of the prototype needs to be verified quickly

4、 System design

interface design

The rest API is used to implement two interfaces: login and logout

  • Login interface
    • Interface name: postlogin
    • Request type: Post
    • input parameter
{
    Username, // username
    Password // password
}
  • Return parameter
{
    Issuccess, // whether the request succeeds
    Resultcode, // request status code 200006: account does not exist; 200001: account is disabled; 200002: password error
    data:{
        Token // the token returned after login succeeds
        User: {// user object
            RealName, // user name
            Username, // login
            ID, // user ID
            Config, // user extension information, JSON string
            Mobilephone, // phone number
        }
    }
}
  • Logout interface
    • Interface name: loginout
    • Request type: get
    • input parameter
      Get token through URL, header and cookie
    • Return parameter
  • {
        Issuccess, // whether the request succeeds
        Resultcode, // request status code
    }

    detailed design

    Login interface detailed design

    • Technological process
      image
    • Online user management
      • Online user management interface class
      class IOnlineUserMgr{
          /// 
          ///Add users to the online user list. This method needs to persist the login information
          /// 
          /// 
          void Add(IUserEntity entity);
          /// 
          ///According to the token to remove the corresponding user, this method needs to persist the logout information
          /// 
          /// 
          /// 
          bool Remove(string token);
          /// 
          ///To remove a user according to the user ID, this method needs to persist the logout information
          /// 
          /// 
          /// 
          bool Remove(int id);
          /// 
          ///Restoring online users from the persistence layer
          /// 
          void Load();
          /// 
          ///Get all online users
          /// 
          IList  GetAll();
      
          IUserEntity Get(int userId);
      }
      • User entity interface class
      class IUserEntity{
          UserInfo UserInfo { get; }
      
          string Token { get; }
      
          /// 
          ///Client information
          /// 
          RequestClientInfo ClientInfo { get; }
      
          DateTime LoginTime { get; }
      
          DateTime ExpiredTime { get; }
          /// 
          ///User login configuration
          /// 
          UserAuthOption Option { get; }
      
          TokenEntity GetTokenEntity();
      }
    • Explain
      • Token generation rules
        User key = token ﹣ userid ﹣ username ﹣ IP ﹣ OS ﹣ time, and then take the value calculated by user key through MD5 as token
      • UAParser
        Implement the conversion of useragent string to object.

    Detailed design of logout interface

    • Technological process

    image

    5、 Data dictionary

    • Online user information

    image

    • user

    image

    Recommended Today

    Python basics Chinese series tutorial · translation completed

    Original: Python basics Python tutorial Protocol: CC by-nc-sa 4.0 Welcome anyone to participate and improve: a person can go very fast, but a group of people can go further. Online reading Apache CN learning resources catalog introduce Seven reasons to learn Python Why Python is great Learn Python introduction Executing Python scripts variable character string […]