BlackHorse Rating Login Design

SMS Verification Code Login
- User enters phone number on login page and clicks “Get Code”. Backend validates phone format, generates a verification code, stores phone:code in Redis with 2-minute expiry.
- User enters code and clicks “Login”. Backend compares submitted code with stored value.
- If user doesn’t exist, create and save to database.
- Generate random token as login credential; convert User object to Hash and store as token:userHash in Redis.
Login Status Validation
- Requests carry token in header. RefreshTokenInterceptor intercepts all requests (passes through if no token).
- Extract token from header, retrieve user Map from Redis using token.
- If user exists, convert Map to UserDTO, store in ThreadLocal, and refresh token expiry.
LoginInterceptor intercepts all paths except specified public ones. If UserHolder is empty (not logged in), request is rejected.
UserHolder
Each ThreadLocal stores one object per thread. ThreadLocal instances are stored in the thread’s private ThreadLocalMap.
| |
After a request requiring login completes, loginInterceptor’s afterCompletion method removes the user from UserHolder.