mirror of
https://github.com/weizhiqiang1995/erp-pro.git
synced 2024-12-26 09:32:33 +08:00
feat: 新增管理端短信验证码登录接口,新增商城的登录管理
This commit is contained in:
parent
1afb576ea6
commit
a06ffe5669
15 changed files with 443 additions and 53 deletions
|
@ -1,49 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.personnel.classenum;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.skyeye.common.base.classenum.SkyeyeEnumClass;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @ClassName: SmsSceneEnum
|
||||
* @Description: 短信场景枚举类
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2024/8/28 20:28
|
||||
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public enum SmsSceneEnum implements SkyeyeEnumClass {
|
||||
|
||||
LOGIN(1, "user-sms-login", "用户 - 手机号登陆", true, false),
|
||||
UPDATE_MOBILE(2, "user-update-mobile", "用户 - 修改绑定的手机", true, false),
|
||||
UPDATE_PASSWORD(3, "user-update-password", "用户 - 修改密码", true, false),
|
||||
RESET_PASSWORD(4, "user-reset-password", "用户 - 忘记密码", true, false);
|
||||
|
||||
private Integer key;
|
||||
|
||||
/**
|
||||
* 模版编码
|
||||
*/
|
||||
private String value;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Boolean show;
|
||||
|
||||
private Boolean isDefault;
|
||||
|
||||
public static SmsSceneEnum getCodeByScene(Integer scene) {
|
||||
return ArrayUtil.firstMatch(sceneEnum -> sceneEnum.getKey().equals(scene),
|
||||
values());
|
||||
}
|
||||
|
||||
}
|
|
@ -77,4 +77,13 @@ public class AppAuthController {
|
|||
appAuthService.sendSmsCode(inputObject, outputObject);
|
||||
}
|
||||
|
||||
@ApiOperation(id = "smsLogin", value = "短信验证码登录", method = "POST", allUse = "0")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(id = "mobile", name = "mobile", value = "手机号", required = "required"),
|
||||
@ApiImplicitParam(id = "smsCode", name = "smsCode", value = "短信验证码", required = "required")})
|
||||
@RequestMapping("/post/AppAuthController/smsLogin")
|
||||
public void smsLogin(InputObject inputObject, OutputObject outputObject) {
|
||||
appAuthService.smsLogin(inputObject, outputObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,4 +19,5 @@ public interface AppAuthService {
|
|||
|
||||
void sendSmsCode(InputObject inputObject, OutputObject outputObject);
|
||||
|
||||
void smsLogin(InputObject inputObject, OutputObject outputObject);
|
||||
}
|
||||
|
|
|
@ -5,14 +5,15 @@
|
|||
package com.skyeye.personnel.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.skyeye.common.enumeration.SmsSceneEnum;
|
||||
import com.skyeye.common.object.InputObject;
|
||||
import com.skyeye.common.object.OutputObject;
|
||||
import com.skyeye.exception.CustomException;
|
||||
import com.skyeye.personnel.classenum.SmsSceneEnum;
|
||||
import com.skyeye.personnel.entity.SysEveUserStaff;
|
||||
import com.skyeye.personnel.service.AppAuthService;
|
||||
import com.skyeye.personnel.service.SysEveUserStaffService;
|
||||
import com.skyeye.sms.entity.SmsCodeSendReq;
|
||||
import com.skyeye.sms.entity.SmsCodeValidateReq;
|
||||
import com.skyeye.sms.service.SmsCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -70,4 +71,17 @@ public class AppAuthServiceImpl implements AppAuthService {
|
|||
smsCodeService.sendSmsCodeReq(smsCodeSendReq);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void smsLogin(InputObject inputObject, OutputObject outputObject) {
|
||||
Map<String, Object> params = inputObject.getParams();
|
||||
String mobile = params.get("mobile").toString();
|
||||
String smsCode = params.get("smsCode").toString();
|
||||
// 校验验证码
|
||||
SmsCodeValidateReq smsCodeValidateReq = new SmsCodeValidateReq();
|
||||
smsCodeValidateReq.setMobile(mobile);
|
||||
smsCodeValidateReq.setSmsCode(smsCode);
|
||||
smsCodeValidateReq.setScene(SmsSceneEnum.LOGIN.getKey());
|
||||
smsCodeService.validateSmsCode(smsCodeValidateReq);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,6 @@ public class SmsCodeValidateReq implements Serializable {
|
|||
private Integer scene;
|
||||
|
||||
@ApiModelProperty(value = "验证码", required = "required")
|
||||
private String code;
|
||||
private String smsCode;
|
||||
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.skyeye.annotation.service.SkyeyeService;
|
||||
import com.skyeye.common.constans.CommonNumConstants;
|
||||
import com.skyeye.common.constans.RedisConstants;
|
||||
import com.skyeye.common.enumeration.SmsSceneEnum;
|
||||
import com.skyeye.common.object.InputObject;
|
||||
import com.skyeye.common.object.OutputObject;
|
||||
import com.skyeye.common.util.DateUtil;
|
||||
import com.skyeye.exception.CustomException;
|
||||
import com.skyeye.jedis.JedisClientService;
|
||||
import com.skyeye.personnel.classenum.SmsSceneEnum;
|
||||
import com.skyeye.sms.core.config.SmsCodeProperties;
|
||||
import com.skyeye.sms.entity.SmsCodeSendReq;
|
||||
import com.skyeye.sms.entity.SmsCodeUseReq;
|
||||
|
@ -126,9 +126,12 @@ public class SmsCodeServiceImpl implements SmsCodeService {
|
|||
@Override
|
||||
public void validateSmsCode(SmsCodeValidateReq smsCodeValidateReq) {
|
||||
String chcheCode = validateSmsCode0(smsCodeValidateReq.getMobile(), smsCodeValidateReq.getScene());
|
||||
if (!StrUtil.equals(chcheCode, smsCodeValidateReq.getCode())) {
|
||||
if (!StrUtil.equals(chcheCode, smsCodeValidateReq.getSmsCode())) {
|
||||
throw new CustomException("验证码错误");
|
||||
}
|
||||
// 验证码使用过后,删除缓存
|
||||
String key = String.format(MOBILE_SMS_CODE, smsCodeValidateReq.getMobile(), smsCodeValidateReq.getScene());
|
||||
jedisClientService.del(key);
|
||||
}
|
||||
|
||||
private String validateSmsCode0(String mobile, Integer scene) {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.rest.sms.rest;
|
||||
|
||||
import com.skyeye.common.client.ClientConfiguration;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: ISmsCodeRest
|
||||
* @Description: 短信验证码接口
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2024/9/16 16:27
|
||||
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@FeignClient(value = "${webroot.skyeye-pro}", configuration = ClientConfiguration.class)
|
||||
public interface ISmsCodeRest {
|
||||
|
||||
@PostMapping("/sendSmsCodeReq")
|
||||
String sendSmsCodeReq(Map<String, Object> params);
|
||||
|
||||
@PostMapping("/validateSmsCode")
|
||||
String validateSmsCode(Map<String, Object> params);
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.rest.sms.service;
|
||||
|
||||
import com.skyeye.base.rest.service.IService;
|
||||
|
||||
/**
|
||||
* @ClassName: ISmsCodeService
|
||||
* @Description: 短信验证码服务接口
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2024/9/16 16:27
|
||||
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
public interface ISmsCodeService extends IService {
|
||||
|
||||
void sendSmsCodeReq(String mobile, Integer scene);
|
||||
|
||||
void validateSmsCode(String mobile, String smsCode, Integer scene);
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.rest.sms.service.impl;
|
||||
|
||||
import com.skyeye.base.rest.service.impl.IServiceImpl;
|
||||
import com.skyeye.common.client.ExecuteFeignClient;
|
||||
import com.skyeye.rest.sms.rest.ISmsCodeRest;
|
||||
import com.skyeye.rest.sms.service.ISmsCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: ISmsCodeServiceImpl
|
||||
* @Description: 短信验证码服务接口实现类
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2024/9/16 16:27
|
||||
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@Service
|
||||
public class ISmsCodeServiceImpl extends IServiceImpl implements ISmsCodeService {
|
||||
|
||||
@Autowired
|
||||
private ISmsCodeRest iSmsCodeRest;
|
||||
|
||||
@Override
|
||||
public void sendSmsCodeReq(String mobile, Integer scene) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("mobile", mobile);
|
||||
params.put("scene", scene);
|
||||
ExecuteFeignClient.get(() -> iSmsCodeRest.sendSmsCodeReq(params)).getRows();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateSmsCode(String mobile, String smsCode, Integer scene) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("mobile", mobile);
|
||||
params.put("smsCode", smsCode);
|
||||
params.put("scene", scene);
|
||||
ExecuteFeignClient.get(() -> iSmsCodeRest.validateSmsCode(params)).getRows();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.controller;
|
||||
|
||||
import com.skyeye.annotation.api.Api;
|
||||
import com.skyeye.annotation.api.ApiImplicitParam;
|
||||
import com.skyeye.annotation.api.ApiImplicitParams;
|
||||
import com.skyeye.annotation.api.ApiOperation;
|
||||
import com.skyeye.common.object.InputObject;
|
||||
import com.skyeye.common.object.OutputObject;
|
||||
import com.skyeye.service.ShopAppAuthService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @ClassName: ShopAppAuthController
|
||||
* @Description: 商城登录管理控制层
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2024/9/16 11:57
|
||||
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@RestController
|
||||
@Api(value = "商城登录管理", tags = "商城登录管理", modelName = "商城登录管理")
|
||||
public class ShopAppAuthController {
|
||||
|
||||
@Autowired
|
||||
private ShopAppAuthService shopAppAuthService;
|
||||
|
||||
@ApiOperation(id = "shopLoginForPC", value = "登录", method = "POST", allUse = "0")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(id = "phone", name = "phone", value = "手机号", required = "required"),
|
||||
@ApiImplicitParam(id = "password", name = "password", value = "密码", required = "required")})
|
||||
@RequestMapping("/post/ShopAppAuthController/shopLoginForPC")
|
||||
public void shopLoginForPC(InputObject inputObject, OutputObject outputObject) {
|
||||
shopAppAuthService.shopLoginForPC(inputObject, outputObject);
|
||||
}
|
||||
|
||||
@ApiOperation(id = "shopLoginForApp", value = "手机端用户登录", method = "POST", allUse = "0")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(id = "phone", name = "phone", value = "手机号", required = "required"),
|
||||
@ApiImplicitParam(id = "password", name = "password", value = "密码", required = "required"),
|
||||
@ApiImplicitParam(id = "cId", name = "cId", value = "cId,用于手机端消息通知")})
|
||||
@RequestMapping("/post/ShopAppAuthController/shopLoginForApp")
|
||||
public void shopLoginForApp(InputObject inputObject, OutputObject outputObject) {
|
||||
shopAppAuthService.shopLoginForApp(inputObject, outputObject);
|
||||
}
|
||||
|
||||
@ApiOperation(id = "shopLogout", value = "退出", method = "POST", allUse = "2")
|
||||
@RequestMapping("/post/ShopAppAuthController/shopLogout")
|
||||
public void shopLogout(InputObject inputObject, OutputObject outputObject) {
|
||||
shopAppAuthService.shopLogout(inputObject, outputObject);
|
||||
}
|
||||
|
||||
@ApiOperation(id = "editShopUserPassword", value = "修改密码", method = "POST", allUse = "2")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(id = "newPassword", name = "newPassword", value = "新密码", required = "required")})
|
||||
@RequestMapping("/post/ShopAppAuthController/editShopUserPassword")
|
||||
public void editShopUserPassword(InputObject inputObject, OutputObject outputObject) {
|
||||
shopAppAuthService.editShopUserPassword(inputObject, outputObject);
|
||||
}
|
||||
|
||||
@ApiOperation(id = "sendShopSmsCode", value = "发送手机验证码", method = "POST", allUse = "0")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(id = "mobile", name = "mobile", value = "手机号"),
|
||||
@ApiImplicitParam(id = "scene", name = "scene", value = "发送场景,参考#SmsSceneEnum", required = "required")})
|
||||
@RequestMapping("/post/ShopAppAuthController/sendShopSmsCode")
|
||||
public void sendShopSmsCode(InputObject inputObject, OutputObject outputObject) {
|
||||
shopAppAuthService.sendShopSmsCode(inputObject, outputObject);
|
||||
}
|
||||
|
||||
@ApiOperation(id = "smsShopLogin", value = "短信验证码登录", method = "POST", allUse = "0")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(id = "mobile", name = "mobile", value = "手机号", required = "required"),
|
||||
@ApiImplicitParam(id = "smsCode", name = "smsCode", value = "短信验证码", required = "required")})
|
||||
@RequestMapping("/post/ShopAppAuthController/smsLsmsShopLoginogin")
|
||||
public void smsShopLogin(InputObject inputObject, OutputObject outputObject) {
|
||||
shopAppAuthService.smsShopLogin(inputObject, outputObject);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.skyeye.annotation.api.ApiModel;
|
||||
import com.skyeye.annotation.api.ApiModelProperty;
|
||||
import com.skyeye.annotation.api.Property;
|
||||
import com.skyeye.annotation.cache.RedisCacheField;
|
||||
import com.skyeye.annotation.unique.UniqueField;
|
||||
import com.skyeye.common.base.handler.enclosure.bean.Enclosure;
|
||||
|
@ -48,6 +49,18 @@ public class Member extends AreaInfo implements EnclosureFace {
|
|||
@ApiModelProperty(value = "联系电话", required = "required,phone")
|
||||
private String phone;
|
||||
|
||||
@TableField("password")
|
||||
@ApiModelProperty(value = "密码")
|
||||
private String password;
|
||||
|
||||
@TableField("pwd_num_enc")
|
||||
@Property(value = "用户密码加密次数")
|
||||
private Integer pwdNumEnc;
|
||||
|
||||
@TableField("wechat_open_id")
|
||||
@ApiModelProperty(value = "微信的openId")
|
||||
private String wechatOpenId;
|
||||
|
||||
@TableField(value = "email")
|
||||
@ApiModelProperty(value = "电子邮箱", required = "email")
|
||||
private String email;
|
||||
|
@ -66,4 +79,9 @@ public class Member extends AreaInfo implements EnclosureFace {
|
|||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "附件", required = "json")
|
||||
private Enclosure enclosureInfo;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Property(value = "用户token")
|
||||
private String userToken;
|
||||
|
||||
}
|
||||
|
|
|
@ -21,4 +21,7 @@ public interface MemberService extends SkyeyeBusinessService<Member> {
|
|||
|
||||
void queryMyWriteMemberList(InputObject inputObject, OutputObject outputObject);
|
||||
|
||||
Member queryMemberByPhone(String phone);
|
||||
|
||||
void editMemberPassword(String userId, String newPassword, int pwdNum);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.service;
|
||||
|
||||
import com.skyeye.common.object.InputObject;
|
||||
import com.skyeye.common.object.OutputObject;
|
||||
|
||||
/**
|
||||
* @ClassName: ShopAppAuthService
|
||||
* @Description: 商城登录管理服务接口层
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2024/9/16 11:57
|
||||
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
public interface ShopAppAuthService {
|
||||
|
||||
void shopLoginForPC(InputObject inputObject, OutputObject outputObject);
|
||||
|
||||
void shopLoginForApp(InputObject inputObject, OutputObject outputObject);
|
||||
|
||||
void shopLogout(InputObject inputObject, OutputObject outputObject);
|
||||
|
||||
void editShopUserPassword(InputObject inputObject, OutputObject outputObject);
|
||||
|
||||
void sendShopSmsCode(InputObject inputObject, OutputObject outputObject);
|
||||
|
||||
void smsShopLogin(InputObject inputObject, OutputObject outputObject);
|
||||
}
|
|
@ -4,15 +4,19 @@
|
|||
|
||||
package com.skyeye.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.skyeye.annotation.service.SkyeyeService;
|
||||
import com.skyeye.base.business.service.impl.SkyeyeBusinessServiceImpl;
|
||||
import com.skyeye.common.constans.CommonConstants;
|
||||
import com.skyeye.common.entity.search.CommonPageInfo;
|
||||
import com.skyeye.common.enumeration.DeleteFlagEnum;
|
||||
import com.skyeye.common.object.InputObject;
|
||||
import com.skyeye.common.object.OutputObject;
|
||||
import com.skyeye.common.util.CharUtil;
|
||||
import com.skyeye.common.util.mybatisplus.MybatisPlusUtil;
|
||||
import com.skyeye.dao.MemberDao;
|
||||
import com.skyeye.entity.Member;
|
||||
import com.skyeye.eve.service.IAreaService;
|
||||
|
@ -54,6 +58,10 @@ public class MemberServiceImpl extends SkyeyeBusinessServiceImpl<MemberDao, Memb
|
|||
@Override
|
||||
public void updatePrepose(Member entity) {
|
||||
setMemberMation(entity);
|
||||
Member oldMember = selectById(entity.getId());
|
||||
entity.setPassword(oldMember.getPassword());
|
||||
entity.setWechatOpenId(oldMember.getWechatOpenId());
|
||||
entity.setPwdNumEnc(oldMember.getPwdNumEnc());
|
||||
}
|
||||
|
||||
private void setMemberMation(Member entity) {
|
||||
|
@ -89,4 +97,22 @@ public class MemberServiceImpl extends SkyeyeBusinessServiceImpl<MemberDao, Memb
|
|||
outputObject.settotal(pages.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member queryMemberByPhone(String phone) {
|
||||
QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(MybatisPlusUtil.toColumns(Member::getPhone), phone);
|
||||
queryWrapper.eq(MybatisPlusUtil.toColumns(Member::getDeleteFlag), DeleteFlagEnum.NOT_DELETE.getKey());
|
||||
Member member = getOne(queryWrapper, false);
|
||||
return member;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editMemberPassword(String userId, String newPassword, int pwdNum) {
|
||||
UpdateWrapper<Member> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq(CommonConstants.ID, userId);
|
||||
updateWrapper.set(MybatisPlusUtil.toColumns(Member::getPassword), newPassword);
|
||||
updateWrapper.set(MybatisPlusUtil.toColumns(Member::getPwdNumEnc), pwdNum);
|
||||
update(updateWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
|
||||
******************************************************************************/
|
||||
|
||||
package com.skyeye.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.skyeye.common.constans.CommonNumConstants;
|
||||
import com.skyeye.common.constans.SysUserAuthConstants;
|
||||
import com.skyeye.common.enumeration.RequestType;
|
||||
import com.skyeye.common.enumeration.SmsSceneEnum;
|
||||
import com.skyeye.common.object.GetUserToken;
|
||||
import com.skyeye.common.object.InputObject;
|
||||
import com.skyeye.common.object.OutputObject;
|
||||
import com.skyeye.common.object.PutObject;
|
||||
import com.skyeye.common.util.ToolUtil;
|
||||
import com.skyeye.entity.Member;
|
||||
import com.skyeye.exception.CustomException;
|
||||
import com.skyeye.rest.sms.service.ISmsCodeService;
|
||||
import com.skyeye.service.MemberService;
|
||||
import com.skyeye.service.ShopAppAuthService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: ShopAppAuthServiceImpl
|
||||
* @Description: 商城登录管理服务层
|
||||
* @author: skyeye云系列--卫志强
|
||||
* @date: 2024/9/16 11:57
|
||||
* @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
|
||||
* 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
|
||||
*/
|
||||
@Service
|
||||
public class ShopAppAuthServiceImpl implements ShopAppAuthService {
|
||||
|
||||
@Autowired
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private ISmsCodeService iSmsCodeService;
|
||||
|
||||
@Override
|
||||
public void shopLoginForPC(InputObject inputObject, OutputObject outputObject) {
|
||||
Map<String, Object> map = inputObject.getParams();
|
||||
Member member = login(map, RequestType.PC.getKey());
|
||||
outputObject.setBean(member);
|
||||
outputObject.settotal(CommonNumConstants.NUM_ONE);
|
||||
}
|
||||
|
||||
private Member login(Map<String, Object> map, String requestType) {
|
||||
String phone = map.get("phone").toString();
|
||||
Member member = memberService.queryMemberByPhone(phone);
|
||||
if (ObjectUtil.isEmpty(member)) {
|
||||
throw new CustomException("手机号码不存在,请先注册!");
|
||||
}
|
||||
String password = map.get("password").toString();
|
||||
for (int i = 0; i < member.getPwdNumEnc(); i++) {
|
||||
password = ToolUtil.MD5(password);
|
||||
}
|
||||
if (!StrUtil.equals(password, member.getPassword())) {
|
||||
throw new CustomException("密码错误!");
|
||||
}
|
||||
SysUserAuthConstants.setUserLoginRedisCache(member.getId(), BeanUtil.beanToMap(member));
|
||||
String userToken;
|
||||
if (RequestType.APP.getKey().equals(requestType)) {
|
||||
userToken = GetUserToken.createNewToken(member.getId() + SysUserAuthConstants.APP_IDENTIFYING, password);
|
||||
} else {
|
||||
userToken = GetUserToken.createNewToken(member.getId(), password);
|
||||
}
|
||||
member.setPassword(null);
|
||||
member.setPwdNumEnc(null);
|
||||
member.setUserToken(userToken);
|
||||
return member;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shopLoginForApp(InputObject inputObject, OutputObject outputObject) {
|
||||
Map<String, Object> map = inputObject.getParams();
|
||||
Member member = login(map, RequestType.APP.getKey());
|
||||
outputObject.setBean(member);
|
||||
outputObject.settotal(CommonNumConstants.NUM_ONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shopLogout(InputObject inputObject, OutputObject outputObject) {
|
||||
String userId = GetUserToken.getUserTokenUserId(PutObject.getRequest());
|
||||
SysUserAuthConstants.delUserLoginRedisCache(userId);
|
||||
inputObject.removeSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editShopUserPassword(InputObject inputObject, OutputObject outputObject) {
|
||||
Map<String, Object> map = inputObject.getParams();
|
||||
String newPassword = map.get("newPassword").toString();
|
||||
String userId = inputObject.getLogParams().get("id").toString();
|
||||
int pwdNum = (int) (Math.random() * 100);
|
||||
for (int i = 0; i < pwdNum; i++) {
|
||||
newPassword = ToolUtil.MD5(newPassword);
|
||||
}
|
||||
memberService.editMemberPassword(userId, newPassword, pwdNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendShopSmsCode(InputObject inputObject, OutputObject outputObject) {
|
||||
Map<String, Object> params = inputObject.getParams();
|
||||
String mobile = params.get("mobile").toString();
|
||||
Integer scene = Integer.parseInt(params.get("scene").toString());
|
||||
// 情况 1:如果是修改手机场景,需要校验新手机号是否已经注册,说明不能使用该手机了
|
||||
if (scene == SmsSceneEnum.UPDATE_MOBILE.getKey()) {
|
||||
Member member = memberService.queryMemberByPhone(mobile);
|
||||
if (ObjectUtil.isNotEmpty(member)) {
|
||||
throw new CustomException("手机号已经被使用");
|
||||
}
|
||||
}
|
||||
// 情况 2:如果是重置密码场景,需要校验手机号是存在的
|
||||
if (scene == SmsSceneEnum.RESET_PASSWORD.getKey()) {
|
||||
Member member = memberService.queryMemberByPhone(mobile);
|
||||
if (ObjectUtil.isEmpty(member)) {
|
||||
throw new CustomException("手机号不存在");
|
||||
}
|
||||
}
|
||||
// 情况 3:如果是修改密码场景,需要查询手机号,无需前端传递
|
||||
if (scene == SmsSceneEnum.UPDATE_PASSWORD.getKey()) {
|
||||
String id = inputObject.getLogParams().get("id").toString();
|
||||
Member member = memberService.selectById(id);
|
||||
if (StrUtil.isEmpty(member.getPhone())) {
|
||||
throw new CustomException("您还没有绑定手机号,请先绑定手机号");
|
||||
}
|
||||
mobile = member.getPhone();
|
||||
}
|
||||
if (StrUtil.isEmpty(mobile)) {
|
||||
throw new CustomException("手机号不能为空");
|
||||
}
|
||||
// 发送短信验证码
|
||||
iSmsCodeService.sendSmsCodeReq(mobile, scene);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void smsShopLogin(InputObject inputObject, OutputObject outputObject) {
|
||||
Map<String, Object> params = inputObject.getParams();
|
||||
String mobile = params.get("mobile").toString();
|
||||
String smsCode = params.get("smsCode").toString();
|
||||
// 校验验证码
|
||||
iSmsCodeService.validateSmsCode(mobile, smsCode, SmsSceneEnum.LOGIN.getKey());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue