|
@@ -0,0 +1,69 @@
|
|
|
+package com.ynfy.app.api.v1.controller;
|
|
|
+
|
|
|
+import com.ynfy.app.api.v1.annoation.IgnoreAuth;
|
|
|
+import com.ynfy.app.api.v1.entity.dto.UserDTO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
+import org.jeecg.common.util.PasswordUtil;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
+import org.jeecg.modules.system.service.ISysUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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 java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/v1/user")
|
|
|
+@Slf4j
|
|
|
+public class ApiUserController extends ApiBaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户注册
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/register")
|
|
|
+ @IgnoreAuth
|
|
|
+ public Result<?> userRegister(@RequestBody UserDTO dto) {
|
|
|
+ if (StringUtils.isBlank(dto.getUsername())) {
|
|
|
+ throw new JeecgBootException("账号不能为空");
|
|
|
+ }
|
|
|
+ SysUser user1 = sysUserService.getUserByName(dto.getUsername());
|
|
|
+ if (!Objects.isNull(user1)) {
|
|
|
+ return Result.error("账号已被注册");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getPhone())) {
|
|
|
+ SysUser user2 = sysUserService.getUserByPhone(dto.getPhone());
|
|
|
+ if (!Objects.isNull(user2)) {
|
|
|
+ return Result.error("该手机号已被注册");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ user.setCreateTime(new Date());
|
|
|
+ String salt = oConvertUtils.randomGen(8);
|
|
|
+ String passwordEncode = PasswordUtil.encrypt(dto.getUsername(), dto.getPassword(), salt);
|
|
|
+ user.setSalt(salt);
|
|
|
+ user.setUsername(dto.getUsername());
|
|
|
+ user.setRealname(dto.getRealname());
|
|
|
+ user.setAvatar(dto.getAvatar());
|
|
|
+ user.setSex(dto.getSex());
|
|
|
+ user.setPassword(passwordEncode);
|
|
|
+ user.setEmail(dto.getEmail());
|
|
|
+ user.setPhone(dto.getPhone());
|
|
|
+ user.setStatus(CommonConstant.USER_UNFREEZE);
|
|
|
+ user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
+ sysUserService.save(user);
|
|
|
+ return Result.ok("注册成功");
|
|
|
+ }
|
|
|
+}
|