diff --git a/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java b/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java index d5ab7164..3bb28914 100644 --- a/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java +++ b/exam-module-system/exam-module-system-api/src/main/java/pc/exam/pp/module/system/enums/ErrorCodeConstants.java @@ -17,6 +17,8 @@ public interface ErrorCodeConstants { ErrorCode AUTH_MOBILE_NOT_EXISTS = new ErrorCode(1_002_000_007, "手机号不存在"); ErrorCode AUTH_REGISTER_CAPTCHA_CODE_ERROR = new ErrorCode(1_002_000_008, "验证码不正确,原因:{}"); + ErrorCode AUTH_LOGIN_NICKNAME_NOT = new ErrorCode(1_002_000_009, "登录失败,账号昵称不正确"); + ErrorCode AUTH_LOGIN_BAD_USERNAME_NOT = new ErrorCode(1_002_000_010, "登录失败,账号不正确"); // ========== 菜单模块 1-002-001-000 ========== ErrorCode MENU_NAME_DUPLICATE = new ErrorCode(1_002_001_000, "已经存在该名字的菜单"); ErrorCode MENU_PARENT_NOT_EXISTS = new ErrorCode(1_002_001_001, "父菜单不存在"); diff --git a/exam-module-system/exam-module-system-biz/pom.xml b/exam-module-system/exam-module-system-biz/pom.xml index 7a1d9a47..c15e9725 100644 --- a/exam-module-system/exam-module-system-biz/pom.xml +++ b/exam-module-system/exam-module-system-biz/pom.xml @@ -131,6 +131,12 @@ 2.4.2-SNAPSHOT compile + + pc.exam.gg + exam-module-infra-biz + 2.4.2-SNAPSHOT + compile + diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/AuthLoginReqVO.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/AuthLoginReqVO.java index abf93eef..e8ce1521 100644 --- a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/AuthLoginReqVO.java +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/AuthLoginReqVO.java @@ -32,6 +32,12 @@ public class AuthLoginReqVO extends CaptchaVerificationReqVO { @Length(min = 4, max = 16, message = "密码长度为 4-16 位") private String password; + @Schema(description = "用户昵称") + private String nickname; + + @Schema(description = "用户类型") + private String userType; + // ========== 绑定社交登录时,需要传递如下参数 ========== @Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") @@ -41,8 +47,7 @@ public class AuthLoginReqVO extends CaptchaVerificationReqVO { @Schema(description = "授权码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private String socialCode; - @Schema(description = "用户类型") - private String userType; + @Schema(description = "state", requiredMode = Schema.RequiredMode.REQUIRED, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62") private String socialState; diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthService.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthService.java index 236969a5..c73023d5 100644 --- a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthService.java +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthService.java @@ -23,6 +23,23 @@ public interface AdminAuthService { */ AdminUserDO authenticate(String username, String password); + /** + * 验证账号 + 昵称。如果通过,则返回用户 + * + * @param username 账号 + * @param nickname 昵称 + * @return 用户 + */ + AdminUserDO authenticateByNickName(String username, String nickname); + + /** + * 验证账号。如果通过,则返回用户 + * + * @param username 账号 + * @return 用户 + */ + AdminUserDO authenticateOnlyUsername(String username); + /** * 账号登录 * diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthServiceImpl.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthServiceImpl.java index de749d17..a6714ecb 100644 --- a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthServiceImpl.java +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/auth/AdminAuthServiceImpl.java @@ -6,6 +6,8 @@ import pc.exam.pp.framework.common.enums.UserTypeEnum; import pc.exam.pp.framework.common.util.monitor.TracerUtils; import pc.exam.pp.framework.common.util.servlet.ServletUtils; import pc.exam.pp.framework.common.util.validation.ValidationUtils; +import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO; +import pc.exam.pp.module.infra.service.config.ConfigService; import pc.exam.pp.module.system.api.logger.dto.LoginLogCreateReqDTO; import pc.exam.pp.module.system.api.sms.SmsCodeApi; import pc.exam.pp.module.system.api.sms.dto.code.SmsCodeUseReqDTO; @@ -67,7 +69,8 @@ public class AdminAuthServiceImpl implements AdminAuthService { private CaptchaService captchaService; @Resource private SmsCodeApi smsCodeApi; - + @Resource + private ConfigService configService; /** * 验证码的开关,默认为 true */ @@ -95,15 +98,62 @@ public class AdminAuthServiceImpl implements AdminAuthService { } return user; } - + @Override + public AdminUserDO authenticateOnlyUsername(String username) { + final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_USERNAME; + // 校验账号是否存在 + AdminUserDO user = userService.getUserByUsername(username); + if (user == null) { + createLoginLog(null, username, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS); + throw exception(AUTH_LOGIN_BAD_USERNAME_NOT); + } + // 校验是否禁用 + if (CommonStatusEnum.isDisable(user.getStatus())) { + createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.USER_DISABLED); + throw exception(AUTH_LOGIN_USER_DISABLED); + } + return user; + } + @Override + public AdminUserDO authenticateByNickName(String username, String nickname) { + final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_USERNAME; + // 校验账号是否存在 + AdminUserDO user = userService.getUserByUsername(username); + // 校验昵称是否匹配 + if (user.getNickname().equals(nickname)) { + throw exception(AUTH_LOGIN_NICKNAME_NOT); + } + // 校验是否禁用 + if (CommonStatusEnum.isDisable(user.getStatus())) { + createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.USER_DISABLED); + throw exception(AUTH_LOGIN_USER_DISABLED); + } + return user; + } @Override public AuthLoginRespVO login(AuthLoginReqVO reqVO) { - // 校验验证码 + AdminUserDO user = new AdminUserDO(); + // 校验验证码 validateCaptcha(reqVO); - - // 使用账号密码,进行登录 - AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword()); - + // 判断用户类型 + if (reqVO.getUserType().equals("2")) { + // 说明是学生用户,在判断学生的登录方式 + ConfigDO config = configService.getConfigByKey("student_login"); + String type = config.getValue(); + if (type.equals("1")) { + // 考生账号+姓名登录 + user = authenticateByNickName(reqVO.getUsername(), reqVO.getPassword()); + } else if (type.equals("2")) { + // 考生账号+密码登录 + user = authenticate(reqVO.getUsername(), reqVO.getPassword()); + } else if (type.equals("3")) { + // 考生账号登录 + user = authenticateOnlyUsername(reqVO.getUsername()); + } + } else { + // 使用账号密码,进行登录 + user = authenticate(reqVO.getUsername(), reqVO.getPassword()); + } // 如果 socialType 非空,说明需要绑定社交用户 if (reqVO.getSocialType() != null) { socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java index 6ac4e625..80882a8d 100644 --- a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.StrUtil; -import org.bouncycastle.jcajce.provider.symmetric.TEA; import pc.exam.pp.framework.common.enums.CommonStatusEnum; import pc.exam.pp.framework.common.exception.ServiceException; import pc.exam.pp.framework.common.pojo.PageResult; @@ -12,9 +11,13 @@ import pc.exam.pp.framework.common.util.collection.CollectionUtils; import pc.exam.pp.framework.common.util.object.BeanUtils; import pc.exam.pp.framework.common.util.validation.ValidationUtils; import pc.exam.pp.framework.datapermission.core.util.DataPermissionUtils; +import pc.exam.pp.framework.web.core.util.WebFrameworkUtils; import pc.exam.pp.module.exam.controller.admin.classs.vo.ClassSaveReqVO; +import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtListByUserReqVo; +import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtyQueryVo; import pc.exam.pp.module.exam.dal.dataobject.classs.ClassDO; import pc.exam.pp.module.exam.dal.mysql.classs.ClassMapper; +import pc.exam.pp.module.exam.dal.mysql.specialty.ExamSpecialtyMapper; import pc.exam.pp.module.exam.service.classs.ClassService; import pc.exam.pp.module.infra.api.config.ConfigApi; import pc.exam.pp.module.infra.api.file.FileApi; @@ -99,6 +102,8 @@ public class AdminUserServiceImpl implements AdminUserService { private FileApi fileApi; @Resource private ConfigApi configApi; + @Resource + private ExamSpecialtyMapper examSpecialtyMapper; @Override @Transactional(rollbackFor = Exception.class) @@ -731,6 +736,29 @@ public class AdminUserServiceImpl implements AdminUserService { return passwordEncoder.matches(rawPassword, encodedPassword); } + @Override + public List getListByUser() { + Long userId = WebFrameworkUtils.getLoginUserId(); + AdminUserDO adminUserDO = getUser(userId); + List specialtyQueryVos = new ArrayList<>(); + // 判断用户类型 管理员所有专业 + if (adminUserDO.getUserType().equals("0")) { + // 查询所有专业数据 + specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll(); + } else { + + // 判断专业是否为空,为空的话查询所有 + if (adminUserDO.getClassIds() != null) { + // 查询所有数据 + specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll(); + } else { + // 查询部分数据 + specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyByids(adminUserDO.getClassIds()); + } + } + return specialtyQueryVos; + } + /** * 对密码进行加密 *