1.add imageCheckCode in sendSms 2.expand userCollect to follow/black_list/thumb_up

main
Gary 1 year ago
parent 9e130d628e
commit ff07475aa3

@ -1,30 +1,30 @@
package enums; package enums;
public enum CollectTypeEnum { public enum CollectTypeEnum {
SONG(0, "歌曲"), JOURNAL(1, "期刊"); SONG(0, "歌曲"), JOURNAL(1, "期刊"), FOLLOW(2, "关注"), BLACK_LIST(3, "黑名单"), THUMB_UP(4, "点赞");
private Integer type; private Integer type;
private String description; private String description;
CollectTypeEnum(int type, String description) { CollectTypeEnum(int type, String description) {
this.type = type; this.type = type;
this.description = description; this.description = description;
} }
public Integer getType() { public Integer getType() {
return type; return type;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public static CollectTypeEnum getByType(Integer type) { public static CollectTypeEnum getByType(Integer type) {
for (CollectTypeEnum at : CollectTypeEnum.values()) { for (CollectTypeEnum at : CollectTypeEnum.values()) {
if (at.type.equals(type)) { if (at.type.equals(type)) {
return at; return at;
} }
} }
return null; return null;
} }
} }

@ -46,8 +46,9 @@ import util.StringTools;
@CrossOrigin @CrossOrigin
@RequestMapping("/user") @RequestMapping("/user")
@Api(tags = "LoginController") @Api(tags = "LoginController")
public class LoginController extends BaseController{ public class LoginController extends BaseController {
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES=Arrays.asList(new CountryCodeDTO("中国","+86")); private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays
.asList(new CountryCodeDTO("中国", "+86"));
@Autowired @Autowired
private UserInfoService userInfoService; private UserInfoService userInfoService;
@ -71,30 +72,44 @@ public class LoginController extends BaseController{
*/ */
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天内最多发送50个请求") @ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天内最多发送50个请求")
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true), @ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
@ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86", required = false, defaultValue="+86"), @ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86", required = false, defaultValue = "+86"),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)}) @ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "imageCheckCode", value = "图形验证码", required = false) })
@PostMapping("/sendsms") @PostMapping("/sendsms")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50) @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50)
public Result<Void> sendSms( public Result<Void> sendSms(@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId, @RequestParam(name = "countryCode", defaultValue = "+86") String countryCode,
@RequestParam(name="countryCode",defaultValue="+86") String countryCode, @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile) { @VerifyParam(required = false) @RequestParam("imageCheckCode") String imageCheckCode) {
userInfoService.sendSms(deviceId,mobile); 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(); return Result.success();
} }
@ApiOperation(value = "2.登录/注册", notes = "成功后返回token") @ApiOperation(value = "2.登录/注册", notes = "成功后返回token")
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true), @ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
@ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true), @ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true), @ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) }) @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
@PostMapping("/appLogin") @PostMapping("/appLogin")
@GlobalInterceptor @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
public Result appLogin(HttpServletRequest request, public Result appLogin(HttpServletRequest request,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile, @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, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId, @VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam("deviceBrand") String deviceBrand) { @RequestParam("deviceBrand") String deviceBrand) {
// 得到缓存中的验证码 // 得到缓存中的验证码
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId; String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId;
try { try {
@ -116,34 +131,30 @@ public class LoginController extends BaseController{
} }
} }
/** /**
* token * token
*/ */
@ApiOperation(value = "3.token续期", notes = "有效期7天") @ApiOperation(value = "3.token续期", notes = "有效期7天")
@ApiImplicitParams({ @ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true), @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
@PostMapping("/autoLogin") @PostMapping("/autoLogin")
@GlobalInterceptor @GlobalInterceptor
public Result<String> autoLogin(HttpServletRequest request,@RequestHeader(value = "token", required = false) String token, public Result<String> autoLogin(HttpServletRequest request,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId, @RequestHeader(value = "token", required = false) String token,
@RequestParam("deviceBrand") String deviceBrand) { @VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
return Result.success(userInfoService.autoLogin(token,deviceId,deviceBrand,getIpAddr(request))); @RequestParam("deviceBrand") String deviceBrand) {
return Result.success(userInfoService.autoLogin(token, deviceId, deviceBrand, getIpAddr(request)));
} }
/** /**
* *
*/ */
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟") @ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@ApiImplicitParams({ @ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true) })
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
@GetMapping("/imageCheckCode/{deviceId}") @GetMapping("/imageCheckCode/{deviceId}")
@GlobalInterceptor @GlobalInterceptor
public void imageCheckCode(HttpServletResponse response, public void imageCheckCode(HttpServletResponse response,
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) @VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
throws IOException {
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10); CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
response.setHeader("Pragma", "no-cache"); response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache"); response.setHeader("Cache-Control", "no-cache");
@ -155,35 +166,12 @@ public class LoginController extends BaseController{
vCode.write(response.getOutputStream()); 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") @GetMapping("/supportedCountryCode")
public Result<List<CountryCodeDTO>> getSupportedCountryCode(){ public Result<List<CountryCodeDTO>> getSupportedCountryCode() {
return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES); return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES);
} }
} }

