修改店铺登录密码

This commit is contained in:
wangw 2024-03-08 19:59:51 +08:00
parent 3b59b87cf5
commit 1eef8f2c5c
7 changed files with 88 additions and 23 deletions

View File

@ -34,6 +34,8 @@
#### 问题记录
- 手动修改密码
- token生成 地址 TokenProvider.createToken
- OnlineUserService.save token保存地址
原文:[123456]()

View File

@ -16,26 +16,30 @@
package cn.ysk.cashier.controller.shop;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.service.shop.TbShopInfoService;
import cn.ysk.cashier.config.security.security.TokenProvider;
import cn.ysk.cashier.config.security.service.OnlineUserService;
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
import org.springframework.data.domain.Pageable;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.service.shop.TbShopInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
/**
* @website https://eladmin.vip
* @author lyf
* @date 2023-11-07
**/
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "/shop/list管理")
@ -43,6 +47,8 @@ import javax.servlet.http.HttpServletResponse;
public class TbShopInfoController {
private final TbShopInfoService tbShopInfoService;
private final OnlineUserService onlineUserService;
private final TokenProvider tokenProvider;
// @Log("导出数据")
// @ApiOperation("导出数据")
@ -75,6 +81,16 @@ public class TbShopInfoController {
return new ResponseEntity<>(tbShopInfoService.create(resources),HttpStatus.CREATED);
}
@ApiOperation("修改商户密码")
@PostMapping(value = "/shop/upPass")
public ResponseEntity<Object> upShopPass(HttpServletRequest request, @RequestBody String username,String password) throws Exception {
tbShopInfoService.upShopPass(username,password);
//根据token踢出用户
// onlineUserService.logout(tokenProvider.getToken(request));
log.info("修改商户密码成功。");
return new ResponseEntity<>(HttpStatus.OK);
}
@PutMapping
@Log("修改/shop/list")
@ApiOperation("修改/shop/list")

View File

@ -18,6 +18,8 @@ package cn.ysk.cashier.repository.shop;
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/**
* @website https://eladmin.vip
@ -25,4 +27,15 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2024-02-08
**/
public interface TbMerchantAccountRepository extends JpaRepository<TbMerchantAccount, Integer>, JpaSpecificationExecutor<TbMerchantAccount> {
/**
* 修改密码
* @param account 用户名
* @param password 密码
* @param lastPasswordResetTime 更新时间
* @param lastPasswordResetTime /
*/
@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);
}

View File

@ -18,6 +18,8 @@ package cn.ysk.cashier.repository.shop;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/**
* @website https://eladmin.vip
@ -25,4 +27,16 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2024-03-01
**/
public interface TbPlussShopStaffRepository extends JpaRepository<TbPlussShopStaff, Integer>, JpaSpecificationExecutor<TbPlussShopStaff> {
/**
* 修改密码
* @param account 用户名
* @param password 密码
* @param lastPasswordResetTime 更新时间
* @param lastPasswordResetTime /
*/
@Modifying
// @Query(value = "update tb_pluss_shop_staff set password = ?2 , updated_at = ?3 where account = ?1",nativeQuery = true)
@Query("update TbPlussShopStaff set password = :password , updatedAt = :lastPasswordResetTime where account = :account")
void updatePass(String account, String password, Long lastPasswordResetTime);
}

View File

@ -69,7 +69,6 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
//找到子分类
List<TbShopCategory> children = tbShopCategoryRepository.findChildren(treeId);
if (children.isEmpty()){
log.info("子类为空,{}", FastJsonUtils.toJSONString(treeId));
return PageUtil.toPage(page.map(tbShopCategoryMapper::toDto));
}
@ -86,11 +85,9 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
BeanUtils.copyProperties(category, tbShopCategoryDto);
dto.add(tbShopCategoryDto);
}
log.info("过滤前,{}", FastJsonUtils.toJSONString(dto));
List<TbShopCategoryDto> result = dto.stream()
.filter(d -> d.getTree()==null || d.getId().equals(d.getTree()))
.collect(Collectors.toList());
log.info("过滤后,{}", FastJsonUtils.toJSONString(result));
return PageUtil.toPage(result, page.getTotalElements()-children.size());
}

View File

@ -15,41 +15,44 @@
*/
package cn.ysk.cashier.service.impl.shopimpl;
import cn.ysk.cashier.config.security.security.TokenProvider;
import cn.ysk.cashier.config.security.service.UserCacheManager;
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.pojo.product.TbShopCategory;
import cn.ysk.cashier.exception.EntityNotFoundException;
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.pojo.shop.TbMerchantRegister;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository;
import cn.ysk.cashier.repository.shop.TbMerchantRegisterRepository;
import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository;
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
import cn.ysk.cashier.service.shop.TbShopInfoService;
import cn.ysk.cashier.system.domain.Dept;
import cn.ysk.cashier.system.domain.Job;
import cn.ysk.cashier.system.domain.Role;
import cn.ysk.cashier.system.domain.User;
import cn.ysk.cashier.system.repository.UserRepository;
import cn.ysk.cashier.system.service.UserService;
import cn.ysk.cashier.utils.*;
import lombok.RequiredArgsConstructor;
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
import cn.ysk.cashier.service.shop.TbShopInfoService;
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.time.Instant;
import java.util.*;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
/**
* @website https://eladmin.vip
@ -69,6 +72,11 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
private final UserRepository userRepository;
private final UserService userService;
private final UserCacheManager userCacheManager;
private final TokenProvider tokenProvider;
private final TbMerchantRegisterRepository merchantRegisterRepository;
private final PasswordEncoder passwordEncoder;
@ -214,6 +222,19 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
return tbShopInfoMapper.toDto(new TbShopInfo());
}
@Override
@Transactional
public void upShopPass(String username,String password){
User user = userRepository.findByUsername(username);
if (user == null) {
throw new EntityNotFoundException(User.class, "username", username);
}
String encPass = MD5Utils.encrypt(password);
shopStaffRepository.updatePass(username,encPass,System.currentTimeMillis());
merchantAccountRepository.updatePass(username,encPass,System.currentTimeMillis());
userService.updatePass(username,passwordEncoder.encode(passwordEncoder.encode(password)));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbShopInfo resources) {

View File

@ -62,6 +62,8 @@ public interface TbShopInfoService {
*/
TbShopInfoDto create(TbShopInfoDto resources);
void upShopPass(String username,String password) throws Exception ;
/**
* 编辑
* @param resources /