User Management
Relevant source files
The following files were used as context for generating this wiki page:
- src/main/java/org/example/coding_convention/user/controller/UserController.java
- src/main/java/org/example/coding_convention/user/service/UserService.java
- src/main/java/org/example/coding_convention/user/model/User.java
- src/main/java/org/example/coding_convention/user/model/UserDto.java
- src/main/java/org/example/coding_convention/user/service/OAuth2UserService.java
- src/main/resources/data.sql
- src/main/java/org/example/coding_convention/config/SecurityConfig.java
The User Management system in PhanesEditor handles the lifecycle of user accounts, authentication, and profile management. It supports both local registration with email verification and social login via platforms like Kakao and Google. The system is designed to provide a secure foundation for collaborative features by ensuring that all real-time interactions, such as chatting and code editing, are performed by authenticated and authorized members.
This module integrates Spring Security for authentication, JWT for session management, and AWS S3 for profile image storage. It serves as the primary gateway for users to access the editor's collaborative environment.
Sources: README.md, src/main/java/org/example/coding_convention/user/model/User.java:23-45, src/main/java/org/example/coding_convention/config/SecurityConfig.java:68-80
User Data Model
The core of the system is the User entity, which maps to the users table. It stores identity information, account status, and platform-specific identifiers.
User Entity Schema
| Field | Type | Description |
|---|---|---|
idx | Integer | Primary key, auto-incremented. |
email | String | Unique user email (limit 120 chars). |
nickname | String | User display name (limit 200 chars). |
password | String | Encrypted password for local users. |
platform | Enum | Login source: LOCAL, KAKAO, GOOGLE. |
status | Enum | Account state: ACTIVE, INACTIVE, BANNED. |
enabled | Boolean | Verification status for local accounts. |
profileImg | String | URL to the user's profile image in S3. |
Sources: src/main/java/org/example/coding_convention/user/model/User.java:32-78, src/main/resources/data.sql:40-56
Entity Relationships
The User entity acts as a central hub for various collaborative entities within the system.
The diagram shows how the user is linked to projects as a creator or member, and how they interact via chats and likes.
Sources: src/main/java/org/example/coding_convention/user/model/User.java:82-96, src/main/resources/data.sql:102-140
Authentication & Registration
The system provides two distinct paths for user onboarding: local registration and OAuth2 social login.
Local Registration Flow
Local registration requires a valid email and adherence to password complexity rules (8-20 characters including upper, lower, numbers, and symbols).
- Signup Request: User provides email, password, and nickname.
- Encryption: The password is encoded using
BCryptPasswordEncoder. - Email Dispatch: A verification mail is sent with a unique UUID.
- Verification: The user clicks the link, activating the account (
enabled = true).
This sequence details the asynchronous verification process required for local accounts.
Sources: src/main/java/org/example/coding_convention/user/service/UserService.java:84-118, src/main/java/org/example/coding_convention/user/model/UserDto.java:23-35
OAuth2 Integration
The OAuth2UserService handles social logins by extracting attributes from the provider (e.g., Kakao's nickname and id). If a user does not exist, a new account is automatically created.
Sources: src/main/java/org/example/coding_convention/user/service/OAuth2UserService.java:25-45
Profile Management
Users can manage their profile information and upload custom avatars.
API Endpoints
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET | /user/usr_mypage | Retrieves profile: nickname, email, platform, and image URL. | Yes |
POST | /user/usr_mypage/image | Uploads a profile image to S3 and updates the database. | Yes |
GET | /user/search | Searches users by nickname using a LIKE query. | No |
Sources: src/main/java/org/example/coding_convention/user/controller/UserController.java:71-125, src/main/java/org/example/coding_convention/user/service/UserService.java:54-75
Image Upload Logic
The updateImage function processes MultipartFile inputs, generates a unique S3 key using UUID, and stores the file in a bucket. The resulting URL is then persisted to the user's profileImg field.
// src/main/java/org/example/coding_convention/user/service/UserService.java:54-68
@Transactional
public String updateImage(MultipartFile file, UserDto.AuthUser authUser) {
User user = userRepository.findById(authUser.getIdx())
.orElseThrow(() -> new UsernameNotFoundException("User not found"));
try {
String key = "profiles/" + authUser.getIdx() + "/"
+ UUID.randomUUID() + "_" + file.getOriginalFilename();
s3Template.upload(bucketName, key, file.getInputStream());
String imageUrl = String.format("https://%s.s3.%s.amazonaws.com/%s",
bucketName, "ap-northeast-2", key);
user.setProfileImg(imageUrl);
return imageUrl;
} catch (IOException e) {
throw new RuntimeException("이미지 업로드 실패", e);
}
}
Sources: src/main/java/org/example/coding_convention/user/service/UserService.java:54-75
Security Configuration
User Management is governed by a SecurityFilterChain that defines access levels for various resources.
- Public Access:
/user/signup,/user/verify, and login endpoints are permitted for all. - Authenticated Access: Profile management and testing APIs require
ROLE_USER. - Filters:
JwtAuthFilterprocesses tokens before theUsernamePasswordAuthenticationFilter. - Session: The system uses JWT, and a
/user/logoutendpoint exists to clear tokens viaJwtUtil.
Sources: src/main/java/org/example/coding_convention/config/SecurityConfig.java:68-101, src/main/java/org/example/coding_convention/user/controller/UserController.java:112-117
The User Management system provides a robust framework for identity and access, ensuring that collaboration features are securely linked to verified users while offering flexible login options through both local and social providers.