@ -3,9 +3,7 @@ package com.luoo.user.controller;
import annotation.GlobalInterceptor; import annotation.GlobalInterceptor;
import annotation.VerifyParam; import annotation.VerifyParam;
import api.Result; import api.Result;
import client.vo.SimpleUser;
import com.luoo.user.service.UserCollectService; import com.luoo.user.service.UserCollectService;
import com.luoo.user.service.UserService;
import dto.UserLoginDto; import dto.UserLoginDto;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -15,8 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import util.JwtUtil; import util.JwtUtil;
import java.util.List;
@Api(tags = "UserCollectController") @Api(tags = "UserCollectController")
@RestController @RestController
@RequestMapping("/userCollect") @RequestMapping("/userCollect")
@ -25,12 +21,11 @@ public class UserCollectController {
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@Autowired @Autowired
private UserCollectService userCollectService; private UserCollectService userCollectService;
@Autowired
private UserService userService;
@ApiOperation(value = "1.收藏/喜欢") @ApiOperation(value = "1.喜欢歌曲/收藏期刊/关注/黑名单/点赞")
@ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id此处为歌曲/期刊id", required = true), @ApiImplicitParams({
@ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型0为歌曲1为期刊", required = true) }) @ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@PostMapping("/addCollect") @PostMapping("/addCollect")
@GlobalInterceptor(checkLogin = true) @GlobalInterceptor(checkLogin = true)
public Result<Void> addCollect(@RequestHeader(value = "token", required = false) String token, public Result<Void> addCollect(@RequestHeader(value = "token", required = false) String token,
@ -41,9 +36,10 @@ public class UserCollectController {
return Result.success(); return Result.success();
} }
@ApiOperation(value = "2.取消 收藏/喜欢") @ApiOperation(value = "2.取消 喜欢歌曲/收藏期刊/关注/黑名单/点赞")
@ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id此处为歌曲/期刊id", required = true), @ApiImplicitParams({
@ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型0为歌曲1为期刊", required = true) }) @ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@DeleteMapping("/cancelCollect") @DeleteMapping("/cancelCollect")
@GlobalInterceptor(checkLogin = true) @GlobalInterceptor(checkLogin = true)
public Result<Void> cancelCollect(@RequestHeader(value = "token", required = false) String token, public Result<Void> cancelCollect(@RequestHeader(value = "token", required = false) String token,
@ -54,13 +50,4 @@ public class UserCollectController {
collectType); collectType);
return Result.success(); return Result.success();
} }
/*
* @ApiOperation(value = "根据 IDs 获取用户简要信息")
*
* @GetMapping("/findUserByIds") public Result<List<SimpleUser>>
* findUserByIds(@RequestBody List<String> ids) { List<SimpleUser> userByIds =
* userService.findUserByIds(ids); return Result.success(userByIds); }
*/
} }

Loading…
Cancel
Save