|
@@ -1,16 +1,25 @@
|
|
|
package boot.modules.manage.controller;
|
|
|
|
|
|
+import boot.common.bean.LocalUser;
|
|
|
+import boot.common.constant.SchoolConstant;
|
|
|
+import boot.common.enums.SmsTypeEnum;
|
|
|
+import boot.common.interceptor.AuthCheck;
|
|
|
+import boot.common.respond.ApiCode;
|
|
|
import boot.common.respond.ApiResult;
|
|
|
import boot.common.respond.EException;
|
|
|
import boot.common.utils.JwtToken;
|
|
|
import boot.common.utils.RedisUtils;
|
|
|
import boot.modules.manage.pojo.Manage;
|
|
|
import boot.modules.manage.service.ManageService;
|
|
|
+import boot.modules.user.param.ForgetParam;
|
|
|
import boot.modules.user.param.HLoginParam;
|
|
|
import boot.modules.user.param.RegParam;
|
|
|
+import boot.modules.user.param.VerityParam;
|
|
|
import boot.modules.user.pojo.User;
|
|
|
import boot.modules.user.service.UserService;
|
|
|
import boot.modules.user.service.impl.AuthService;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -93,4 +102,67 @@ public class ManageController {
|
|
|
authService.registerManage(param);
|
|
|
return ApiResult.ok("", "注册成功");
|
|
|
}
|
|
|
+
|
|
|
+ @AuthCheck
|
|
|
+ @ApiOperation(value = "退出登录", notes = "退出登录")
|
|
|
+ @PostMapping(value = "/logout")
|
|
|
+ public ApiResult<String> logout(HttpServletRequest request) {
|
|
|
+ String bearerToken = request.getHeader("Authorization");
|
|
|
+ String[] tokens = bearerToken.split(" ");
|
|
|
+ String token = tokens[1];
|
|
|
+ authService.logout(LocalUser.getUser().getUsername(), token);
|
|
|
+ return ApiResult.ok("退出成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "忘记密码", notes = "忘记密码")
|
|
|
+ @PostMapping(value = "/forget")
|
|
|
+ public ApiResult<String> forget(@Validated @RequestBody ForgetParam param) {
|
|
|
+ Object codeObj = redisUtil.get("code_" + param.getAccount());
|
|
|
+ if (codeObj == null) {
|
|
|
+ return ApiResult.fail("请先获取验证码");
|
|
|
+ }
|
|
|
+ String code = codeObj.toString();
|
|
|
+ if (!StrUtil.equals(code, param.getCaptcha())) {
|
|
|
+ return ApiResult.fail("验证码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ Manage manager = manageService.getOne(Wrappers.<Manage>lambdaQuery()
|
|
|
+ .eq(Manage::getPhone, param.getAccount()), false);
|
|
|
+ if (ObjectUtil.isNull(manager)) {
|
|
|
+ return ApiResult.fail("该用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ manager.setPassword(SecureUtil.md5(param.getPassword()));
|
|
|
+ manageService.updateById(manager);
|
|
|
+ return ApiResult.ok("密码重置成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/register/verify")
|
|
|
+ @ApiOperation(value = "短信验证码发送", notes = "短信验证码发送")
|
|
|
+ public ApiResult<String> verify(@Validated @RequestBody VerityParam param) {
|
|
|
+ Manage manager = manageService.getOne(Wrappers.<Manage>lambdaQuery()
|
|
|
+ .eq(Manage::getPhone, param.getPhone()), false);
|
|
|
+ if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(manager)) {
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"手机号已注册");
|
|
|
+ }
|
|
|
+ if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(manager)) {
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"账号不存在");
|
|
|
+ }
|
|
|
+ String codeKey = "code_" + param.getPhone();
|
|
|
+ if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) {
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"10分钟内有效:" + redisUtil.get(codeKey).toString());
|
|
|
+ }
|
|
|
+ String code = RandomUtil.randomNumbers(SchoolConstant.SCHOOL_SMS_SIZE);
|
|
|
+
|
|
|
+ //redis存储
|
|
|
+ redisUtil.set(codeKey, code, SchoolConstant.SCHOOL_SMS_REDIS_TIME);
|
|
|
+
|
|
|
+// String enable = redisUtil.getY("sms_enable");
|
|
|
+ Boolean enable = false;
|
|
|
+// if (SchoolEnum.ENABLE_2.getValue().toString().equals(enable)) {
|
|
|
+ return ApiResult.ok(code);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|