|
@@ -1,16 +1,21 @@
|
|
|
package com.care.keeper.controller;
|
|
|
|
|
|
+import com.care.common.entity.CareSysUser;
|
|
|
+import com.care.common.service.CareSysUserService;
|
|
|
import com.care.keeper.service.KeeperPassportService;
|
|
|
import com.care.keeper.vo.KeeperInitParams;
|
|
|
+import com.care.common.service.SmsSendService;
|
|
|
import com.care.common.util.CheckUtils;
|
|
|
import com.care.common.util.Result;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.annotations.ApiParam;
|
|
|
+import com.google.common.cache.Cache;
|
|
|
+import com.google.common.cache.CacheBuilder;
|
|
|
+import io.swagger.annotations.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Api(tags = "登录")
|
|
|
@RestController
|
|
@@ -20,8 +25,14 @@ public class KeeperPassportController {
|
|
|
|
|
|
@Resource
|
|
|
private KeeperPassportService keeperPassportService;
|
|
|
+ @Resource
|
|
|
+ private SmsSendService smsSendService;
|
|
|
+ @Resource
|
|
|
+ private CareSysUserService careSysUserService;
|
|
|
|
|
|
- @ApiOperation(value = "小程序登录", notes = "小程序授权登录")
|
|
|
+ public final Cache<String, String> smsTimeoutCache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
|
|
|
+
|
|
|
+ @ApiOperation(value = "管家小程序登录", notes = "管家小程序登录,微信登录传参:loginType=wx,code; 密码登录:loginType=pwd, phone, password")
|
|
|
@ApiParam(name = "params", value = "登录参数")
|
|
|
@PostMapping("login")
|
|
|
public Result<Object> login(@RequestBody KeeperInitParams params) {
|
|
@@ -40,6 +51,97 @@ public class KeeperPassportController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @ApiOperation(value = "管家小程序登录", notes = "微信登录解密手机号 --二期新增")
|
|
|
+ @PostMapping("decodePhoneNumber")
|
|
|
+ public Result<Object> decodePhoneNumber(@RequestParam(value = "code", required = true) String code,
|
|
|
+ @RequestParam(value = "encryptedData", required = true) String encryptedData,
|
|
|
+ @RequestParam(value = "iv", required = true) String iv) {
|
|
|
+ if (keeperPassportService.decodePhoneNumber(code,encryptedData,iv)){
|
|
|
+ return Result.success();
|
|
|
+ } else {
|
|
|
+ return Result.error("失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ @ApiOperation(value = " 获取验证码", notes = "获取验证码 --二期新增")
|
|
|
+ @GetMapping("getVCode")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "phone", value = "电话号码"),
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "type", value = "类型:1手机号注册,2密码重置,3修改注册手机号"),
|
|
|
+ })
|
|
|
+ public Result<String> getVCode(@RequestParam(value = "phone", required = true) String phone,
|
|
|
+ @RequestParam(value = "type", required = true) String type) {
|
|
|
+
|
|
|
+ String vcode = String.format("%04d",new Random().nextInt(9999));
|
|
|
+ boolean flag = false;
|
|
|
+ if("1".equals(type)){
|
|
|
+ flag = smsSendService.sendSmsCode4RegisterPhone(phone, vcode);
|
|
|
+ } else if("2".equals(type)){
|
|
|
+ flag = smsSendService.sendSmsCode4ModifyPassword(phone, vcode);
|
|
|
+ } else if("3".equals(type)){
|
|
|
+ flag = smsSendService.sendSmsCode4ModifyPhone(phone, vcode);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ smsTimeoutCache.put(phone, vcode);
|
|
|
+ return Result.success();
|
|
|
+ } else {
|
|
|
+ return Result.error("获取验证码失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "校验验证码", notes = "校验验证码 --二期新增")
|
|
|
+ @GetMapping("checkVCode")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "phone", value = "电话号码"),
|
|
|
+ })
|
|
|
+ public Result<String> checkVCode(@RequestParam(value = "phone", required = true) String phone,
|
|
|
+ @RequestParam(value = "vcode", required = true) String vcode) {
|
|
|
+ if(StringUtils.equalsIgnoreCase(vcode, smsTimeoutCache.getIfPresent(phone))){
|
|
|
+ return Result.success();
|
|
|
+ } else {
|
|
|
+ return Result.error("请输入正确的验证码");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "设置新密码", notes = "设置新密码, 传值:手机号,密码,确认密码,验证码")
|
|
|
+ @ApiParam(name = "params", value = "登录参数")
|
|
|
+ @PostMapping("changePwd")
|
|
|
+ public Result<Object> changePwd(@RequestBody KeeperInitParams params) {
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(params.getPhone())) {
|
|
|
+ return Result.error("手机号码不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(params.getPassword())) {
|
|
|
+ return Result.error("请输入密码");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(params.getPasswordAgain())) {
|
|
|
+ return Result.error("请再次输入密码");
|
|
|
+ }
|
|
|
+ if (!params.getPassword().equals(params.getPasswordAgain())) {
|
|
|
+ return Result.error("两次输入密码不一致");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(params.getVcode())) {
|
|
|
+ return Result.error("验证码不能为空");
|
|
|
+ }
|
|
|
+ if (!StringUtils.equalsIgnoreCase(params.getVcode(), smsTimeoutCache.getIfPresent(params.getPhone()))) {
|
|
|
+ return Result.error("验证码无效");
|
|
|
+ }
|
|
|
+ CareSysUser careSysUser = careSysUserService.detailByPhone4Keeper(params.getPhone());
|
|
|
+ if (careSysUser == null) {
|
|
|
+ return Result.error("该手机号未注册");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean flag = keeperPassportService.changePwd(params.getPassword(), careSysUser.getId());
|
|
|
+ if (flag) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.error("设置新密码失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@ApiOperation(value = "小程序登出", notes = "小程序登出")
|
|
|
@PostMapping("logout")
|
|
|
public Result<Object> logout(@RequestHeader String token) {
|