diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/HitRegistrationTeachInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/HitRegistrationTeachInfoController.java index cb5a76f..105e2a7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/HitRegistrationTeachInfoController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/HitRegistrationTeachInfoController.java @@ -2,6 +2,8 @@ package com.ruoyi.cms.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -9,7 +11,6 @@ import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; import com.ruoyi.cms.service.IHitRegistrationTeachInfoService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/IHitRegistrationTeachInfoService.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/IHitRegistrationTeachInfoService.java index 4a77fa4..7253033 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/IHitRegistrationTeachInfoService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/IHitRegistrationTeachInfoService.java @@ -1,8 +1,10 @@ package com.ruoyi.cms.service; -import java.util.List; import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; import com.ruoyi.common.core.domain.model.RegisterBody; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; /** * 教师信息Service接口 @@ -62,4 +64,5 @@ public interface IHitRegistrationTeachInfoService List getTeacherInfo(String schoolName, String division); + void register(RegisterBody user) throws Exception; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitCompetitionStudentInfoServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitCompetitionStudentInfoServiceImpl.java index b564a00..cae2daf 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitCompetitionStudentInfoServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitCompetitionStudentInfoServiceImpl.java @@ -11,8 +11,6 @@ import com.ruoyi.cms.mapper.HitTeamMembersMapper; import com.ruoyi.cms.mapper.HitTeamsMapper; import com.ruoyi.cms.service.IHitCompetitionStudentInfoService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ruoyi.cms.service.IHitRegistrationTeachInfoService; -import com.ruoyi.cms.service.IHitTeamsService; import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.DateUtils; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegInfoServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegInfoServiceImpl.java index d38ab06..8eb9ffe 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegInfoServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegInfoServiceImpl.java @@ -7,7 +7,6 @@ import java.util.List; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.ruoyi.cms.domain.*; import com.ruoyi.cms.mapper.*; import com.ruoyi.cms.service.ICmsContentService; @@ -15,7 +14,6 @@ import com.ruoyi.cms.service.IHitCompetitionStudentInfoService; import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.common.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.cms.service.IHitRegInfoService; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegistrationTeachInfoServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegistrationTeachInfoServiceImpl.java index e4ad979..73b93d8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegistrationTeachInfoServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitRegistrationTeachInfoServiceImpl.java @@ -1,16 +1,31 @@ package com.ruoyi.cms.service.impl; -import java.util.Collections; import java.util.List; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ruoyi.common.constant.CacheConstants; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.RegisterBody; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.exception.user.CaptchaException; +import com.ruoyi.common.exception.user.CaptchaExpireException; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.MessageUtils; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.framework.manager.AsyncManager; +import com.ruoyi.framework.manager.factory.AsyncFactory; +import com.ruoyi.framework.web.service.SysRegisterService; +import com.ruoyi.system.service.ISysConfigService; +import com.ruoyi.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.cms.mapper.HitRegistrationTeachInfoMapper; -import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; import com.ruoyi.cms.service.IHitRegistrationTeachInfoService; +import org.springframework.transaction.annotation.Transactional; /** * 教师信息Service业务层处理 @@ -22,6 +37,14 @@ import com.ruoyi.cms.service.IHitRegistrationTeachInfoService; public class HitRegistrationTeachInfoServiceImpl implements IHitRegistrationTeachInfoService { @Autowired private HitRegistrationTeachInfoMapper hitRegistrationTeachInfoMapper; + @Autowired + private SysRegisterService registerService; + @Autowired + private ISysConfigService configService; + @Autowired + private ISysUserService userService; + @Autowired + private RedisCache redisCache; /** * 查询教师信息 @@ -104,6 +127,83 @@ public class HitRegistrationTeachInfoServiceImpl implements IHitRegistrationTeac queryWrapper.eq(HitRegistrationTeachInfo::getDivision, division); return hitRegistrationTeachInfoMapper.selectList(queryWrapper); } + + @Override + @Transactional(rollbackFor = Exception.class) + public void register(RegisterBody user) throws Exception { + String msg = "", username = user.getUsername(), password = user.getPassword(); + SysUser sysUser = new SysUser(); + sysUser.setUserName(username); + + // 验证码开关 + boolean captchaEnabled = configService.selectCaptchaEnabled(); + if (captchaEnabled) { + validateCaptcha(username, user.getCode(), user.getUuid()); + } + + if (StringUtils.isEmpty(username)) { + msg = "用户名不能为空"; + } else if (StringUtils.isEmpty(password)) { + msg = "用户密码不能为空"; + } else if (username.length() < UserConstants.USERNAME_MIN_LENGTH + || username.length() > UserConstants.USERNAME_MAX_LENGTH) { + msg = "账户长度必须在2到20个字符之间"; + } else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH + || password.length() > UserConstants.PASSWORD_MAX_LENGTH) { + msg = "密码长度必须在5到20个字符之间"; + } else if (!userService.checkUserNameUnique(sysUser)) { + msg = "保存用户'" + username + "'失败,注册账号已存在"; + } else { + sysUser.setNickName(user.getNickName()); + sysUser.setPassword(SecurityUtils.encryptPassword(password)); + sysUser.setUserType(user.getUserType()); + boolean regFlag = userService.registerUser(sysUser); + if (!regFlag) { + msg = "注册失败,请联系系统管理人员"; + } else { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success"))); + } + + } + if(StringUtils.isNotEmpty(msg)){ + throw new Exception(msg); + } + if (user.getUserType().equals("02")){ + HitRegistrationTeachInfo teachInfo = user.getHitRegistrationTeachInfo(); + teachInfo.setRelatedAccounts(user.getUsername()); + teachInfo.setStatus("1"); + teachInfo.setType(user.getUserType()); + teachInfo.setTeacherName(user.getNickName()); + this.insertHitRegistrationTeachInfo(teachInfo); + }else if (user.getUserType().equals("03")){ + HitRegistrationTeachInfo teachInfo = user.getHitRegistrationTeachInfo(); + teachInfo.setRelatedAccounts(user.getUsername()); + teachInfo.setStatus("0"); + teachInfo.setType(user.getUserType()); + teachInfo.setTeacherName(user.getNickName()); + this.insertHitRegistrationTeachInfo(teachInfo); + } + } + + /** + * 校验验证码 + * + * @param username 用户名 + * @param code 验证码 + * @param uuid 唯一标识 + * @return 结果 + */ + public void validateCaptcha(String username, String code, String uuid) { + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); + String captcha = redisCache.getCacheObject(verifyKey); + redisCache.deleteObject(verifyKey); + if (captcha == null) { + throw new CaptchaExpireException(); + } + if (!code.equalsIgnoreCase(captcha)) { + throw new CaptchaException(); + } + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitTeamMembersServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitTeamMembersServiceImpl.java index f48ea69..84783fb 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitTeamMembersServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/HitTeamMembersServiceImpl.java @@ -1,9 +1,7 @@ package com.ruoyi.cms.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.ruoyi.cms.domain.HitCompetitionStudentInfo; import com.ruoyi.cms.domain.HitTeamMembers; import com.ruoyi.cms.domain.HitTeams; import com.ruoyi.cms.domain.Preliminary; @@ -11,7 +9,6 @@ import com.ruoyi.cms.mapper.HitRegistrationTeachInfoMapper; import com.ruoyi.cms.mapper.HitTeamMembersMapper; import com.ruoyi.cms.service.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java index 6adf46f..038c9b7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java @@ -1,8 +1,19 @@ package com.ruoyi.web.controller.system; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.ruoyi.cms.service.IHitRegistrationTeachInfoService; +import com.ruoyi.common.constant.CacheConstants; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.HitRegistrationTeachInfo; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.exception.user.CaptchaException; +import com.ruoyi.common.exception.user.CaptchaExpireException; +import com.ruoyi.common.utils.MessageUtils; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.framework.manager.AsyncManager; +import com.ruoyi.framework.manager.factory.AsyncFactory; +import com.ruoyi.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -22,29 +33,25 @@ import com.ruoyi.system.service.ISysConfigService; @RestController public class SysRegisterController extends BaseController { - @Autowired - private SysRegisterService registerService; - @Autowired - private ISysConfigService configService; @Autowired private IHitRegistrationTeachInfoService hitRegistrationTeachInfoService; + + @PostMapping("/register") public AjaxResult register(@RequestBody RegisterBody user) { - if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) - { - return error("当前系统没有开启注册功能!"); - } - String msg = registerService.register(user); - - if (user.getUserType().equals("02")){ - HitRegistrationTeachInfo teachInfo = user.getHitRegistrationTeachInfo(); - teachInfo.setRelatedAccounts(user.getUsername()); - hitRegistrationTeachInfoService.insertHitRegistrationTeachInfo(teachInfo); + String msg=""; + try { + hitRegistrationTeachInfoService.register(user); + }catch (Exception e){ + msg = e.getMessage(); } return StringUtils.isEmpty(msg) ? success() : error(msg); } + + + } diff --git a/ruoyi-admin/src/main/resources/mapper/cms/HitRegistrationTeachInfoMapper.xml b/ruoyi-admin/src/main/resources/mapper/cms/HitRegistrationTeachInfoMapper.xml index eb08eed..fb5af6f 100644 --- a/ruoyi-admin/src/main/resources/mapper/cms/HitRegistrationTeachInfoMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/cms/HitRegistrationTeachInfoMapper.xml @@ -4,7 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -19,16 +19,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, hit_reg_id, teacher_name, teacher_job, teacher_number, teacher_email, teacher_school, remark, del_flag, create_time, create_by, update_time, update_by, type from hit_registration_teach_info + select id, hit_reg_id, teacher_name, teacher_job, teacher_number, teacher_email, teacher_school, remark, del_flag, create_time, create_by, update_time, update_by, type,status from hit_registration_teach_info - and hit_reg_id = #{hitRegId} @@ -38,6 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and teacher_email = #{teacherEmail} and teacher_school = #{teacherSchool} and type = #{type} + and status = #{status} @@ -46,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} - + insert into hit_registration_teach_info id, @@ -63,10 +65,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update_time, update_by, type, + status, school_name, division, related_accounts, - sample_address, + #{id}, @@ -82,15 +85,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{createBy}, #{updateTime}, #{updateBy}, - #{type}, + type, + #{status}, #{schoolName}, #{division}, #{relatedAccounts}, - #{SampleAddress}, + - + update hit_registration_teach_info hit_reg_id = #{hitRegId}, @@ -105,7 +109,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_by = #{createBy}, update_time = #{updateTime}, update_by = #{updateBy}, - type = #{type}, + status = #{status}, where id = #{id} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 0c384c6..4a4890e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -93,7 +93,7 @@ public class Constants /** * 验证码有效期(分钟) */ - public static final Integer CAPTCHA_EXPIRATION = 2; + public static final Integer CAPTCHA_EXPIRATION = 5; /** * 令牌 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HitRegistrationTeachInfo.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HitRegistrationTeachInfo.java index b17c741..3b1d33e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HitRegistrationTeachInfo.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HitRegistrationTeachInfo.java @@ -2,9 +2,10 @@ package com.ruoyi.common.core.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.annotation.Excel; /** * 教师信息对象 hit_registration_teach_info @@ -66,6 +67,8 @@ public class HitRegistrationTeachInfo extends BaseEntity /** 盲样邮寄地址 */ @Excel(name = "盲样邮寄地址") private String SampleAddress; + //审核状态0待审核1审核通过2审核拒绝 + private String status; public String getSampleAddress() { return SampleAddress; @@ -206,4 +209,12 @@ public class HitRegistrationTeachInfo extends BaseEntity .append("sampleAddress",getSampleAddress()) .toString(); } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java index b5bc8c8..67e11ba 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java @@ -11,6 +11,7 @@ public class LoginBody * 用户名 */ private String username; + private String nickName; /** * 用户密码 @@ -66,4 +67,12 @@ public class LoginBody { this.uuid = uuid; } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index d9cbb0f..84e4a35 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -116,7 +116,7 @@ public class SecurityConfig .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() .antMatchers("/api/**", "/ueditor/**","/system/dict/data/type/sys_user_sex","/system/dict/data/type/imitation_type" - ,"/system/dict/data/type/school_name").permitAll() + ,"/system/dict/data/type/school_name","/system/dict/data/type/com_region").permitAll() .antMatchers("/system/hit_stu_info/*").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java index 2598e52..50b04b5 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java @@ -65,7 +65,7 @@ public class SysRegisterService { } else if (!userService.checkUserNameUnique(sysUser)) { msg = "保存用户'" + username + "'失败,注册账号已存在"; } else { - sysUser.setNickName(username); + sysUser.setNickName(registerBody.getNickName()); sysUser.setPassword(SecurityUtils.encryptPassword(password)); sysUser.setUserType(registerBody.getUserType()); boolean regFlag = userService.registerUser(sysUser); diff --git a/ruoyi-ui/src/views/officialWebsite/Components/header.vue b/ruoyi-ui/src/views/officialWebsite/Components/header.vue index 5c87995..d1d91c0 100644 --- a/ruoyi-ui/src/views/officialWebsite/Components/header.vue +++ b/ruoyi-ui/src/views/officialWebsite/Components/header.vue @@ -1,5 +1,5 @@