添加发送短信,设置操作密码
This commit is contained in:
@@ -128,6 +128,13 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.21</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<profile>
|
||||
|
||||
@@ -18,12 +18,12 @@ package cn.ysk.cashier.controller;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.pojo.TbUserInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
||||
import cn.ysk.cashier.repository.TbUserInfoRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository;
|
||||
import cn.ysk.cashier.service.TbUserInfoService;
|
||||
import cn.ysk.cashier.dto.TbUserInfoQueryCriteria;
|
||||
import cn.ysk.cashier.utils.JSONUtil;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import cn.ysk.cashier.utils.StringUtil;
|
||||
import cn.ysk.cashier.utils.ValidateCodeUtil;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
@@ -38,6 +38,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -128,4 +129,57 @@ public class TbUserInfoController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
TbMerchantAccountRepository tbMerchantAccountRepository;
|
||||
|
||||
|
||||
@RequestMapping(value = "modfiyUserInfo",method = RequestMethod.POST)
|
||||
public ResponseEntity<Object> modfiyUserInfo(@RequestBody Map<String,String> map){
|
||||
Object o= SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
if(Objects.isNull(o)){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
JSONObject object=JSON.parseObject(JSON.toJSONString(o));
|
||||
if(Objects.isNull(object)){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
String regex="^\\d{11}$";
|
||||
|
||||
if(!object.containsKey("username")||Objects.isNull(object.getString("username"))||
|
||||
!object.getString("username").matches(regex)
|
||||
){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
|
||||
String tempcode="SMS_244665149";
|
||||
String phone=object.getString("username");
|
||||
Object redisCode= redisUtils.get(phone.concat("#").concat(tempcode));
|
||||
if(Objects.isNull(redisCode)){
|
||||
throw new BadRequestException("短信验证码已过期");
|
||||
}
|
||||
|
||||
|
||||
String code= map.get("code");
|
||||
|
||||
if(!redisCode.toString().equals(code)){
|
||||
throw new BadRequestException("短信验证码错误");
|
||||
}
|
||||
redisUtils.del(phone.concat("#").concat(tempcode));
|
||||
String pwd= map.get("pwd");
|
||||
|
||||
TbMerchantAccount account= tbMerchantAccountRepository.findByAccount(phone);
|
||||
if(Objects.isNull(account)){
|
||||
throw new BadRequestException("账户不存在");
|
||||
}
|
||||
|
||||
account.setPwd(MD5Utils.md5(pwd.concat(account.getAccount()).concat(account.getId().toString())));
|
||||
account.setUpdatedAt(System.currentTimeMillis());
|
||||
tbMerchantAccountRepository.save(account);
|
||||
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,10 @@ public class TbMerchantAccount implements Serializable {
|
||||
@ApiModelProperty(value = "updatedAt")
|
||||
private Long updatedAt;
|
||||
|
||||
@Column(name = "`pwd`")
|
||||
@ApiModelProperty(value = "操作密码")
|
||||
private String pwd;
|
||||
|
||||
public void copy(TbMerchantAccount source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
||||
@@ -25,4 +25,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
* @date 2023-11-13
|
||||
**/
|
||||
public interface TbUserInfoRepository extends JpaRepository<TbUserInfo, Integer>, JpaSpecificationExecutor<TbUserInfo> {
|
||||
|
||||
|
||||
}
|
||||
@@ -38,4 +38,7 @@ public interface TbMerchantAccountRepository extends JpaRepository<TbMerchantAcc
|
||||
@Modifying
|
||||
@Query(value = "update tb_merchant_account set password = ?2 , updated_at = ?3 where account = ?1",nativeQuery = true)
|
||||
void updatePass(String account, String password, Long lastPasswordResetTime);
|
||||
|
||||
|
||||
TbMerchantAccount findByAccount(String account);
|
||||
}
|
||||
Reference in New Issue
Block a user