saas1提交
parent
6d682e1423
commit
262899c57e
|
@ -66,7 +66,7 @@ public class TokenController {
|
|||
@PostMapping("register")
|
||||
public Result<?> register (@RequestBody RegisterBody registerBody) {
|
||||
// 用户注册
|
||||
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
||||
sysLoginService.register(registerBody);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,6 @@ package com.muyu.auth.form;
|
|||
*/
|
||||
public class LoginBody {
|
||||
|
||||
/**
|
||||
* 登录公司名称
|
||||
*/
|
||||
private Integer firmName;
|
||||
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
|
|
@ -1,10 +1,35 @@
|
|||
package com.muyu.auth.form;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 用户注册对象
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class RegisterBody extends LoginBody {
|
||||
/**
|
||||
* 公司名称
|
||||
*/
|
||||
private String firmName;
|
||||
|
||||
/**
|
||||
* 邮件地址
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phoneNumber;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.auth.service;
|
||||
|
||||
import com.muyu.auth.form.RegisterBody;
|
||||
import com.muyu.common.core.constant.CacheConstants;
|
||||
import com.muyu.common.core.constant.Constants;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
|
@ -12,6 +13,8 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.ip.IpUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.remote.RemoteFirmService;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
|
@ -28,6 +31,9 @@ public class SysLoginService {
|
|||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Autowired
|
||||
private RemoteFirmService remoteFirmService;
|
||||
|
||||
@Autowired
|
||||
private SysPasswordService passwordService;
|
||||
|
||||
|
@ -98,31 +104,39 @@ public class SysLoginService {
|
|||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void register (String username, String password) {
|
||||
public void register (RegisterBody registerBody) {
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password)) {
|
||||
if (StringUtils.isAnyBlank(registerBody.getUsername(), registerBody.getPassword())) {
|
||||
throw new ServiceException("用户/密码必须填写");
|
||||
}
|
||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
||||
if (registerBody.getUsername().length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| registerBody.getUsername().length() > UserConstants.USERNAME_MAX_LENGTH) {
|
||||
throw new ServiceException("账户长度必须在2到20个字符之间");
|
||||
}
|
||||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
||||
if (registerBody.getPassword().length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| registerBody.getPassword().length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
||||
throw new ServiceException("密码长度必须在5到20个字符之间");
|
||||
}
|
||||
String firmName = registerBody.getFirmName();
|
||||
Result<Firm> byFirmName = remoteFirmService.findByFirmName(firmName);
|
||||
Firm data = byFirmName.getData();
|
||||
if (null != data){
|
||||
throw new ServiceException("公司名称已经存在");
|
||||
}
|
||||
|
||||
|
||||
// 注册用户信息
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserName(username);
|
||||
sysUser.setNickName(username);
|
||||
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
||||
sysUser.setUserName(registerBody.getUsername());
|
||||
sysUser.setEmail(registerBody.getEmail());
|
||||
sysUser.setPhonenumber(registerBody.getPhoneNumber());
|
||||
sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
|
||||
Result<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
||||
|
||||
if (Result.FAIL == registerResult.getCode()) {
|
||||
throw new ServiceException(registerResult.getMsg());
|
||||
}
|
||||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
recordLogService.recordLogininfor(registerBody.getUsername(), Constants.REGISTER, "注册成功");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.common.system.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.system.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:Firm
|
||||
* @Date:2024/9/25 22:03
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Firm {
|
||||
|
||||
/**
|
||||
* 公司编号
|
||||
*/
|
||||
private Integer firmId;
|
||||
|
||||
/**
|
||||
* 公司名称
|
||||
*/
|
||||
private String firmName;
|
||||
|
||||
/**
|
||||
* 公司所属数据库
|
||||
*/
|
||||
private String databaseName;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.common.system.remote;
|
||||
|
||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.remote.factory.RemoteFirmFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.system.remote
|
||||
* @Project:cloud-server-8
|
||||
* @name:RemoteFirmService
|
||||
* @Date:2024/9/25 22:21
|
||||
*/
|
||||
@FeignClient(contextId = "remoteFirmService", value = ServiceNameConstants.SYSTEM_SERVICE,fallbackFactory = RemoteFirmFallbackFactory.class)
|
||||
public interface RemoteFirmService {
|
||||
|
||||
@RequestMapping("/firm/findByFirmName/{firmName}")
|
||||
public Result<Firm> findByFirmName(@PathVariable("firmName") String firmName);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.common.system.remote.factory;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.remote.RemoteFirmService;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.system.remote.factory
|
||||
* @Project:cloud-server-8
|
||||
* @name:RemoteFirmFallbackFactory
|
||||
* @Date:2024/9/25 22:22
|
||||
*/
|
||||
@Component
|
||||
public class RemoteFirmFallbackFactory implements FallbackFactory<RemoteFirmService> {
|
||||
@Override
|
||||
public RemoteFirmService create(Throwable cause) {
|
||||
|
||||
return new RemoteFirmService() {
|
||||
@Override
|
||||
public Result<Firm> findByFirmName(String firmName) {
|
||||
throw new ServiceException(cause.getCause().toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteFirmFallbackFactory
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.system.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.system.service.FirmService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.system.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:FirmController
|
||||
* @Date:2024/9/25 22:18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/firm")
|
||||
@AllArgsConstructor
|
||||
public class FirmController {
|
||||
|
||||
private final FirmService firmService;
|
||||
|
||||
|
||||
@RequestMapping("/findByFirmName/{firmName}")
|
||||
public Result<Firm> findByFirmName(@PathVariable("firmName") String firmName){
|
||||
Firm firmServiceByFirmName = firmService.findByFirmName(firmName);
|
||||
return Result.success(firmServiceByFirmName);
|
||||
}
|
||||
}
|
|
@ -127,9 +127,9 @@ public class SysUserController extends BaseController {
|
|||
@PostMapping("/register")
|
||||
public Result<Boolean> register (@RequestBody SysUser sysUser) {
|
||||
String username = sysUser.getUserName();
|
||||
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
|
||||
/* if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
|
||||
return Result.error("当前系统没有开启注册功能!");
|
||||
}
|
||||
}*/
|
||||
if (!userService.checkUserNameUnique(sysUser)) {
|
||||
return Result.error("保存用户'" + username + "'失败,注册账号已存在");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.system.mapper
|
||||
* @Project:cloud-server-8
|
||||
* @name:FirmMapper
|
||||
* @Date:2024/9/25 22:17
|
||||
*/
|
||||
public interface FirmMapper extends BaseMapper<Firm> {
|
||||
|
||||
Firm findByFirmName(@Param("firmName") String firmName);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.system.service
|
||||
* @Project:cloud-server-8
|
||||
* @name:FirmService
|
||||
* @Date:2024/9/25 22:17
|
||||
*/
|
||||
public interface FirmService extends IService<Firm> {
|
||||
Firm findByFirmName(String firmName);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.system.mapper.FirmMapper;
|
||||
import com.muyu.system.service.FirmService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.system.service.impl
|
||||
* @Project:cloud-server-8
|
||||
* @name:FirmServiceImpl
|
||||
* @Date:2024/9/25 22:17
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class FirmServiceImpl
|
||||
extends ServiceImpl<FirmMapper, Firm> implements FirmService {
|
||||
|
||||
private final FirmMapper firmMapper;
|
||||
|
||||
@Override
|
||||
public Firm findByFirmName(String firmName) {
|
||||
return firmMapper.findByFirmName(firmName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.system.mapper.FirmMapper">
|
||||
|
||||
<select id="findByFirmName" resultType="com.muyu.common.system.domain.Firm">
|
||||
select * from firm where firm_name = #{firmName}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue