代码提交
parent
3ef1a05250
commit
a869781fb2
|
|
@ -10,6 +10,7 @@ import com.whdc.model.group.Update;
|
|||
import com.whdc.model.vo.AuthToken;
|
||||
import com.whdc.model.vo.LoginVo;
|
||||
import com.whdc.service.IUserService;
|
||||
import com.whdc.service.impl.UserServiceImpl;
|
||||
import com.whdc.utils.ResultJson;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
@ -22,6 +23,8 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.whdc.service.impl.UserServiceImpl.getPassword;
|
||||
|
||||
/**
|
||||
* @author xusan
|
||||
* @date 2024-05-11
|
||||
|
|
@ -148,5 +151,23 @@ public class UserController {
|
|||
return service.updatePwd(dto);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "忘记密码")
|
||||
@GetMapping(value = "forgotPassword/{username}")
|
||||
public ResultJson updatePwd(@PathVariable("username") String username) {
|
||||
User one = service.lambdaQuery().eq(User::getUsername, username)
|
||||
.one();
|
||||
|
||||
if (Objects.isNull(service.getById(one))) {
|
||||
|
||||
return ResultJson.error("当前数据不存在");
|
||||
|
||||
}
|
||||
|
||||
one.setPassword(getPassword(one.getSalt(), UserServiceImpl.DEFAULT_PASSWORD));
|
||||
|
||||
return ResultJson.ok(one.updateById() + " " + UserServiceImpl.DEFAULT_PASSWORD);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.whdc.model.vo.LoginVo;
|
|||
import com.whdc.service.IUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.whdc.utils.ResultJson;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -32,6 +33,7 @@ import java.util.UUID;
|
|||
* @date 2024-05-11
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
|
||||
|
||||
public static final String DEFAULT_PASSWORD = "Fxkh@123456";
|
||||
|
|
@ -129,6 +131,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|||
if (getPassword(sysUser.getSalt() ,dto.getOldPassword()).equals(sysUser.getPassword())) {
|
||||
// 更新密码
|
||||
sysUser.setPassword(getPassword(sysUser.getSalt() ,dto.getNewPassword()));
|
||||
log.info("修改密码" + sysUser.getUsername() + "_" + dto.getNewPassword());
|
||||
return ResultJson.ok(sysUser.updateById());
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +147,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|||
|
||||
}
|
||||
|
||||
private String getPassword(String salt,String password) {
|
||||
public static String getPassword(String salt,String password) {
|
||||
return DigestUtils.md5DigestAsHex((salt + password).getBytes());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue