glj-代码提交
This commit is contained in:
parent
63c4a85a5f
commit
1e73ec8c55
|
@ -1,17 +1,31 @@
|
|||
package com.kening.vordm.controller;
|
||||
|
||||
import com.kening.vordm.entity.Email;
|
||||
import com.kening.vordm.mapper.GuestInfoMapper;
|
||||
import com.kening.vordm.service.EmailService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.common.cache.CacheNames;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.redis.cache.BladeRedis;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.support.Kv;
|
||||
import org.springblade.core.tool.utils.DigestUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
|
||||
|
||||
/**
|
||||
* @author wanghongqing
|
||||
|
@ -21,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("/ui/captcha")
|
||||
@RequiredArgsConstructor
|
||||
@Api(value = "验证码校验接口", tags = "验证码校验")
|
||||
@Slf4j
|
||||
public class CaptchaController extends BladeController {
|
||||
|
||||
private final BladeRedis bladeRedis;
|
||||
|
@ -37,4 +52,80 @@ public class CaptchaController extends BladeController {
|
|||
}
|
||||
return R.success("OK");
|
||||
}
|
||||
|
||||
private final EmailService emailService;
|
||||
|
||||
private final GuestInfoMapper guestInfoMapper;
|
||||
|
||||
//发送邮箱验证码
|
||||
@GetMapping("/sendEmailCode")
|
||||
@ApiOperation(value = "验证码校验", notes = "传入需要校验的邮箱")
|
||||
public R sendEmailCode(String emailAccount) {
|
||||
String verCode = makeRandomPassword(4);
|
||||
bladeRedis.setEx(CacheNames.CAPTCHA_KEY + emailAccount, verCode, Duration.ofMinutes(5));
|
||||
//发送邮件
|
||||
Email email = new Email();
|
||||
email.setSubject("Retrieve password and verify email address");
|
||||
String text = "Code:" + verCode + "<br>";
|
||||
text += "period of validity" + 5 + "minute" + "<br>";
|
||||
|
||||
email.setText(text);
|
||||
String[] to = new String[]{emailAccount};
|
||||
email.setTos(to);
|
||||
email.setHtmlText(true);
|
||||
try {
|
||||
emailService.sendMimeMessage(email);
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件失败:{}", e);
|
||||
return R.fail("发送失败");
|
||||
}
|
||||
// 将key返回给前端
|
||||
return R.success("OK");
|
||||
}
|
||||
|
||||
@GetMapping("/codeCheck")
|
||||
@ApiOperation(value = "邮箱验证码校验", notes = "传入需要校验的验证码以及缓存Key")
|
||||
public R codeCheck(String emailAccount, String code) {
|
||||
// 获取验证码
|
||||
String redisCode = bladeRedis.get(CacheNames.CAPTCHA_KEY + emailAccount);
|
||||
// 判断验证码
|
||||
if (code == null || !StringUtil.equalsIgnoreCase(redisCode, code)) {
|
||||
return R.data(1404, "Verification code error");
|
||||
}
|
||||
|
||||
String password = makeRandomPassword(8);
|
||||
|
||||
//修改用户密码
|
||||
guestInfoMapper.updatePassword(emailAccount, DigestUtil.encrypt(password));
|
||||
CacheUtil.clear(USER_CACHE);
|
||||
//发送邮件
|
||||
Email email = new Email();
|
||||
email.setSubject("Retrieve password and verify email address");
|
||||
String text = "Latest password:" + password + "<br>";
|
||||
|
||||
email.setText(text);
|
||||
String[] to = new String[]{emailAccount};
|
||||
email.setTos(to);
|
||||
email.setHtmlText(true);
|
||||
try {
|
||||
emailService.sendMimeMessage(email);
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件失败:{}", e);
|
||||
return R.fail("发送失败");
|
||||
}
|
||||
return R.success("OK");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static String makeRandomPassword(int len) {
|
||||
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random r = new Random();
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(charr[r.nextInt(charr.length)]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -346,6 +346,7 @@ public class DisasterInfoController {
|
|||
Boolean flag = disasterInfoService.updateById(disasterInfo);
|
||||
return R.data(flag);
|
||||
}
|
||||
|
||||
private final EmailService emailService;
|
||||
@ApiOperationSupport(order = 6)
|
||||
@ApiOperation(value = "提交", notes = "传入Tool")
|
||||
|
@ -360,6 +361,7 @@ public class DisasterInfoController {
|
|||
one.setStatus(1);
|
||||
one.setManagerId(chiefId);
|
||||
guestManageDisasterRefService.updateById(one);
|
||||
disasterInfoService.updateById(disasterInfo);
|
||||
//获得disasterInfo
|
||||
disasterInfo = disasterInfoService.getById(disasterInfo.getId());
|
||||
|
||||
|
@ -368,7 +370,7 @@ public class DisasterInfoController {
|
|||
Administrator user = administratorService.getById(chiefId);
|
||||
//发送邮件
|
||||
Email email = new Email();
|
||||
email.setSubject("You have a new pending disaster");
|
||||
email.setSubject("You have a Disaster Response task pending");
|
||||
String text ="Disaster Keyword:" + disasterInfo.getDisasterKeyword()+"<br>";
|
||||
text+= "Disaster Time:" + disasterInfo.getDisasterTime()+"<br>";
|
||||
//disaster_country
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.time.LocalDate;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 管理员用户实现类
|
||||
|
@ -66,8 +67,11 @@ public class AdministratorServiceImpl extends BaseServiceImpl<AdministratorMappe
|
|||
administrator.setTenantId(tenantId);
|
||||
administrator.setUserType(1);
|
||||
administrator.setRealName(administrator.getName());
|
||||
//随机密码
|
||||
String s = makeRandomPassword(8);
|
||||
System.out.println(s);
|
||||
//密码默认为1234
|
||||
administrator.setPassword(DigestUtil.encrypt("1234"));
|
||||
administrator.setPassword(DigestUtil.encrypt(s));
|
||||
//角色为chief
|
||||
Long roleId = baseMapper.getChiefRole("chief");
|
||||
administrator.setRoleId(String.valueOf(roleId));
|
||||
|
@ -75,12 +79,12 @@ public class AdministratorServiceImpl extends BaseServiceImpl<AdministratorMappe
|
|||
save(administrator);
|
||||
try{
|
||||
//设置标题
|
||||
String subject = "Welcome to register";
|
||||
String subject = "Welcome to become the operation and maintenance administrator of the VoRDM platform";
|
||||
//设置要填充模板的参数
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("account", administrator.getAccount());
|
||||
//默认密码 1234
|
||||
dataMap.put("password", "1234");
|
||||
dataMap.put("password", s);
|
||||
dataMap.put("link",link);
|
||||
dataMap.put("time", LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")));
|
||||
Email email = new Email();
|
||||
|
@ -94,4 +98,16 @@ public class AdministratorServiceImpl extends BaseServiceImpl<AdministratorMappe
|
|||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
public static String makeRandomPassword(int len) {
|
||||
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random r = new Random();
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(charr[r.nextInt(charr.length)]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class EmailServiceImpl implements EmailService {
|
|||
}
|
||||
disasterInfoMapper.updataUserByEmail(userVo.getEmail(),"1790ae2beb8e6c6a4c6744667e11c4ba26abeb09");
|
||||
Email email = new Email();
|
||||
email.setSubject("您的登录密码");
|
||||
email.setSubject("Your login password has been updated");
|
||||
String encrypt = DigestUtil.encrypt(bladeUser.getPassword());
|
||||
email.setText("Your login password has been updated to:“admin@#”");
|
||||
email.setHtmlText(false);
|
||||
|
|
|
@ -84,8 +84,9 @@ public class NewsServiceImpl extends ServiceImpl<NewsMapper, News>
|
|||
@Override
|
||||
public R importTemplate(MultipartFile file, Integer typeData, Long disasterId) {
|
||||
List content;
|
||||
ExcelReader reader = null;
|
||||
try {
|
||||
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
|
||||
reader = ExcelUtil.getReader(file.getInputStream());
|
||||
content = reader.read();
|
||||
} catch (Exception var30) {
|
||||
return R.fail("上传文件格式解析错误");
|
||||
|
|
|
@ -67,11 +67,11 @@
|
|||
<a href="#" th:href="@{http://www.baidu.com/register/{id}(id=${id})}">激活账号</a>-->
|
||||
<div class="container">
|
||||
<div class="content">
|
||||
<h2>Hello, thank you for your registration</h2>
|
||||
<!-- <h2>Hello, thank you for your registration</h2>-->
|
||||
<p>Your account number:<b><span th:text="${account}"></span></b></p>
|
||||
<p>Your password:<b><span th:text="${password}"></span></b></p>
|
||||
<p>The date you registered:<b><span th:text="${time}"></span></b></p>
|
||||
<P><b>Please click login:<a th:href="${link}">Point-me jump</a></b></P>
|
||||
<P><b>Please click here to jump to the:<a th:href="${link}">login interface</a></b></P>
|
||||
<p></p>
|
||||
</div>
|
||||
<div class="footer">
|
||||
|
|
Loading…
Reference in New Issue