parent
385b377b10
commit
b06a6da7de
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,32 @@
|
|||||||
|
package com.luojia_channel.modules.user.controller;
|
||||||
|
|
||||||
|
import com.luojia_channel.common.domain.Result;
|
||||||
|
import com.luojia_channel.modules.user.dto.UserChangeInfoDTO;
|
||||||
|
import com.luojia_channel.modules.user.service.UserInfoService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user/info")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserInfoController {
|
||||||
|
private final UserInfoService userInfoService;
|
||||||
|
@PostMapping("/update")
|
||||||
|
public Result<Void> updateInfo(@RequestBody UserChangeInfoDTO userChangeInfoDTO){
|
||||||
|
userInfoService.updateInfo(userChangeInfoDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/password")
|
||||||
|
public Result<Void> updatePassword(@RequestParam String password){
|
||||||
|
userInfoService.updatePassword(password);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/avatar")
|
||||||
|
public Result<Void> updateAvatar(@RequestParam MultipartFile file){
|
||||||
|
// TODO 通过oss存储服务或者minio实现头像更新
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.luojia_channel.modules.user.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserChangeInfoDTO {
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String studentId;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
private Integer gender;
|
||||||
|
|
||||||
|
private String college;
|
||||||
|
}
|
@ -1,7 +1,11 @@
|
|||||||
package com.luojia_channel.modules.user.service;
|
package com.luojia_channel.modules.user.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.luojia_channel.modules.user.dto.UserChangeInfoDTO;
|
||||||
import com.luojia_channel.modules.user.entity.User;
|
import com.luojia_channel.modules.user.entity.User;
|
||||||
|
|
||||||
public interface UserInfoService extends IService<User> {
|
public interface UserInfoService extends IService<User> {
|
||||||
|
void updateInfo(UserChangeInfoDTO userChangeInfoDTO);
|
||||||
|
|
||||||
|
void updatePassword(String password);
|
||||||
}
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.luojia_channel.modules.user.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.crypto.digest.BCrypt;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.luojia_channel.common.exception.UserException;
|
||||||
|
import com.luojia_channel.common.utils.UserContext;
|
||||||
|
import com.luojia_channel.modules.user.dto.UserChangeInfoDTO;
|
||||||
|
import com.luojia_channel.modules.user.entity.User;
|
||||||
|
import com.luojia_channel.modules.user.mapper.UserMapper;
|
||||||
|
import com.luojia_channel.modules.user.service.UserInfoService;
|
||||||
|
|
||||||
|
import com.luojia_channel.modules.user.utils.ValidateParameterUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserInfoServiceImpl extends ServiceImpl<UserMapper, User> implements UserInfoService {
|
||||||
|
|
||||||
|
private final UserMapper userMapper;
|
||||||
|
private final ValidateParameterUtil validateParameterUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateInfo(UserChangeInfoDTO userChangeInfoDTO) {
|
||||||
|
Long userId = UserContext.getUserId();
|
||||||
|
User currentUser = userMapper.selectById(userId);
|
||||||
|
if(currentUser == null){
|
||||||
|
throw new UserException("用户不存在");
|
||||||
|
}
|
||||||
|
validateParameterUtil.validateFormats(userChangeInfoDTO, userId);
|
||||||
|
User user = BeanUtil.copyProperties(userChangeInfoDTO, User.class);
|
||||||
|
user.setId(userId);
|
||||||
|
user.setUpdateTime(LocalDateTime.now());
|
||||||
|
updateById(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePassword(String password) {
|
||||||
|
Long userId = UserContext.getUserId();
|
||||||
|
User user = userMapper.selectById(userId);
|
||||||
|
if(user == null){
|
||||||
|
throw new UserException("用户不存在");
|
||||||
|
}
|
||||||
|
if (!password.matches(ValidateParameterUtil.PASSWORD_REGEX)) {
|
||||||
|
throw new UserException("密码格式不符合要求");
|
||||||
|
}
|
||||||
|
if (BCrypt.checkpw(password, user.getPassword())) {
|
||||||
|
throw new UserException("修改密码不能与原密码相同");
|
||||||
|
}
|
||||||
|
String encodedPassword = BCrypt.hashpw(password, BCrypt.gensalt());
|
||||||
|
user.setPassword(encodedPassword);
|
||||||
|
user.setUpdateTime(LocalDateTime.now());
|
||||||
|
updateById(user);
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
# software_teamwork
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 85 KiB |
Before Width: | Height: | Size: 118 KiB |
Before Width: | Height: | Size: 121 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.6 MiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue