Commit 49a8fc46 by 张晋雄

用户基本信息

parent c5372948
package cn.meteor.beyondclouds.modules.user.api;
import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.annotation.CurrentSubject;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.bean.Subject;
import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.exception.UserServiceException;
import cn.meteor.beyondclouds.modules.user.form.UserBaseinfoFrom;
import cn.meteor.beyondclouds.modules.user.form.UserRegisterFrom;
import cn.meteor.beyondclouds.modules.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
......@@ -22,7 +23,7 @@ import javax.validation.Valid;
@Api(tags = "用户Api")
@RestController
@RequestMapping("/api/user")
@RequestMapping("/api")
public class UserApi {
private IUserService userService;
......@@ -34,7 +35,7 @@ public class UserApi {
@Anonymous
@ApiOperation("用户注册")
@PostMapping("/register/mobile")
@PostMapping("/user/register/mobile")
public Response register(@RequestBody @Valid UserRegisterFrom registerFrom, BindingResult result) {
if (result.hasErrors()) {
......@@ -50,5 +51,51 @@ public class UserApi {
}
}
@ApiOperation("修改我的基本信息")
@PutMapping("/my/baseinfo")
public Response alterBaseinfo(@RequestBody @Valid UserBaseinfoFrom userBaseinfoFrom, BindingResult result,
@CurrentSubject Subject subject){
if (result.hasErrors()) {
return Response.fieldError(result.getFieldError());
}
userService.alterBaseinfo(userBaseinfoFrom.getNickName(),userBaseinfoFrom.getUserAvatar(),
userBaseinfoFrom.getGender(),userBaseinfoFrom.getMobile(),userBaseinfoFrom.getSignature(),
userBaseinfoFrom.getQqNumber(),userBaseinfoFrom.getWxNumber(), String.valueOf(subject.getId()));
return Response.success();
}
@Anonymous
@ApiOperation("修改密码")
@PutMapping("/my/password")
public Response alterPassword(@RequestBody @Valid UserRegisterFrom registerFrom, BindingResult result){
if (result.hasErrors()) {
return Response.fieldError(result.getFieldError());
}
try {
userService.alterPassword(registerFrom.getMobile(), registerFrom.getPassword(), registerFrom.getVerifyCode());
return Response.success();
} catch (UserServiceException e) {
e.printStackTrace();
return Response.error(e);
}
}
@ApiOperation(("获取我的基本信息"))
@GetMapping("/my/baseinfo")
public Response myBaseinfo(@CurrentSubject Subject subject){
return Response.success(userService.myBaseinfo(String.valueOf(subject.getId())));
}
@ApiOperation(("获取他人基本信息"))
@GetMapping("/user/{userId}/baseinfo")
public Response otherBaseinfo(@PathVariable(name = "userId") String userId ){
return Response.success(userService.otherBaseinfo(userId));
}
}
package cn.meteor.beyondclouds.modules.user.form;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @program: beyond-clouds
* @description: 用户信息表
* @author: Mr.Zhang
* @create: 2020-01-31 11:41
**/
@Data
@ApiModel("用户信息表")
public class UserBaseinfoFrom {
private String nickName;
private String userAvatar;
private Integer gender;
private String signature;
private String mobile;
private String wxNumber;
private String qqNumber;
}
......@@ -4,6 +4,8 @@ import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.exception.UserServiceException;
import com.baomidou.mybatisplus.extension.service.IService;
import java.io.Serializable;
/**
* @author meteor
*/
......@@ -32,4 +34,12 @@ public interface IUserService extends IService<User> {
* @param nickName
*/
void updateNickName(String userId, String nickName);
void alterBaseinfo(String nickName, String userAvatar, Integer gender, String mobile, String signature, String qqNumber, String wxNumber, String id);
void alterPassword(String mobile, String password, String verifyCode) throws UserServiceException;
User myBaseinfo(String id);
User otherBaseinfo(String nickName);
}
......@@ -17,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.Serializable;
/**
* @author meteor
*/
......@@ -85,4 +87,55 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
updateWrapper.set("nick_name", nickName);
update(updateWrapper);
}
@Override
public void alterBaseinfo(String nickName, String userAvatar, Integer gender, String mobile, String signature, String qqNumber, String wxNumber, String id) {
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.eq("user_id",id);
updateWrapper.set("nick_name", nickName);
updateWrapper.set("user_avatar", userAvatar);
updateWrapper.set("gender", gender);
updateWrapper.set("signature", signature);
updateWrapper.set("mobile", mobile);
updateWrapper.set("wx_number", wxNumber);
updateWrapper.set("qq_number", qqNumber);
update(updateWrapper);
}
@Override
public void alterPassword(String mobile, String password, String verifyCode) throws UserServiceException {
//1.检查验证码是否正确
String realVerifyCode = redisHelper.get(RedisKey.VERIFY_CODE_KEY(mobile));
if (StringUtils.isEmpty(realVerifyCode) || !realVerifyCode.equals(verifyCode)) {
throw new UserServiceException(UserErrorCode.REG_VERIFY_CODE_ERROR);
}
// 删除验证码
redisHelper.del(RedisKey.VERIFY_CODE_KEY(mobile));
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.set("password", Md5Utils.encode(password));
updateWrapper.eq("mobile", mobile);
userAuthLocalService.update(updateWrapper);
}
@Override
public User myBaseinfo(String userId) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
System.out.println(userId);
return getOne(queryWrapper);
}
@Override
public User otherBaseinfo(String userId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
return getOne(queryWrapper);
}
}
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 100Centa30821%mysql
password: 2018006709
swagger:
enable: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment