add 企业联系人登录
This commit is contained in:
+1
-1
@@ -90,7 +90,7 @@ public class JwtUtil {
|
||||
String accessToken = request.getHeader("X-Access-Token");
|
||||
String username = getUsername(accessToken);
|
||||
if (oConvertUtils.isEmpty(username)) {
|
||||
throw new JeroBootException("未获取到用户");
|
||||
throw new JeroBootException("未获取到用户");
|
||||
}
|
||||
return username;
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ public class TokenUtils {
|
||||
// 查询用户信息
|
||||
LoginUser user = commonAPI.getUserByName(username);
|
||||
if (user == null) {
|
||||
|
||||
throw new AuthenticationException("用户不存在!");
|
||||
}
|
||||
// 判断用户状态
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ public class ShiroConfig {
|
||||
filterChainDefinitionMap.put("/company/payContactsManagement/queryByName","anon");//联系人校验
|
||||
filterChainDefinitionMap.put("/sys/common/download/**","anon");//下载接口
|
||||
filterChainDefinitionMap.put("/sys/oss/file/queryById","anon");//通过id查询文件
|
||||
|
||||
filterChainDefinitionMap.put("/company/login", "anon"); //登录接口排除
|
||||
|
||||
filterChainDefinitionMap.put("/", "anon");
|
||||
filterChainDefinitionMap.put("/doc.html", "anon");
|
||||
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
package com.jero.company.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.company.entity.PayContactsManagement;
|
||||
import com.jero.company.service.IPayContactsManagementService;
|
||||
import com.jero.modules.base.service.BaseCommonService;
|
||||
import com.jero.modules.system.model.SysLoginModel;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author liJiaRao
|
||||
* @date 2021-09-22 19:28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/company")
|
||||
@Api(tags = "企业端登录")
|
||||
@Slf4j
|
||||
public class CompanyLoginController {
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
@Autowired
|
||||
private IPayContactsManagementService payContactsManagementService;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
@Resource
|
||||
private BaseCommonService baseCommonService;
|
||||
/**
|
||||
* 密码登录错误的次数前缀
|
||||
*/
|
||||
public static final String RETRY_LOGIN_PREFIX = "login:retryLoginCount_";
|
||||
/**
|
||||
* 密码登录错误的最大限制次数
|
||||
*/
|
||||
public static final int RETRY_LOGIN_MAX_COUNT = 5;
|
||||
|
||||
@ApiOperation("登录接口")
|
||||
@PostMapping(value = "/login")
|
||||
public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel) {
|
||||
Result<JSONObject> result = new Result<>();
|
||||
String username = PasswordUtil.encrypt(sysLoginModel.getUsername());
|
||||
String password = sysLoginModel.getPassword();
|
||||
/*String rsaPublicKey = sysLoginModel.getRsaPublicKey();
|
||||
String rsaPrivateKey = String.valueOf(redisUtil.get(rsaPublicKey));
|
||||
//update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题
|
||||
//前端密码加密,后端进行密码解密
|
||||
//password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密
|
||||
//update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题
|
||||
//update-begin-author:taoyan date:20190828 for:校验验证码
|
||||
String captcha = sysLoginModel.getCaptcha();
|
||||
if (captcha == null) {
|
||||
result.error500("验证码无效");
|
||||
return result;
|
||||
}
|
||||
String lowerCaseCaptcha = captcha.toLowerCase();
|
||||
String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), "utf-8");
|
||||
Object checkCode = redisUtil.get(realKey);
|
||||
//当进入登录页时,有一定几率出现验证码错误 #1714
|
||||
if (checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) {
|
||||
result.error500("验证码错误");
|
||||
return result;
|
||||
} else {
|
||||
redisUtil.del(realKey);
|
||||
}
|
||||
try {
|
||||
//解密获取密码和用户名
|
||||
password = CommonUtils.decryptBtRsaPriKey(password, rsaPrivateKey);
|
||||
username = CommonUtils.decryptBtRsaPriKey(username, rsaPrivateKey);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
//1. 校验用户是否有效
|
||||
//update-begin-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为false
|
||||
LambdaQueryWrapper<PayContactsManagement> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PayContactsManagement::getPhone, username);
|
||||
PayContactsManagement contactsManagement = payContactsManagementService.getOne(queryWrapper);
|
||||
//update-end-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为false
|
||||
if (Objects.isNull(contactsManagement)) {
|
||||
throw new JeroBootException("用户名或密码错误");
|
||||
}
|
||||
|
||||
// 若用户名有效,则查询该账号的登陆失败次数是否符合等保要求
|
||||
int retryCount = 0;
|
||||
if (redisUtil.get(RETRY_LOGIN_PREFIX + username) != null) {
|
||||
retryCount = (int) redisUtil.get(RETRY_LOGIN_PREFIX + username);
|
||||
}
|
||||
if (retryCount >= RETRY_LOGIN_MAX_COUNT) {
|
||||
result.error500("密码错误次数过多,请稍后重试");
|
||||
return result;
|
||||
}
|
||||
//2. 校验用户名或密码是否正确
|
||||
String userpassword = PasswordUtil.encrypt(username, password, contactsManagement.getSalt());
|
||||
String syspassword = contactsManagement.getPassword();
|
||||
if (!syspassword.equals(userpassword)) {
|
||||
// 重试登录次数加一
|
||||
retryCount++;
|
||||
if (retryCount == 1) {
|
||||
redisUtil.set(RETRY_LOGIN_PREFIX + username, retryCount, 60 * 30);
|
||||
} else {
|
||||
redisUtil.set(RETRY_LOGIN_PREFIX + username, retryCount, redisUtil.getExpire(RETRY_LOGIN_PREFIX + username));
|
||||
}
|
||||
String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请稍后重试" : "用户名或密码错误,剩余可登录次数:" + (RETRY_LOGIN_MAX_COUNT - retryCount);
|
||||
result.error500(msg);
|
||||
return result;
|
||||
}
|
||||
//登录成功,清除错误登录次数
|
||||
redisUtil.del(RETRY_LOGIN_PREFIX + username);
|
||||
|
||||
//用户登录信息
|
||||
userInfo(contactsManagement, result);
|
||||
//update-begin--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(contactsManagement, loginUser);
|
||||
baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser);
|
||||
//update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @param contactsManagement
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
private void userInfo(PayContactsManagement contactsManagement, Result<JSONObject> result) {
|
||||
String syspassword = contactsManagement.getPassword();
|
||||
String username = contactsManagement.getPhone();
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(username, syspassword);
|
||||
// 设置token缓存有效时间
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
||||
|
||||
// 获取用户部门信息
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
obj.put("token", token);
|
||||
obj.put("userInfo", contactsManagement);
|
||||
obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
|
||||
result.setResult(obj);
|
||||
result.success("登录成功");
|
||||
}
|
||||
}
|
||||
+7
@@ -35,6 +35,7 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -62,6 +63,8 @@ public class PayContactsManagementController extends JeroController<PayContactsM
|
||||
private Environment env;
|
||||
@Autowired
|
||||
private ProjectCountService projectCountService;
|
||||
@Value("${defaultPassword}")
|
||||
private String defaultPassword;
|
||||
|
||||
// todo 缺少联系人加入到用户表,可以登录
|
||||
|
||||
@@ -161,6 +164,10 @@ public class PayContactsManagementController extends JeroController<PayContactsM
|
||||
if (!StringUtils.isBlank(payContactsManagement.getEmail())){
|
||||
payContactsManagement.setEmail(PasswordUtil.encrypt(payContactsManagement.getEmail()));
|
||||
}
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
String passwordEncode = PasswordUtil.encrypt(payContactsManagement.getPhone(), defaultPassword, salt);
|
||||
payContactsManagement.setSalt(salt);
|
||||
payContactsManagement.setPassword(passwordEncode);
|
||||
}catch (Exception e){
|
||||
log.error("手机号、邮箱加密异常!",e);
|
||||
}
|
||||
|
||||
+14
@@ -5,7 +5,9 @@ import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import com.jero.modules.system.volid.group.CreateGroup;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
@@ -106,4 +108,16 @@ public class PayContactsManagement implements Serializable {
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* md5密码盐
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String salt;
|
||||
}
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package com.jero.modules.pay.company.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import com.jero.modules.system.volid.group.CreateGroup;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* @Description: pay_contacts_management
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2021-08-25
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("pay_contacts_management")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="pay_contacts_management对象", description="pay_contacts_management")
|
||||
public class PayContactsManagement implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
/**企业id*/
|
||||
@ApiModelProperty(value = "企业id")
|
||||
@Size(max = 32, message = "企业id长度不能大于32个字符")
|
||||
private String companyId;
|
||||
/**企业名称*/
|
||||
@Excel(name = "企业名称", width = 15)
|
||||
@ApiModelProperty(value = "企业名称")
|
||||
@Size(max = 200, message = "企业名称长度不能大于200个字符")
|
||||
private String companyName;
|
||||
/**姓名*/
|
||||
@Excel(name = "姓名", width = 15)
|
||||
@ApiModelProperty(value = "姓名")
|
||||
@NotEmpty(message = "姓名不能为空!")
|
||||
@Size(max = 20, message = "姓名长度不能大于20个字符")
|
||||
private String name;
|
||||
/**性别(1:男,2:女)*/
|
||||
@Excel(name = "性别", width = 15,dicCode="sex")
|
||||
@ApiModelProperty(value = "性别")
|
||||
@Dict(dicCode = "sex")
|
||||
private Integer gender;
|
||||
/**职务*/
|
||||
@Excel(name = "职务", width = 15)
|
||||
@ApiModelProperty(value = "职务")
|
||||
@Size(max = 20, message = "职务长度不能大于20个字符")
|
||||
private String post;
|
||||
/**手机号*/
|
||||
@Excel(name = "手机号", width = 15)
|
||||
@ApiModelProperty(value = "手机号")
|
||||
@NotEmpty(message = "手机号不能为空!")
|
||||
@Pattern(regexp = "^((13[0-9])|(14[579])|(15([0-3]|[5-9]))|(17[0135678])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$",message = "手机号码格式错误")
|
||||
private String phone;
|
||||
/**邮箱*/
|
||||
@Excel(name = "邮箱", width = 15)
|
||||
@ApiModelProperty(value = "邮箱")
|
||||
@Pattern(regexp = "^\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}$",message = "邮箱格式有误")
|
||||
@NotEmpty(message = "邮箱不能为空!")
|
||||
private String email;
|
||||
/**通讯地址*/
|
||||
@Excel(name = "通讯地址", width = 15)
|
||||
@ApiModelProperty(value = "通讯地址")
|
||||
@Size(max = 50, message = "通讯地址长度不能大于50个字符")
|
||||
@NotEmpty(message = "通讯地址不能为空!")
|
||||
private String contactAddress;
|
||||
/**邮政编码*/
|
||||
@Excel(name = "邮政编码", width = 15)
|
||||
@Size(min=6,max = 6,message = "邮政编码长度必须为6个字符")
|
||||
@ApiModelProperty(value = "邮政编码")
|
||||
@Pattern(regexp = "^[0-9]\\d{5}$",message = "邮编格式错误")
|
||||
@NotEmpty(message = "邮政编码不能为空!")
|
||||
private String postalCode;
|
||||
/**备注*/
|
||||
@Excel(name = "备注", width = 15)
|
||||
@ApiModelProperty(value = "备注")
|
||||
@Size(max = 200, message = "备注长度不能大于200个字符")
|
||||
private String remarks;
|
||||
/**创建人*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createBy;
|
||||
/**创建时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
/**更新人*/
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private String updateBy;
|
||||
/**更新时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* md5密码盐
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String salt;
|
||||
}
|
||||
+3
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.modules.pay.company.entity.PayContactsManagement;
|
||||
import com.jero.modules.system.entity.SysRole;
|
||||
import com.jero.modules.system.vo.SysUserVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -162,4 +163,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
* @return
|
||||
*/
|
||||
List<SysRole> getRoleNameByUserIds(@Param("userIds") List<String> userIds);
|
||||
|
||||
PayContactsManagement getPayContactsManagementByPhone(@Param("username") String username);
|
||||
}
|
||||
|
||||
+5
@@ -199,4 +199,9 @@
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="getPayContactsManagementByPhone" resultType="com.jero.modules.pay.company.entity.PayContactsManagement">
|
||||
select *
|
||||
from pay_contacts_management where phone = #{username};
|
||||
</select>
|
||||
</mapper>
|
||||
+11
-5
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.jero.modules.oss.mapper.OSSFileMapper;
|
||||
import com.jero.modules.pay.company.entity.PayContactsManagement;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
@@ -95,7 +96,6 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
private SysPermissionMapper sysPermissionMapper;
|
||||
@Autowired
|
||||
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames=CacheConstant.SYS_USERS_CACHE, key="#username")
|
||||
public LoginUser getUserByName(String username) {
|
||||
@@ -105,11 +105,17 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
LoginUser loginUser = new LoginUser();
|
||||
SysUser sysUser = userMapper.getUserByName(username);
|
||||
if(sysUser==null) {
|
||||
return null;
|
||||
PayContactsManagement contactsManagement = userMapper.getPayContactsManagementByPhone(username);
|
||||
if (contactsManagement == null){
|
||||
return null;
|
||||
}else {
|
||||
BeanUtils.copyProperties(contactsManagement, loginUser);
|
||||
}
|
||||
}else {
|
||||
BeanUtils.copyProperties(sysUser, loginUser);
|
||||
List<String> roleByUserName = sysUserRoleMapper.getRoleByUserName(username);
|
||||
loginUser.setRoleCode(roleByUserName.get(0));
|
||||
}
|
||||
BeanUtils.copyProperties(sysUser, loginUser);
|
||||
List<String> roleByUserName = sysUserRoleMapper.getRoleByUserName(username);
|
||||
loginUser.setRoleCode(roleByUserName.get(0));
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user