统一repairman角色类型 #59

Merged
hnu202326010122 merged 3 commits from jingyou_branch into develop 1 month ago

@ -12,7 +12,6 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
@ -27,7 +26,7 @@ import java.util.Arrays;
*/
@Configuration
@EnableWebSecurity
@EnableMethodSecurity(prePostEnabled = true) // 启用方法级权限控制
@EnableMethodSecurity() // 启用方法级权限控制
public class SecurityConfig {
private final UserDetailsServiceImpl userDetailsService;

@ -33,7 +33,7 @@ public class LoginService {
return switch (userType) {
case "admin" -> handleAdminLogin(username, password);
case "user" -> handleUserLogin(username, password);
case "repairer" -> handleRepairerLogin(username, password);
case "repairman" -> handleRepairmanLogin(username, password);
default -> throw new RuntimeException("无效的用户类型:" + userType);
};
}
@ -84,7 +84,7 @@ public class LoginService {
return createLoginVO(user.getStudentId(), username, "user");
}
private LoginVO handleRepairerLogin(String username, String password) {
private LoginVO handleRepairmanLogin(String username, String password) {
// 此处将RepairerAuthPO改为RepairerAuth
RepairerAuth repairer = repairerAuthRepository.findByUsername(username)
.orElseThrow(() -> new RuntimeException("维修人员不存在"));
@ -93,7 +93,7 @@ public class LoginService {
throw new RuntimeException("密码错误");
}
return createLoginVO(repairer.getRepairmanId(), username, "repairer");
return createLoginVO(repairer.getRepairmanId(), username, "repairman");
}
private LoginVO createLoginVO(String userId, String username, String userType) {

@ -40,8 +40,8 @@ public class RegisterService {
case "user":
handleUserRegister(username, encryptedPwd, request);
break;
case "repairer":
handleRepairerRegister(username, encryptedPwd, request);
case "repairman":
handleRepairmanRegister(username, encryptedPwd, request);
break;
default:
throw new RuntimeException("无效的用户类型:" + userType);
@ -89,7 +89,7 @@ public class RegisterService {
}
// 维修人员注册逻辑保持不变
private void handleRepairerRegister(String username, String password, RegisterRequest request) {
private void handleRepairmanRegister(String username, String password, RegisterRequest request) {
if (repairerAuthRepository.existsByUsername(username)) {
throw new RuntimeException("维修人员用户名已存在");
}
@ -97,12 +97,12 @@ public class RegisterService {
throw new RuntimeException("维修人员ID已被注册");
}
RepairerAuth repairer = new RepairerAuth();
repairer.setUsername(username);
repairer.setPassword(password);
repairer.setRepairmanId(request.getRepairmanId());
repairer.setAccountStatus(RepairerAuth.AccountStatus.active);
RepairerAuth repairman = new RepairerAuth();
repairman.setUsername(username);
repairman.setPassword(password);
repairman.setRepairmanId(request.getRepairmanId());
repairman.setAccountStatus(RepairerAuth.AccountStatus.active);
repairerAuthRepository.save(repairer);
repairerAuthRepository.save(repairman);
}
}
Loading…
Cancel
Save