|
@@ -8,6 +8,7 @@ import cn.cslg.permission.common.model.vo.RoleVO;
|
|
|
import cn.cslg.permission.common.utils.*;
|
|
|
import cn.cslg.permission.common.utils.message.MessageUtils;
|
|
|
import cn.cslg.permission.domain.Personnel;
|
|
|
+import cn.cslg.permission.domain.ReSetPasswordDTO;
|
|
|
import cn.cslg.permission.domain.Tenant;
|
|
|
import cn.cslg.permission.mapper.PersonnelMapper;
|
|
|
import cn.cslg.permission.service.associate.PerDpService;
|
|
@@ -24,6 +25,7 @@ import eu.bitwalker.useragentutils.UserAgent;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -37,6 +39,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
* @description 登录 Service 层
|
|
|
*/
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
@@ -113,6 +116,11 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
return Response.error(ResponseEnum.PERSONNEL_STATUS_ERROR);
|
|
|
}
|
|
|
+ //判断登陆人所属的租户是否过期(截止日期与当前时间比较)
|
|
|
+ if (tenant.getDeadLine() != null && tenant.getDeadLine().compareTo(new Date()) < 0) {
|
|
|
+ return Response.error(ResponseEnum.TENANT_DEADLINE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
//Sa-token 登录方法 登录后 生成Token 如果集成了Redis的话 会自动存入Redis
|
|
|
StpUtil.login(personnel.getId());
|
|
|
//填充数据
|
|
@@ -254,4 +262,55 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
return Response.success(true);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录前重置密码
|
|
|
+ *
|
|
|
+ * @param reSetPasswordDTO 人员账号和邮箱
|
|
|
+ */
|
|
|
+ public void reSetPasswordBeforeLogin(ReSetPasswordDTO reSetPasswordDTO) {
|
|
|
+ log.info("开始处理【登录前重置密码】的业务,参数为:{}", reSetPasswordDTO);
|
|
|
+
|
|
|
+ //若账号与邮箱未填写或格式不正确,则返回提示"请正确填写账号与邮箱"
|
|
|
+ if (reSetPasswordDTO.getPersonnelUserName() == null || reSetPasswordDTO.getPersonnelUserName().trim().equals("")
|
|
|
+ || reSetPasswordDTO.getPersonnelEmail() == null || reSetPasswordDTO.getPersonnelEmail().trim().equals("")) {
|
|
|
+ ThrowException.throwXiaoShiException("请正确填写账号与邮箱");
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查账号是否存在,若不存在则返回提示"账号错误,请检查账号是否输入正确"
|
|
|
+ Personnel personnel = this.getOne(new LambdaQueryWrapper<Personnel>().eq(Personnel::getPersonnelUserName, reSetPasswordDTO.getPersonnelUserName()).last("LIMIT 1"));
|
|
|
+ if (personnel == null) {
|
|
|
+ ThrowException.throwXiaoShiException("账号错误,请检查账号是否输入正确");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查邮箱是否存在,若没有邮箱则返回提示"该账号未绑定邮箱无法重置密码,请联系管理员"
|
|
|
+ String personnelEmail = personnel.getPersonnelEmail();
|
|
|
+ if (personnelEmail == null || personnelEmail.trim().equals("")) {
|
|
|
+ ThrowException.throwXiaoShiException("该账号未绑定邮箱无法重置密码,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查邮箱是否正确,若错误则返回提示"邮箱不正确,请检查后重新填写"
|
|
|
+ if (!reSetPasswordDTO.getPersonnelEmail().equals(personnelEmail)) {
|
|
|
+ ThrowException.throwXiaoShiException("邮箱不正确,请检查后重新填写");
|
|
|
+ }
|
|
|
+
|
|
|
+ //重置密码,发送邮件通知
|
|
|
+ int tem = (int) ((Math.random() * 9 + 1) * 100000);
|
|
|
+ String newPassword = String.valueOf(tem);
|
|
|
+ personnel.setPersonnelPassword(SecureUtil.md5(newPassword));
|
|
|
+ if (personnel.updateById()) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("title", "密码重置通知");
|
|
|
+ map.put("template", "mail/email.html");
|
|
|
+ map.put("value1", newPassword);
|
|
|
+ map.put("img", "/logo.png");
|
|
|
+ map.put("email", personnel.getPersonnelEmail());
|
|
|
+ map.put("value2", personnel.getPersonnelName());
|
|
|
+ mailUtils.sendEmailMessage(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|