Module: User Center (UCenter)
Relevant source files
The following files were used as context for generating this wiki page:
- zheng-ucenter/zheng-ucenter-dao/src/main/java/com/zheng/ucenter/dao/model/UcenterUser.java
- zheng-ucenter/zheng-ucenter-dao/src/main/java/com/zheng/ucenter/dao/model/UcenterOauth.java
- zheng-ucenter/zheng-ucenter-web/src/main/java/com/zheng/ucenter/web/controller/SignController.java
- project-datamodel/zheng-ucenter.sql
- zheng-ucenter/pom.xml
- project-datamodel/zheng.sql
- zheng-admin/src/index.html
- zheng-upms/zheng-upms-server/src/main/java/com/zheng/upms/server/controller/manage/UpmsUserController.java
The User Center (UCenter) module is a foundational component of the zheng project, designed to serve as a centralized system for user management. Its primary responsibilities include handling user registration, storing core user profile data, managing authentication credentials (both password-based and third-party OAuth), and logging user activities. It is distinct from the zheng-upms (User Permission Management System) module, which focuses on roles, permissions, and organizational structures. UCenter provides the core user identity upon which other systems, like zheng-upms, can build more complex authorization logic.
The main administrative interface identifies this module as "用户管理系统" (User Management System), accessible via the system switcher. This indicates its role as a top-level, user-facing management service within the zheng ecosystem.
Sources: zheng-ucenter/pom.xml, zheng-admin/src/index.html:103, zheng-upms/README.md
Module Architecture
The zheng-ucenter module follows a standard multi-module Maven project structure, which separates concerns into distinct sub-modules. This design promotes maintainability and clear dependency management.
Sources: zheng-ucenter/pom.xml
The following diagram illustrates the sub-modules within zheng-ucenter.
| Module | Description |
|---|---|
zheng-ucenter-common | Contains common classes, constants, and utilities shared across the UCenter module. |
zheng-ucenter-dao | The Data Access Object layer, responsible for database interactions, including MyBatis mappers and data models. |
zheng-ucenter-rpc-api | Defines the Remote Procedure Call (RPC) service interfaces, exposing UCenter's functionality to other modules. |
zheng-ucenter-rpc-service | The implementation of the RPC services defined in the API module. |
zheng-ucenter-web | The web layer, which would typically contain controllers for handling HTTP requests, such as user sign-in and registration. |
Sources: zheng-ucenter/pom.xml:21-27
Database Schema
The database schema for the UCenter module is defined in project-datamodel/zheng-ucenter.sql. It consists of several tables designed to store user information, authentication details, logs, and relationships with third-party services.
Sources: project-datamodel/zheng-ucenter.sql
The Entity-Relationship diagram below shows the relationships between the main tables in the UCenter schema.
ucenter_user Table
This is the primary table for storing core user account information.
| Column | Type | Default | Comment |
|---|---|---|---|
user_id | int unsigned | (auto_increment) | 编号 (Primary Key) |
password | varchar(32) | 密码(MD5(密码+盐)) | |
salt | varchar(32) | 盐 | |
nickname | varchar(20) | 昵称 | |
sex | tinyint(4) | 0 | 性别(0:未知,1:男,2:女) |
avatar | varchar(100) | 头像 | |
create_time | timestamp | CURRENT_TIMESTAMP | 注册时间 |
create_ip | varchar(50) | 注册IP地址 | |
last_login_time | timestamp | 最后登录时间 | |
last_login_ip | varchar(50) | 最后登录IP地址 |
Sources: project-datamodel/zheng-ucenter.sql:19-34
ucenter_user_details Table
This table stores supplementary, non-essential user profile information and is linked to ucenter_user by a one-to-one relationship.
| Column | Type | Comment |
|---|---|---|
user_id | int unsigned | 编号 (Primary Key, Foreign Key to ucenter_user) |
signature | varchar(300) | 个性签名 |
real_name | varchar(20) | 真实姓名 |
birthday | timestamp | 出生日期 |
question | varchar(100) | 帐号安全问题 |
answer | varchar(100) | 帐号安全答案 |
Sources: project-datamodel/zheng-ucenter.sql:39-48
ucenter_oauth Table
This table defines the available third-party authentication providers.
| Column | Type | Comment |
|---|---|---|
oauth_id | int unsigned | 编号 (Primary Key) |
name | varchar(20) | 认证方式名称 |
The system is pre-configured with the following OAuth providers:
oauth_id | name |
|---|---|
| 1 | 手机 (Mobile) |
| 2 | 微信 (WeChat) |
| 3 | |
| 4 | 微博 (Weibo) |
Sources: project-datamodel/zheng-ucenter.sql:10-15, project-datamodel/zheng.sql:390-395
ucenter_user_oauth Table
This table links a user account to one or more third-party authentication methods, storing the user's unique identifier (open_id) from that provider.
| Column | Type | Default | Comment |
|---|---|---|---|
user_oauth_id | int unsigned | (auto_increment) | 编号 (Primary Key) |
user_id | int unsigned | 帐号编号 (Foreign Key to ucenter_user) | |
oauth_id | int unsigned | 认证方式编号 (Foreign Key to ucenter_oauth) | |
open_id | varbinary(50) | 第三方ID | |
status | tinyint(4) unsigned | 绑定状态(0:解绑,1:绑定) | |
create_time | timestamp | CURRENT_TIMESTAMP | 创建时间 |
Sources: project-datamodel/zheng-ucenter.sql:67-77
ucenter_user_log Table
This table is used for logging significant user actions.
| Column | Type | Default | Comment |
|---|---|---|---|
user_log_id | int unsigned | (auto_increment) | 编号 (Primary Key) |
user_id | int unsigned | 用户编号 (Foreign Key to ucenter_user) | |
content | varbinary(100) | 内容 | |
ip | varchar(20) | 操作IP地址 | |
agent | varbinary(200) | 操作环境 | |
create_time | timestamp | CURRENT_TIMESTAMP | 操作时间 |
Sources: project-datamodel/zheng-ucenter.sql:53-62
Core Data Models
The DAO layer contains Java classes that map directly to the database tables. These models are used throughout the application to represent user-related data.
Sources: zheng-ucenter/zheng-ucenter-dao/src/main/java/com/zheng/ucenter/dao/model/UcenterUser.java, zheng-ucenter/zheng-ucenter-dao/src/main/java/com/zheng/ucenter/dao/model/UcenterOauth.java
UcenterUser Class
This class is the Java representation of a record in the ucenter_user table.
| Field | Type | Description |
|---|---|---|
userId | Integer | The unique identifier for the user. |
password | String | The user's hashed password. |
salt | String | The salt used for password hashing. |
nickname | String | The user's display name. |
sex | Byte | Gender (0: Unknown, 1: Male, 2: Female). |
avatar | String | URL to the user's avatar image. |
createTime | Date | Timestamp of registration. |
createIp | String | IP address used during registration. |
lastLoginTime | Date | Timestamp of the last login. |
lastLoginIp | String | IP address of the last login. |
Sources: zheng-ucenter/zheng-ucenter-dao/src/main/java/com/zheng/ucenter/dao/model/UcenterUser.java
Authentication
The UCenter module is designed to handle both local password-based authentication and third-party OAuth integration.
Password-based Authentication
The ucenter_user table contains password and salt fields. The comment 密码(MD5(密码+盐)) indicates that the system uses an MD5 hash of the password concatenated with a salt for security. While MD5 is specified, modern systems typically use stronger hashing algorithms like bcrypt or scrypt.
Sources: project-datamodel/zheng-ucenter.sql:21-22
Third-Party (OAuth) Authentication
The system is architected to support third-party authentication through the ucenter_oauth and ucenter_user_oauth tables. This allows users to sign in using external accounts like WeChat, QQ, or Weibo.
The logical flow for linking an account is as follows:
- A user initiates a login with a third-party provider (e.g., WeChat).
- After successful authentication with the provider, the application receives an
open_id. - The application checks the
ucenter_user_oauthtable for thisopen_id. - If a record exists, the user is logged into the corresponding local
user_id. - If no record exists, the user may be prompted to create a new local account and link it, which creates a new entry in
ucenter_user_oauth.