|
|
@@ -10,7 +10,10 @@ import com.fs.common.VerifyCodeUtil;
|
|
|
import com.fs.common.annotation.RepeatSubmit;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.service.ISmsService;
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
+import com.fs.common.utils.ip.IpUtils;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
import com.fs.core.config.WxOpenProperties;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
@@ -669,4 +672,82 @@ public class AppLoginController extends AppBaseController{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/loginByPhone")
|
|
|
+ public R loginByPhone(@RequestBody Map<String,String> map){
|
|
|
+ String phone = map.get("phone");
|
|
|
+ String code = map.get("code");
|
|
|
+ String encryptPhone = encryptPhone(phone);
|
|
|
+ List<FsUser> user = userService.selectFsUserListByPhone(encryptPhone);
|
|
|
+ if (CollectionUtil.isEmpty(user)){
|
|
|
+ user = userService.selectFsUserListByPhone(encryptPhoneOldKey(phone));
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isEmpty(user)){
|
|
|
+ return R.error("此电话号码未绑定用户");
|
|
|
+ }
|
|
|
+ if (user.size()>1){
|
|
|
+ //如果出现了一个手机号多个用户的情况,找出登陆过app的那个用户
|
|
|
+ user.removeIf(fsUser -> StringUtils.isEmpty(fsUser.getHistoryApp()));
|
|
|
+ }
|
|
|
+ String redisCode = redisCache.getCacheObject("sms:code:" + phone);
|
|
|
+ if (StringUtils.isEmpty(redisCode)){
|
|
|
+ return R.error("验证码已过期,请重新发送");
|
|
|
+ }
|
|
|
+ if (!redisCode.equals(code)) {
|
|
|
+ return R.error("验证码错误");
|
|
|
+ }
|
|
|
+ updateExistingUserJpushId(user.get(0), map.get("jpushId"));
|
|
|
+
|
|
|
+ // 更新登录设备信息
|
|
|
+ updateLoginDevice(user.get(0).getUserId(), map.get("loginDevice"), map.get("source"));
|
|
|
+
|
|
|
+ return generateTokenAndReturn(user.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/resetPassword")
|
|
|
+ public R resetPassword(@RequestBody Map<String, String> body){
|
|
|
+ String phone = body.get("phone");
|
|
|
+ String code = body.get("code");
|
|
|
+ String newPassword = body.get("newPassword");
|
|
|
+ String confirmPassword = body.get("confirmPassword");
|
|
|
+ if (!newPassword.equals(confirmPassword)){
|
|
|
+ throw new ServiceException("两次输入密码不一致,请检查");
|
|
|
+ }
|
|
|
+ String encryptPhone = encryptPhone(phone);
|
|
|
+ List<FsUser> user = userService.selectFsUserListByPhone(encryptPhone);
|
|
|
+ if (CollectionUtil.isEmpty(user)){
|
|
|
+ user = userService.selectFsUserListByPhone(encryptPhoneOldKey(phone));
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isEmpty(user)){
|
|
|
+ return R.error("此电话号码未绑定用户");
|
|
|
+ }
|
|
|
+ String redisCode = redisCache.getCacheObject("sms:code:" + phone);
|
|
|
+ if (StringUtils.isEmpty(redisCode)){
|
|
|
+ return R.error("验证码已过期,请重新发送");
|
|
|
+ }
|
|
|
+ if (!redisCode.equals(code)) {
|
|
|
+ return R.error("验证码错误");
|
|
|
+ }
|
|
|
+ String password = Md5Utils.hash(newPassword);
|
|
|
+ return userService.updatePasswordByPhone(password,encryptPhone);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新用户登录设备信息
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @param loginDevice 登录设备
|
|
|
+ * @param source 来源
|
|
|
+ */
|
|
|
+ private void updateLoginDevice(Long userId, String loginDevice, String source) {
|
|
|
+ FsUser updateUser = new FsUser();
|
|
|
+ updateUser.setUserId(userId);
|
|
|
+ if (StringUtils.isNotBlank(loginDevice)) {
|
|
|
+ updateUser.setLoginDevice(loginDevice);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(source)) {
|
|
|
+ updateUser.setSource(source);
|
|
|
+ }
|
|
|
+ updateUser.setLastIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ userService.updateFsUser(updateUser);
|
|
|
+ }
|
|
|
+
|
|
|
}
|