cust auth
This commit is contained in:
parent
53b0630c21
commit
927a2e40de
|
|
@ -52,6 +52,15 @@ public interface RemoteUserService {
|
||||||
@GetMapping("/user/infoPhoto/{phone}")
|
@GetMapping("/user/infoPhoto/{phone}")
|
||||||
public R<LoginUser> getUserInfoByPhone(@PathVariable("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
public R<LoginUser> getUserInfoByPhone(@PathVariable("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户名查询用户信息
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
* @param source 请求来源
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@GetMapping("/user/custInfoPhoto/{phone}")
|
||||||
|
public R<LoginUser> getCustInfoByPhone(@PathVariable("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户信息
|
* 通过用户名查询用户信息
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import com.bonus.common.core.annotation.Excel.Type;
|
||||||
import com.bonus.common.core.annotation.Excels;
|
import com.bonus.common.core.annotation.Excels;
|
||||||
import com.bonus.common.core.web.domain.BaseEntity;
|
import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
import com.bonus.common.core.xss.Xss;
|
import com.bonus.common.core.xss.Xss;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
|
@ -153,6 +155,18 @@ public class SysUser extends BaseEntity {
|
||||||
/**是否内置,0内置,1非内置*/
|
/**是否内置,0内置,1非内置*/
|
||||||
private String isBuiltIn = "1";
|
private String isBuiltIn = "1";
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty("人员id")
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||||
|
private Long custId;
|
||||||
|
@ApiModelProperty("人员姓名")
|
||||||
|
private String custName;
|
||||||
|
@ApiModelProperty("人员编号")
|
||||||
|
private String custNum;
|
||||||
|
@ApiModelProperty("人脸照片地址")
|
||||||
|
private String custPhotoUrl;
|
||||||
|
|
||||||
|
|
||||||
public SysUser() {
|
public SysUser() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -354,6 +368,38 @@ public class SysUser extends BaseEntity {
|
||||||
this.isPermanent = isPermanent;
|
this.isPermanent = isPermanent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getCustId() {
|
||||||
|
return custId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustId(Long custId) {
|
||||||
|
this.custId = custId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustName() {
|
||||||
|
return custName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustName(String custName) {
|
||||||
|
this.custName = custName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustNum() {
|
||||||
|
return custNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustNum(String custNum) {
|
||||||
|
this.custNum = custNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustPhotoUrl() {
|
||||||
|
return custPhotoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustPhotoUrl(String custPhotoUrl) {
|
||||||
|
this.custPhotoUrl = custPhotoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
||||||
return R.fail("获取用户失败:" + throwable.getMessage());
|
return R.fail("获取用户失败:" + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<LoginUser> getCustInfoByPhone(String phone, String source) {
|
||||||
|
return R.fail("获取用户失败:" + throwable.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户信息
|
* 通过用户名查询用户信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@ public class LoginUser implements Serializable
|
||||||
*/
|
*/
|
||||||
private Long userid;
|
private Long userid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户id
|
||||||
|
*/
|
||||||
|
private Long custId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名
|
* 用户名
|
||||||
*/
|
*/
|
||||||
|
|
@ -78,6 +83,14 @@ public class LoginUser implements Serializable
|
||||||
this.userid = userid;
|
this.userid = userid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getCustId() {
|
||||||
|
return custId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustId(Long custId) {
|
||||||
|
this.custId = custId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
return username;
|
return username;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,15 @@ public enum LoginType {
|
||||||
/**
|
/**
|
||||||
* 邮箱验证码
|
* 邮箱验证码
|
||||||
*/
|
*/
|
||||||
EMAIL_OTP;
|
EMAIL_OTP,
|
||||||
|
/**
|
||||||
|
* 客户手机号密码
|
||||||
|
*/
|
||||||
|
CUST_PHONE_PASSWORD,
|
||||||
|
/**
|
||||||
|
* 客户手机号验证码
|
||||||
|
*/
|
||||||
|
CUST_PHONE_OPT;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public static LoginType fromString(String key) {
|
public static LoginType fromString(String key) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.bonus.auth.controller;
|
package com.bonus.auth.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.bonus.auth.config.LoginType;
|
import com.bonus.auth.config.LoginType;
|
||||||
import com.bonus.auth.factory.LoginStrategyFactory;
|
import com.bonus.auth.factory.LoginStrategyFactory;
|
||||||
import com.bonus.auth.form.LoginBody;
|
import com.bonus.auth.form.LoginBody;
|
||||||
|
|
@ -19,25 +18,19 @@ import com.bonus.common.security.service.TokenService;
|
||||||
import com.bonus.common.security.utils.SecurityUtils;
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.config.SystemConfig;
|
import com.bonus.config.SystemConfig;
|
||||||
import com.bonus.system.api.RemoteConfigService;
|
import com.bonus.system.api.RemoteConfigService;
|
||||||
import com.bonus.system.api.RemoteLogService;
|
|
||||||
import com.bonus.system.api.RemoteUserService;
|
import com.bonus.system.api.RemoteUserService;
|
||||||
import com.bonus.system.api.domain.SysUser;
|
import com.bonus.system.api.domain.SysUser;
|
||||||
import com.bonus.system.api.model.LoginUser;
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -136,7 +129,7 @@ public class TokenController {
|
||||||
if (strategy == null) {
|
if (strategy == null) {
|
||||||
return R.fail("不支持的登录方式");
|
return R.fail("不支持的登录方式");
|
||||||
}
|
}
|
||||||
if (form.getLoginType()== LoginType.EMAIL_OTP || form.getLoginType()== LoginType.PHONE_OTP ){
|
if (form.getLoginType()== LoginType.EMAIL_OTP || form.getLoginType()== LoginType.PHONE_OTP || form.getLoginType()== LoginType.CUST_PHONE_OPT){
|
||||||
form.setPassword(form.getVerificationCode());
|
form.setPassword(form.getVerificationCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ public class LoginStrategyFactory {
|
||||||
strategyMap.put(LoginType.EMAIL_PASSWORD, strategy);
|
strategyMap.put(LoginType.EMAIL_PASSWORD, strategy);
|
||||||
} else if (strategy instanceof EmailOtpLoginStrategy) {
|
} else if (strategy instanceof EmailOtpLoginStrategy) {
|
||||||
strategyMap.put(LoginType.EMAIL_OTP, strategy);
|
strategyMap.put(LoginType.EMAIL_OTP, strategy);
|
||||||
|
} else if (strategy instanceof CustPhonePasswordLoginStrategy) {
|
||||||
|
strategyMap.put(LoginType.CUST_PHONE_PASSWORD, strategy);
|
||||||
|
} else if (strategy instanceof CustPhoneOtpLoginStrategy) {
|
||||||
|
strategyMap.put(LoginType.CUST_PHONE_OPT, strategy);
|
||||||
}
|
}
|
||||||
// 继续添加其他策略
|
// 继续添加其他策略
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.bonus.auth.service;
|
||||||
|
|
||||||
|
import com.bonus.common.core.constant.SecurityConstants;
|
||||||
|
import com.bonus.common.core.domain.R;
|
||||||
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
|
import com.bonus.config.SystemConfig;
|
||||||
|
import com.bonus.system.api.RemoteUserService;
|
||||||
|
import com.bonus.system.api.domain.SysUser;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author bonus
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CustPhoneOtpLoginStrategy implements LoginStrategy {
|
||||||
|
@Resource
|
||||||
|
private SystemConfig systemConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PasswordValidatorService passwordValidatorService;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginUser login(String phone, String otp) {
|
||||||
|
if (!systemConfig.getLoginConfig().isPhoneCode()) {
|
||||||
|
throw new ServiceException("用户不存在/验证码错误");
|
||||||
|
}
|
||||||
|
passwordValidatorService.checkPhoneCaptcha(phone, otp);
|
||||||
|
R<LoginUser> userResult = remoteUserService.getUserInfoByPhone(phone, SecurityConstants.INNER);
|
||||||
|
//验证用户是否存在
|
||||||
|
passwordValidatorService.validateUserResult(phone, userResult);
|
||||||
|
LoginUser userInfo = userResult.getData();
|
||||||
|
SysUser user = userInfo.getSysUser();
|
||||||
|
passwordValidatorService.validateApprovalStatus(phone, user);
|
||||||
|
// 验证用户状态
|
||||||
|
passwordValidatorService.validateUserStatus(phone, user);
|
||||||
|
|
||||||
|
passwordValidatorService.processLoginBlackList(user);
|
||||||
|
//返回信息
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.bonus.auth.service;
|
||||||
|
|
||||||
|
import com.bonus.common.core.constant.SecurityConstants;
|
||||||
|
import com.bonus.common.core.domain.R;
|
||||||
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
|
import com.bonus.config.SystemConfig;
|
||||||
|
import com.bonus.system.api.RemoteUserService;
|
||||||
|
import com.bonus.system.api.domain.SysUser;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author bonus
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CustPhonePasswordLoginStrategy implements LoginStrategy {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemConfig systemConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PasswordValidatorService passwordValidatorService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysPasswordService passwordService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginUser login(String phone, String password) {
|
||||||
|
if (!systemConfig.getLoginConfig().isPhonePassword()) {
|
||||||
|
throw new ServiceException("用户不存在/密码错误");
|
||||||
|
}
|
||||||
|
//通过手机号获取用户信息
|
||||||
|
R<LoginUser> userResult = remoteUserService.getCustInfoByPhone(phone, SecurityConstants.INNER);
|
||||||
|
//验证用户是否存在
|
||||||
|
passwordValidatorService.validateUserResult(phone, userResult);
|
||||||
|
//获取用户信息
|
||||||
|
LoginUser userInfo = userResult.getData();
|
||||||
|
SysUser user = userInfo.getSysUser();
|
||||||
|
//校验用户审批状态
|
||||||
|
passwordValidatorService.validateApprovalStatus(user.getUserName(), user);
|
||||||
|
// 处理IP校验
|
||||||
|
passwordValidatorService.validateIpBlacklist(user.getUserName());
|
||||||
|
// 验证密码
|
||||||
|
passwordService.validate(user, password, System.currentTimeMillis());
|
||||||
|
//校验用户启用状态
|
||||||
|
passwordValidatorService.validateUserStatus(user.getUserName(), user);
|
||||||
|
|
||||||
|
passwordValidatorService.processLoginBlackList(user);
|
||||||
|
//返回信息
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -206,6 +206,31 @@ public class SysUserController extends BaseController {
|
||||||
return R.ok(sysUserVo);
|
return R.ok(sysUserVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户信息
|
||||||
|
*/
|
||||||
|
@InnerAuth
|
||||||
|
@GetMapping("/CustInfoPhoto/{photoNumber}")
|
||||||
|
public R<LoginUser> custInfoPhotoNumber(@PathVariable("photoNumber") String photoNumber) {
|
||||||
|
SysUser sysUser = userService.selectCustInfoByPhoneNumber(photoNumber);
|
||||||
|
if (StringUtils.isNull(sysUser)) {
|
||||||
|
return R.fail("用户名或密码错误");
|
||||||
|
}
|
||||||
|
// SysDept sysDept = deptService.selectActiveDeptById(sysUser.getCompanyId());
|
||||||
|
// if (StringUtils.isNull(sysDept)) {
|
||||||
|
// return R.fail("用户所在公司停用或注销");
|
||||||
|
// }
|
||||||
|
// 角色集合
|
||||||
|
//Set<String> roles = permissionService.getRolePermission(sysUser);
|
||||||
|
// 权限集合
|
||||||
|
//Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
||||||
|
LoginUser sysUserVo = new LoginUser();
|
||||||
|
sysUserVo.setSysUser(sysUser);
|
||||||
|
//sysUserVo.setRoles(roles);
|
||||||
|
//sysUserVo.setPermissions(permissions);
|
||||||
|
return R.ok(sysUserVo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册用户信息
|
* 注册用户信息
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -155,4 +155,12 @@ public interface SysUserMapper {
|
||||||
Integer approvalStatus(Long userId);
|
Integer approvalStatus(Long userId);
|
||||||
|
|
||||||
int systemUpdateUser(SysUser user);
|
int systemUpdateUser(SysUser user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过手机号查询用户
|
||||||
|
*
|
||||||
|
* @param phoneNumber 手机号
|
||||||
|
* @return 用户对象信息
|
||||||
|
*/
|
||||||
|
public SysUser selectCustInfoByPhoneNumber(@Param("phoneNumber") String phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,5 +237,5 @@ public interface ISysUserService {
|
||||||
|
|
||||||
public AjaxResult systemUpdateUser(SysUser user);
|
public AjaxResult systemUpdateUser(SysUser user);
|
||||||
|
|
||||||
|
public SysUser selectCustInfoByPhoneNumber(String photoNumber);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -649,4 +649,15 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户名查询用户
|
||||||
|
*
|
||||||
|
* @param photoNumber 用户名
|
||||||
|
* @return 用户对象信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SysUser selectCustInfoByPhoneNumber(String photoNumber) {
|
||||||
|
return userMapper.selectCustInfoByPhoneNumber(Sm4Utils.encrypt(photoNumber));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -369,5 +369,25 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<!--根据人员id集合获取人员信息-->
|
||||||
|
<select id="selectCustInfoByPhoneNumber" resultType="com.bonus.system.api.domain.SysUser">
|
||||||
|
select cust_id, cust_name, cust_num, cust_photo_url, mobile as phonenumber, pwd as password
|
||||||
|
from cust_info
|
||||||
|
<where>
|
||||||
|
cust_state = 1 and (psn_type != 999 or psn_type is null)
|
||||||
|
<if test="custName != null and custName != ''">
|
||||||
|
and cust_name = #{custName}
|
||||||
|
</if>
|
||||||
|
<if test="custNum != null and custNum != ''">
|
||||||
|
and cust_num = #{custNum}
|
||||||
|
</if>
|
||||||
|
<if test="mobile != null and mobile != ''">
|
||||||
|
and mobile = #{mobile}
|
||||||
|
</if>
|
||||||
|
<if test="idCard != null and idCard != ''">
|
||||||
|
and id_card = #{idCard}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue