diff --git a/luoo_common/src/main/java/enums/CollectTypeEnum.java b/luoo_common/src/main/java/enums/CollectTypeEnum.java index 50cbea4..3e7c5c0 100644 --- a/luoo_common/src/main/java/enums/CollectTypeEnum.java +++ b/luoo_common/src/main/java/enums/CollectTypeEnum.java @@ -1,30 +1,30 @@ package enums; public enum CollectTypeEnum { - SONG(0, "歌曲"), JOURNAL(1, "期刊"); + SONG(0, "歌曲"), JOURNAL(1, "期刊"), FOLLOW(2, "关注"), BLACK_LIST(3, "黑名单"), THUMB_UP(4, "点赞"); - private Integer type; - private String description; + private Integer type; + private String description; - CollectTypeEnum(int type, String description) { - this.type = type; - this.description = description; - } + CollectTypeEnum(int type, String description) { + this.type = type; + this.description = description; + } - public Integer getType() { - return type; - } + public Integer getType() { + return type; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public static CollectTypeEnum getByType(Integer type) { - for (CollectTypeEnum at : CollectTypeEnum.values()) { - if (at.type.equals(type)) { - return at; - } - } - return null; - } + public static CollectTypeEnum getByType(Integer type) { + for (CollectTypeEnum at : CollectTypeEnum.values()) { + if (at.type.equals(type)) { + return at; + } + } + return null; + } } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java index cbcd601..d080ad0 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java @@ -46,8 +46,9 @@ import util.StringTools; @CrossOrigin @RequestMapping("/user") @Api(tags = "LoginController") -public class LoginController extends BaseController{ - private static final List DEFAULT_SUPPORTED_COUNTRY_CODES=Arrays.asList(new CountryCodeDTO("中国","+86")); +public class LoginController extends BaseController { + private static final List DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays + .asList(new CountryCodeDTO("中国", "+86")); @Autowired private UserInfoService userInfoService; @@ -71,30 +72,44 @@ public class LoginController extends BaseController{ */ @ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟,一个手机号一天内最多发送50个请求") @ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true), - @ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86’", required = false, defaultValue="+86"), - @ApiImplicitParam(name = "deviceId", value = "设备id", required = true)}) + @ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86’", required = false, defaultValue = "+86"), + @ApiImplicitParam(name = "deviceId", value = "设备id", required = true), + @ApiImplicitParam(name = "imageCheckCode", value = "图形验证码", required = false) }) @PostMapping("/sendsms") @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50) - public Result sendSms( - @VerifyParam(required = true) @RequestParam("deviceId") String deviceId, - @RequestParam(name="countryCode",defaultValue="+86") String countryCode, - @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile) { - userInfoService.sendSms(deviceId,mobile); + public Result sendSms(@VerifyParam(required = true) @RequestParam("deviceId") String deviceId, + @RequestParam(name = "countryCode", defaultValue = "+86") String countryCode, + @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile, + @VerifyParam(required = false) @RequestParam("imageCheckCode") String imageCheckCode) { + if (!StringTools.isEmpty(imageCheckCode)) { + // 得到缓存中的验证码 + String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId; + String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey); + if (StringTools.isEmpty(redisImageCheckCode)) { + return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED); + } + if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) { + return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH); + } + redisTemplate.delete(redisImageCheckCodeKey); + } + + userInfoService.sendSms(deviceId, mobile); return Result.success(); } - + @ApiOperation(value = "2.登录/注册", notes = "成功后返回token") @ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true), - @ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true), - @ApiImplicitParam(name = "deviceId", value = "设备id", required = true), - @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) }) + @ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true), + @ApiImplicitParam(name = "deviceId", value = "设备id", required = true), + @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) }) @PostMapping("/appLogin") - @GlobalInterceptor - public Result appLogin(HttpServletRequest request, + @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12) + public Result appLogin(HttpServletRequest request, @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile, @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode, @VerifyParam(required = true) @RequestParam("deviceId") String deviceId, - @RequestParam("deviceBrand") String deviceBrand) { + @RequestParam("deviceBrand") String deviceBrand) { // 得到缓存中的验证码 String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId; try { @@ -116,34 +131,30 @@ public class LoginController extends BaseController{ } } - - /** * token 续期 */ @ApiOperation(value = "3.token续期", notes = "有效期7天") - @ApiImplicitParams({ - @ApiImplicitParam(name = "deviceId", value = "设备id", required = true), - @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) }) + @ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true), + @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) }) @PostMapping("/autoLogin") @GlobalInterceptor - public Result autoLogin(HttpServletRequest request,@RequestHeader(value = "token", required = false) String token, - @VerifyParam(required = true) @RequestParam("deviceId") String deviceId, - @RequestParam("deviceBrand") String deviceBrand) { - return Result.success(userInfoService.autoLogin(token,deviceId,deviceBrand,getIpAddr(request))); + public Result autoLogin(HttpServletRequest request, + @RequestHeader(value = "token", required = false) String token, + @VerifyParam(required = true) @RequestParam("deviceId") String deviceId, + @RequestParam("deviceBrand") String deviceBrand) { + return Result.success(userInfoService.autoLogin(token, deviceId, deviceBrand, getIpAddr(request))); } /** * 获取图行验证码 */ @ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后,获取图形验证码,有效期10分钟") - @ApiImplicitParams({ - @ApiImplicitParam(name = "deviceId", value = "设备id", required = true)}) + @ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true) }) @GetMapping("/imageCheckCode/{deviceId}") @GlobalInterceptor public void imageCheckCode(HttpServletResponse response, - @VerifyParam(required = true) @PathVariable("deviceId") String deviceId) - throws IOException { + @VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException { CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); @@ -155,35 +166,12 @@ public class LoginController extends BaseController{ vCode.write(response.getOutputStream()); } - @ApiOperation(value = "5.图形验证码+短信验证码 登录/注册后返回token") - @PostMapping("/appLoginWithImageCode") - @GlobalInterceptor - public Result appLoginWithImageCheckCode( - HttpServletRequest request, - @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile, - @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode, - @VerifyParam(required = true) @RequestParam("deviceId") String deviceId, - @RequestParam("deviceBrand") String deviceBrand, - @VerifyParam(required = true) @RequestParam("imageCheckCode") String imageCheckCode) { - // 得到缓存中的验证码 - String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId; - String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey); - if (StringTools.isEmpty(redisImageCheckCode)) { - return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED); - } - if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) { - return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH); - } - redisTemplate.delete(redisImageCheckCodeKey); - return appLogin(request, mobile, mobileCheckCode, deviceId, deviceBrand); - } - /** * 获取支持的手机号国家码 */ - @ApiOperation(value = "6.获取支持的手机号国家码", notes = "v1仅支持'+86'") + @ApiOperation(value = "5.获取支持的手机号国家码", notes = "v1仅支持'+86'") @GetMapping("/supportedCountryCode") - public Result> getSupportedCountryCode(){ + public Result> getSupportedCountryCode() { return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES); } } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java index e8b4217..941d580 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java @@ -3,9 +3,7 @@ package com.luoo.user.controller; import annotation.GlobalInterceptor; import annotation.VerifyParam; import api.Result; -import client.vo.SimpleUser; import com.luoo.user.service.UserCollectService; -import com.luoo.user.service.UserService; import dto.UserLoginDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -15,8 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import util.JwtUtil; -import java.util.List; - @Api(tags = "UserCollectController") @RestController @RequestMapping("/userCollect") @@ -25,12 +21,11 @@ public class UserCollectController { private JwtUtil jwtUtil; @Autowired private UserCollectService userCollectService; - @Autowired - private UserService userService; - @ApiOperation(value = "1.收藏/喜欢") - @ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id,此处为歌曲/期刊id", required = true), - @ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型,0为歌曲,1为期刊", required = true) }) + @ApiOperation(value = "1.喜欢歌曲/收藏期刊/关注/黑名单/点赞") + @ApiImplicitParams({ + @ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true), + @ApiImplicitParam(name = "collectType", value = "0:歌曲,1:期刊,2:关注,3:黑名单,4:点赞", required = true) }) @PostMapping("/addCollect") @GlobalInterceptor(checkLogin = true) public Result addCollect(@RequestHeader(value = "token", required = false) String token, @@ -41,9 +36,10 @@ public class UserCollectController { return Result.success(); } - @ApiOperation(value = "2.取消 收藏/喜欢") - @ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id,此处为歌曲/期刊id", required = true), - @ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型,0为歌曲,1为期刊", required = true) }) + @ApiOperation(value = "2.取消 喜欢歌曲/收藏期刊/关注/黑名单/点赞") + @ApiImplicitParams({ + @ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true), + @ApiImplicitParam(name = "collectType", value = "0:歌曲,1:期刊,2:关注,3:黑名单,4:点赞", required = true) }) @DeleteMapping("/cancelCollect") @GlobalInterceptor(checkLogin = true) public Result cancelCollect(@RequestHeader(value = "token", required = false) String token, @@ -54,13 +50,4 @@ public class UserCollectController { collectType); return Result.success(); } - - /* - * @ApiOperation(value = "根据 IDs 获取用户简要信息") - * - * @GetMapping("/findUserByIds") public Result> - * findUserByIds(@RequestBody List ids) { List userByIds = - * userService.findUserByIds(ids); return Result.success(userByIds); } - */ - }