You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
package com.personalproject.auth;
|
|
|
|
import com.personalproject.model.DifficultyLevel;
|
|
import java.time.LocalDateTime;
|
|
|
|
/**
|
|
* 不可变的账号定义.
|
|
*/
|
|
public record UserAccount(
|
|
String username,
|
|
String email,
|
|
String password,
|
|
DifficultyLevel difficultyLevel,
|
|
LocalDateTime registrationDate,
|
|
boolean isRegistered) {
|
|
|
|
/**
|
|
* Creates a new user account with registration date set to now.
|
|
*
|
|
* @param username The username
|
|
* @param email The email address
|
|
* @param password The password
|
|
* @param difficultyLevel The selected difficulty level
|
|
* @param isRegistered Whether the user has completed registration
|
|
*/
|
|
public UserAccount {
|
|
if (username == null || username.trim().isEmpty()) {
|
|
throw new IllegalArgumentException("Username cannot be null or empty");
|
|
}
|
|
if (email == null || email.trim().isEmpty()) {
|
|
throw new IllegalArgumentException("Email cannot be null or empty");
|
|
}
|
|
if (password == null) {
|
|
throw new IllegalArgumentException("Password cannot be null");
|
|
}
|
|
if (difficultyLevel == null) {
|
|
throw new IllegalArgumentException("Difficulty level cannot be null");
|
|
}
|
|
}
|
|
}
|