修改app用户信息
This commit is contained in:
@ -77,7 +77,7 @@ public class AppTokenProvider implements InitializingBean {
|
|||||||
// 设置参数
|
// 设置参数
|
||||||
Map<String, Object> claims = new HashMap<>(6);
|
Map<String, Object> claims = new HashMap<>(6);
|
||||||
// 设置用户ID
|
// 设置用户ID
|
||||||
// claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
||||||
// if (user.getAppUser() != null){
|
// if (user.getAppUser() != null){
|
||||||
// claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
// claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
||||||
// }else {
|
// }else {
|
||||||
@ -102,7 +102,7 @@ public class AppTokenProvider implements InitializingBean {
|
|||||||
Map<String, Object> claims = new HashMap<>(6);
|
Map<String, Object> claims = new HashMap<>(6);
|
||||||
|
|
||||||
// 设置用户ID
|
// 设置用户ID
|
||||||
// claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
||||||
// if (user.getAppUser() != null){
|
// if (user.getAppUser() != null){
|
||||||
// claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
// claims.put(AUTHORITIES_UID_KEY, user.getAppUser().getId());
|
||||||
// }else {
|
// }else {
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.fuyuanshen.modules.system.domain.dto.app;
|
||||||
|
|
||||||
|
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: 默苍璃
|
||||||
|
* @date: 2025-06-1818:36
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class APPUpdateUserDTO {
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "ID", hidden = true)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户昵称")
|
||||||
|
private String nickName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "地区")
|
||||||
|
private String region;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户性别")
|
||||||
|
private String gender;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "头像图片")
|
||||||
|
private MultipartFile file;
|
||||||
|
}
|
@ -1,19 +1,7 @@
|
|||||||
package com.fuyuanshen.modules.system.domain.vo;
|
package com.fuyuanshen.modules.system.domain.vo;
|
||||||
|
|
||||||
import com.fuyuanshen.base.BaseEntity;
|
|
||||||
import com.fuyuanshen.modules.system.domain.Dept;
|
|
||||||
import com.fuyuanshen.modules.system.domain.Job;
|
|
||||||
import com.fuyuanshen.modules.system.domain.Role;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: 默苍璃
|
* @author: 默苍璃
|
||||||
@ -22,7 +10,7 @@ import java.util.Set;
|
|||||||
@Data
|
@Data
|
||||||
public class APPUserVo {
|
public class APPUserVo {
|
||||||
|
|
||||||
@ApiModelProperty(value = "ID", hidden = true)
|
@ApiModelProperty(value = "ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ApiModelProperty(value = "用户昵称")
|
@ApiModelProperty(value = "用户昵称")
|
||||||
|
@ -20,8 +20,10 @@ import com.fuyuanshen.annotation.Log;
|
|||||||
import com.fuyuanshen.annotation.rest.AnonymousPostMapping;
|
import com.fuyuanshen.annotation.rest.AnonymousPostMapping;
|
||||||
import com.fuyuanshen.exception.BadRequestException;
|
import com.fuyuanshen.exception.BadRequestException;
|
||||||
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.UserQueryCriteria;
|
import com.fuyuanshen.modules.system.domain.dto.UserQueryCriteria;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPForgotPasswordDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPForgotPasswordDTO;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUpdateUserDTO;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPUserDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUserDTO;
|
||||||
import com.fuyuanshen.modules.system.domain.vo.APPUserVo;
|
import com.fuyuanshen.modules.system.domain.vo.APPUserVo;
|
||||||
import com.fuyuanshen.modules.system.enums.UserType;
|
import com.fuyuanshen.modules.system.enums.UserType;
|
||||||
@ -93,10 +95,9 @@ public class APPUserController {
|
|||||||
|
|
||||||
@Log("发送用户注册验证码")
|
@Log("发送用户注册验证码")
|
||||||
@ApiOperation("发送用户注册验证码")
|
@ApiOperation("发送用户注册验证码")
|
||||||
@PostMapping(value = "/sendRegisterSms")
|
@AnonymousPostMapping(value = "/sendRegisterSms")
|
||||||
@PreAuthorize("@el.check('appUser:edit')")
|
|
||||||
public ResponseVO<String> sendRegisterSms(@Param("phoneNumber") String phoneNumber) throws Exception {
|
public ResponseVO<String> sendRegisterSms(@Param("phoneNumber") String phoneNumber) throws Exception {
|
||||||
appUserService.sendSms(phoneNumber);
|
// appUserService.sendSms(phoneNumber);
|
||||||
return ResponseVO.success("success!!!");
|
return ResponseVO.success("success!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,26 +105,20 @@ public class APPUserController {
|
|||||||
@ApiOperation("修改APP用户")
|
@ApiOperation("修改APP用户")
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@PreAuthorize("@el.check('appUser:edit')")
|
@PreAuthorize("@el.check('appUser:edit')")
|
||||||
public ResponseVO<String> updateUser(@Validated(APPUser.Update.class) @RequestBody APPUser appUser) throws Exception {
|
public ResponseVO<String> updateUser(@Validated @ModelAttribute APPUpdateUserDTO appUser) throws Exception {
|
||||||
Long userId = SecurityUtils.getCurrentUserId();
|
Long userId = SecurityUtils.getCurrentUserId();
|
||||||
if(!userId.equals(appUser.getId())){
|
if(!userId.equals(appUser.getId())){
|
||||||
throw new BadRequestException("不能修改他人资料");
|
throw new BadRequestException("不能修改他人资料");
|
||||||
}
|
}
|
||||||
APPUser updUser= new APPUser();
|
|
||||||
updUser.setId(appUser.getId());
|
appUserService.updateUser(appUser);
|
||||||
updUser.setNickName(appUser.getNickName());
|
|
||||||
updUser.setAvatarPath(appUser.getAvatarPath());
|
|
||||||
updUser.setRegion(appUser.getRegion());
|
|
||||||
updUser.setGender(appUser.getGender());
|
|
||||||
appUserService.updateById(appUser);
|
|
||||||
return ResponseVO.success("success!!!");
|
return ResponseVO.success("success!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Log("忘记密码")
|
@Log("忘记密码")
|
||||||
@ApiOperation("忘记密码")
|
@ApiOperation("忘记密码")
|
||||||
@PostMapping(value = "/forgotPassword")
|
@AnonymousPostMapping(value = "/forgotPassword")
|
||||||
@PreAuthorize("@el.check('appUser:edit')")
|
|
||||||
public ResponseVO<String> forgotPassword(@RequestBody APPForgotPasswordDTO appForgotPasswordDTO) throws Exception {
|
public ResponseVO<String> forgotPassword(@RequestBody APPForgotPasswordDTO appForgotPasswordDTO) throws Exception {
|
||||||
if (!"0000".equals(appForgotPasswordDTO.getVerificationCode())) {
|
if (!"0000".equals(appForgotPasswordDTO.getVerificationCode())) {
|
||||||
throw new BadRequestException("验证码错误");
|
throw new BadRequestException("验证码错误");
|
||||||
@ -134,10 +129,9 @@ public class APPUserController {
|
|||||||
|
|
||||||
@Log("发送忘记密码验证码")
|
@Log("发送忘记密码验证码")
|
||||||
@ApiOperation("发送忘记密码验证码")
|
@ApiOperation("发送忘记密码验证码")
|
||||||
@PostMapping(value = "/sendSms")
|
@AnonymousPostMapping(value = "/sendForgotPasswordSms")
|
||||||
@PreAuthorize("@el.check('appUser:edit')")
|
|
||||||
public ResponseVO<String> sendForgotPasswordSms(@Param("phoneNumber") String phoneNumber) throws Exception {
|
public ResponseVO<String> sendForgotPasswordSms(@Param("phoneNumber") String phoneNumber) throws Exception {
|
||||||
appUserService.sendSms(phoneNumber);
|
// appUserService.sendSms(phoneNumber);
|
||||||
return ResponseVO.success("success!!!");
|
return ResponseVO.success("success!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import com.fuyuanshen.modules.system.domain.Role;
|
|||||||
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.UserQueryCriteria;
|
import com.fuyuanshen.modules.system.domain.dto.UserQueryCriteria;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPForgotPasswordDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPForgotPasswordDTO;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUpdateUserDTO;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPUserDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUserDTO;
|
||||||
import com.fuyuanshen.modules.utils.ResponseVO;
|
import com.fuyuanshen.modules.utils.ResponseVO;
|
||||||
import com.fuyuanshen.utils.PageResult;
|
import com.fuyuanshen.utils.PageResult;
|
||||||
@ -59,4 +60,6 @@ public interface APPUserService extends IService<APPUser> {
|
|||||||
void forgotPassword(APPForgotPasswordDTO appForgotPasswordDTO);
|
void forgotPassword(APPForgotPasswordDTO appForgotPasswordDTO);
|
||||||
|
|
||||||
void sendSms(String phoneNumber);
|
void sendSms(String phoneNumber);
|
||||||
|
|
||||||
|
void updateUser(APPUpdateUserDTO appUser);
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,13 @@ import cn.hutool.core.util.RandomUtil;
|
|||||||
import cn.hutool.crypto.digest.MD5;
|
import cn.hutool.crypto.digest.MD5;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.fuyuanshen.constants.DeviceConstants;
|
||||||
import com.fuyuanshen.exception.BadRequestException;
|
import com.fuyuanshen.exception.BadRequestException;
|
||||||
import com.fuyuanshen.modules.system.domain.Role;
|
import com.fuyuanshen.modules.system.domain.Role;
|
||||||
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
import com.fuyuanshen.modules.system.domain.app.APPUser;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.UserQueryCriteria;
|
import com.fuyuanshen.modules.system.domain.dto.UserQueryCriteria;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPForgotPasswordDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPForgotPasswordDTO;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUpdateUserDTO;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPUserDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUserDTO;
|
||||||
import com.fuyuanshen.modules.system.mapper.app.APPUserMapper;
|
import com.fuyuanshen.modules.system.mapper.app.APPUserMapper;
|
||||||
import com.fuyuanshen.modules.system.service.app.APPUserService;
|
import com.fuyuanshen.modules.system.service.app.APPUserService;
|
||||||
@ -31,9 +33,13 @@ import com.fuyuanshen.modules.utils.ResponseVO;
|
|||||||
import com.fuyuanshen.utils.*;
|
import com.fuyuanshen.utils.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.fuyuanshen.constants.RedisConstants.*;
|
import static com.fuyuanshen.constants.RedisConstants.*;
|
||||||
@ -53,7 +59,16 @@ public class APPUserServiceImpl extends ServiceImpl<APPUserMapper, APPUser> impl
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
|
@Value("${file.app_avatar.pic}")
|
||||||
|
private String filePath;
|
||||||
|
@Value("${file.app_avatar.ip}")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件访问路径前缀
|
||||||
|
*/
|
||||||
|
public static final String FILE_ACCESS_PREFIX = "images";
|
||||||
|
public static final String FILE_AVATAR_PREFIX = "avatar";
|
||||||
/**
|
/**
|
||||||
* 查询APP/小程序用户
|
* 查询APP/小程序用户
|
||||||
*
|
*
|
||||||
@ -83,13 +98,13 @@ public class APPUserServiceImpl extends ServiceImpl<APPUserMapper, APPUser> impl
|
|||||||
throw new BadRequestException("该手机号已被注册");
|
throw new BadRequestException("该手机号已被注册");
|
||||||
}
|
}
|
||||||
|
|
||||||
Object verificationCode = redisUtils.get(APP_REGISTER_SMS_TOKEN + username);
|
/* Object verificationCode = redisUtils.get(APP_REGISTER_SMS_TOKEN + username);
|
||||||
if (verificationCode == null) {
|
if (verificationCode == null) {
|
||||||
throw new BadRequestException("验证码已过期");
|
throw new BadRequestException("验证码已过期");
|
||||||
}
|
}
|
||||||
if(!user.getVerificationCode().equals(verificationCode.toString())){
|
if(!user.getVerificationCode().equals(verificationCode.toString())){
|
||||||
throw new BadRequestException("验证码错误");
|
throw new BadRequestException("验证码错误");
|
||||||
}
|
}*/
|
||||||
APPUser appUser = new APPUser();
|
APPUser appUser = new APPUser();
|
||||||
appUser.setUsername(user.getPhoneNumber());
|
appUser.setUsername(user.getPhoneNumber());
|
||||||
|
|
||||||
@ -142,4 +157,38 @@ public class APPUserServiceImpl extends ServiceImpl<APPUserMapper, APPUser> impl
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateUser(APPUpdateUserDTO appUser) {
|
||||||
|
APPUser updUser= new APPUser();
|
||||||
|
updUser.setId(appUser.getId());
|
||||||
|
updUser.setNickName(appUser.getNickName());
|
||||||
|
try {
|
||||||
|
updUser.setAvatarPath(saveUserAvatarImage(appUser.getFile()));
|
||||||
|
}catch (IOException e){
|
||||||
|
throw new BadRequestException("上传头像失败");
|
||||||
|
}
|
||||||
|
updUser.setRegion(appUser.getRegion());
|
||||||
|
updUser.setGender(appUser.getGender());
|
||||||
|
appUserMapper.updateById(updUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String saveUserAvatarImage(MultipartFile file) throws IOException {
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String originalFileName = file.getOriginalFilename();
|
||||||
|
String fileExtension = originalFileName.substring(originalFileName.lastIndexOf(".") + 1);
|
||||||
|
String newFileName = "PS_" + RandomUtil.randomNumbers(8) + "." + fileExtension;
|
||||||
|
|
||||||
|
File newFile = new File(filePath + FILE_AVATAR_PREFIX + File.separator + newFileName);
|
||||||
|
|
||||||
|
if (!newFile.getParentFile().exists()) {
|
||||||
|
newFile.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
file.transferTo(newFile);
|
||||||
|
|
||||||
|
return ip + DeviceConstants.FILE_ACCESS_PREFIX + "/" + FILE_AVATAR_PREFIX + "/" + newFileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,10 @@ file:
|
|||||||
device:
|
device:
|
||||||
pic: C:\eladmin\file\ #设备图片存储路径
|
pic: C:\eladmin\file\ #设备图片存储路径
|
||||||
ip: http://fuyuanshen.com:81/ #服务器地址
|
ip: http://fuyuanshen.com:81/ #服务器地址
|
||||||
|
app_avatar:
|
||||||
|
pic: C:\eladmin\file\ #设备图片存储路径
|
||||||
|
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||||
|
ip: https://fuyuanshen.com/ #服务器地址
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
|
@ -151,3 +151,7 @@ file:
|
|||||||
pic: /home/eladmin/file/ #设备图片存储路径
|
pic: /home/eladmin/file/ #设备图片存储路径
|
||||||
#ip: http://fuyuanshen.com:81/ #服务器地址
|
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||||
ip: https://fuyuanshen.com/ #服务器地址
|
ip: https://fuyuanshen.com/ #服务器地址
|
||||||
|
app_avatar:
|
||||||
|
pic: /home/eladmin/app_avatar/ #设备图片存储路径
|
||||||
|
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||||
|
ip: https://fuyuanshen.com/ #服务器地址
|
||||||
|
@ -43,6 +43,8 @@ spring:
|
|||||||
multipart:
|
multipart:
|
||||||
max-file-size: 5MB # 设置单个上传文件的最大大小为10MB
|
max-file-size: 5MB # 设置单个上传文件的最大大小为10MB
|
||||||
max-request-size: 5MB
|
max-request-size: 5MB
|
||||||
|
jackson:
|
||||||
|
default-property-inclusion: non_null
|
||||||
# pid:
|
# pid:
|
||||||
# file: /自行指定位置/eladmin.pid
|
# file: /自行指定位置/eladmin.pid
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user