screen-common/src/main/java/com/moral/constant/Constants.java | ●●●●● patch | view | raw | blame | history | |
screen-common/src/main/java/com/moral/pojo/VerificationCode.java | ●●●●● patch | view | raw | blame | history | |
screen-common/src/main/java/com/moral/util/KaptchaUtils.java | ●●●●● patch | view | raw | blame | history | |
screen-manage/src/main/java/com/moral/api/controller/AccountController.java | ●●●●● patch | view | raw | blame | history | |
screen-manage/src/main/java/com/moral/api/controller/LoginController.java | ●●●●● patch | view | raw | blame | history | |
screen-manage/src/main/resources/application-dev.yml | ●●●●● patch | view | raw | blame | history |
screen-common/src/main/java/com/moral/constant/Constants.java
@@ -7,4 +7,5 @@ public static String DELETE = "1"; public static String NOT_DELETE = "0"; } screen-common/src/main/java/com/moral/pojo/VerificationCode.java
@@ -1,6 +1,7 @@ package com.moral.pojo; import lombok.Data; import org.springframework.util.ObjectUtils; /** * @ClassName VerificationCode @@ -14,5 +15,17 @@ private String key; private String value; private String encode; private String inputText; public boolean valid(){ if ( ObjectUtils.isEmpty(key) || ObjectUtils.isEmpty(inputText) || inputText.length()!=4 ) return false; return true; } } screen-common/src/main/java/com/moral/util/KaptchaUtils.java
@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; import sun.misc.BASE64Encoder; import javax.annotation.Resource; @@ -18,6 +19,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.UUID; import java.util.concurrent.TimeUnit; /** * @ClassName KaptchaUtils @@ -33,6 +35,9 @@ private static DefaultKaptcha defaultKaptcha; private static RedisTemplate redisTemplate; //验证码有效期 单位:秒 private static final int validity_time = 60; @Autowired public void setRedisTemplate(RedisTemplate redisTemplate) { @@ -54,6 +59,7 @@ */ public static VerificationCode createVerificationCode() throws IOException { VerificationCode verificationCode = new VerificationCode(); //生成验证码内容 String text = defaultKaptcha.createText(); //生成图片 @@ -67,12 +73,19 @@ String encode = encoder.encode(bytes); //将验证码存入redis String key = UUID.randomUUID().toString(); //redisTemplate.opsForValsue().set(key,encode); //redisTemplate.expire(); return null; redisTemplate.opsForValue().set(key,text); redisTemplate.expire(key,validity_time, TimeUnit.SECONDS); verificationCode.setKey(key); verificationCode.setEncode(encode); return verificationCode; } public boolean verify(String verificationCode) { return false; public static boolean verify(VerificationCode code) { String key = code.getKey(); String inputText = code.getInputText(); String validText = (String) redisTemplate.opsForValue().get(key); if(inputText.equals(validText)) return true; return false; } screen-manage/src/main/java/com/moral/api/controller/AccountController.java
@@ -37,55 +37,27 @@ @Autowired ManageAccountService accountService; @PostMapping("login") public ResultMessage login(@RequestBody LoginForm loginForm) { if (!loginForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); LoginDTO loginDTO = accountService.login(loginForm); LoginVO loginVO = LoginVO.convert(loginDTO); return new ResultMessage(loginDTO.getCode(),loginDTO.getMsg(),loginVO); } @PostMapping("logout") public ResultMessage logout (@RequestBody LogoutForm logoutForm, HttpServletRequest request) { if(!logoutForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); String token = request.getHeader("token"); logoutForm.setToken(token); if(accountService.logout(logoutForm)) return ResultMessage.ok(); return ResultMessage.fail(); } @PostMapping("insert") public ResultMessage insert(@RequestBody AccountInsertForm accountInsertForm){ if(!accountInsertForm.valid()) public ResultMessage insert(@RequestBody AccountInsertForm accountInsertForm) { if (!accountInsertForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //判断参数是否符合条件 AccountInsertDTO conditionDTO = accountInsertForm.paramValid(); if(conditionDTO.getCode()!=ResponseCodeEnum.SUCCESS.getCode()){ return new ResultMessage(conditionDTO.getCode(),conditionDTO.getMsg(),null); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } AccountInsertDTO accountInsertDTO = accountService.insertAccount(accountInsertForm); AccountInsertVO accountInsertVO = AccountInsertVO.convert(accountInsertDTO); return new ResultMessage(accountInsertDTO.getCode(),accountInsertDTO.getMsg(),accountInsertVO); return new ResultMessage(accountInsertDTO.getCode(), accountInsertDTO.getMsg(), accountInsertVO); } @GetMapping("query") public ResultMessage query(AccountQueryForm accountQueryForm){ if(!accountQueryForm.valid()) public ResultMessage query(AccountQueryForm accountQueryForm) { if (!accountQueryForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); @@ -93,32 +65,32 @@ AccountQueryVO accountQueryVO = AccountQueryVO.convert(accountQueryDTO); return new ResultMessage(accountQueryDTO.getCode(),accountQueryDTO.getMsg(),accountQueryVO); return new ResultMessage(accountQueryDTO.getCode(), accountQueryDTO.getMsg(), accountQueryVO); } @PostMapping("update") public ResultMessage update(@RequestBody AccountUpdateForm accountUpdateRequest){ if(!accountUpdateRequest.valid()) public ResultMessage update(@RequestBody AccountUpdateForm accountUpdateRequest) { if (!accountUpdateRequest.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //判断参数是否符合条件 AccountUpdateDTO conditionDTO = accountUpdateRequest.paramValid(); if(conditionDTO.getCode()!=ResponseCodeEnum.SUCCESS.getCode()){ return new ResultMessage(conditionDTO.getCode(),conditionDTO.getMsg(),null); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } AccountUpdateDTO accountUpdateDTO = accountService.updateAccount(accountUpdateRequest); AccountUpdateVO accountUpdateVO = AccountUpdateVO.convert(accountUpdateDTO); return new ResultMessage(accountUpdateDTO.getCode(),accountUpdateDTO.getMsg(),accountUpdateVO); return new ResultMessage(accountUpdateDTO.getCode(), accountUpdateDTO.getMsg(), accountUpdateVO); } @PostMapping("delete") public ResultMessage delete(@RequestBody AccountDeleteForm accountDeleteForm){ if(!accountDeleteForm.valid()) public ResultMessage delete(@RequestBody AccountDeleteForm accountDeleteForm) { if (!accountDeleteForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); @@ -126,16 +98,8 @@ AccountDeleteVO accountDeleteVO = AccountDeleteVO.convert(accountDeleteDTO); return new ResultMessage(accountDeleteDTO.getCode(),accountDeleteDTO.getMsg(),accountDeleteVO); return new ResultMessage(accountDeleteDTO.getCode(), accountDeleteDTO.getMsg(), accountDeleteVO); } @PostMapping("yanzhengma") public String yanzhengma(HttpServletResponse response) throws IOException { KaptchaUtils.createVerificationCode(); TokenUtils.getToken("1",1); return null; } } screen-manage/src/main/java/com/moral/api/controller/LoginController.java
New file @@ -0,0 +1,125 @@ package com.moral.api.controller; import com.moral.api.pojo.dto.login.LoginDTO; import com.moral.api.pojo.form.LoginForm; import com.moral.api.pojo.form.LogoutForm; import com.moral.api.pojo.vo.login.LoginVO; import com.moral.api.service.ManageAccountService; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import com.moral.pojo.VerificationCode; import com.moral.util.KaptchaUtils; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; /** * @ClassName LoginController * @Description TODO * @Author 陈凯裕 * @Date 2021/3/18 15:28 * @Version TODO **/ @Slf4j @Api(tags = {"登陆模块"}) @RestController public class LoginController { @Autowired ManageAccountService accountService; /** * @Description: 登陆接口 * @Param: [loginForm] * @return: com.moral.constant.ResultMessage * @Author: 陈凯裕 * @Date: 2021/3/18 */ @PostMapping("login") public ResultMessage login(@RequestBody LoginForm loginForm) { if (!loginForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); LoginDTO loginDTO = accountService.login(loginForm); LoginVO loginVO = LoginVO.convert(loginDTO); return new ResultMessage(loginDTO.getCode(), loginDTO.getMsg(), loginVO); } /** * @Description: 退出接口 * @Param: [logoutForm, request] * @return: com.moral.constant.ResultMessage * @Author: 陈凯裕 * @Date: 2021/3/18 */ @PostMapping("logout") public ResultMessage logout(@RequestBody LogoutForm logoutForm, HttpServletRequest request) { if (!logoutForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); String token = request.getHeader("token"); logoutForm.setToken(token); if (accountService.logout(logoutForm)) return ResultMessage.ok(); return ResultMessage.fail(); } /** * @Description: 获取验证码是否开启 * @Param: [] * @return: com.moral.constant.ResultMessage * @Author: 陈凯裕 * @Date: 2021/3/18 */ @GetMapping public ResultMessage verifyConfig(){ return null; } /** * @Description: 获取验证码接口 * @Param: [] * @return: com.moral.constant.ResultMessage * @Author: 陈凯裕 * @Date: 2021/3/18 */ @GetMapping("verificationCode/get") public ResultMessage getVerificationCode() { VerificationCode verificationCode = null; try { verificationCode = KaptchaUtils.createVerificationCode(); } catch (IOException e) { log.error(e.getMessage()); } if(ObjectUtils.isEmpty(verificationCode)) return ResultMessage.fail(); System.out.println(verificationCode.getEncode()); return ResultMessage.ok(verificationCode); } /** * @Description: 校验验证码 * @Param: [verificationCode] * @return: com.moral.constant.ResultMessage * @Author: 陈凯裕 * @Date: 2021/3/18 */ @GetMapping("verificationCode/verify") public ResultMessage gverifyVerificationCode(VerificationCode verificationCode) { if(!verificationCode.valid()) return ResultMessage.fail(); if(KaptchaUtils.verify(verificationCode)) return ResultMessage.ok(); return ResultMessage.fail(); } } screen-manage/src/main/resources/application-dev.yml
@@ -113,16 +113,18 @@ mvc: interceptor: exclude: - /account/login - /login - /swagger-ui.html - /swagger-resources/** - /webjars/** - /account/logout - /logout - /account/insert - /account/query - /account/update - /account/delete - /account/yanzhengma - /verificationCode/get - /verificationCode/verify AES: KEY: AD42F7787B035B7580000EF93BE20BAD