🔨 Refactor: temp
This commit is contained in:
parent
cfe535e2a8
commit
9b668b64c1
@ -56,20 +56,20 @@ public class BaseInfoController {
|
||||
@PostMapping("/username")
|
||||
public Result updateUsername(@Validated @RequestBody UsernameBody body) {
|
||||
this.baseInfoService.updateUsername(body.getUsername());
|
||||
return null;
|
||||
return Result.success(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description: 修改邮箱,需要先确认密码,获取checkId,然后还需确认新邮箱
|
||||
* Description: 修改邮箱,还需校验新邮箱
|
||||
*
|
||||
* @param email 新的邮箱地址
|
||||
* @param checkId 确认id
|
||||
* @param body body
|
||||
* @return com.fanxb.bookmark.common.entity.Result
|
||||
* @author fanxb
|
||||
* @date 2019/9/18 15:41
|
||||
*/
|
||||
@PostMapping("/email")
|
||||
public Result updateEmail(@Validated @RequestBody EmailUpdateBody body) {
|
||||
return null;
|
||||
baseInfoService.updateEmail(body);
|
||||
return Result.success(null);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class UserController {
|
||||
/**
|
||||
* Description: 用户登录
|
||||
*
|
||||
* @param user 登录表单
|
||||
* @param body 登录表单
|
||||
* @return com.fanxb.bookmark.common.entity.Result
|
||||
* @author fanxb
|
||||
* @date 2019/7/6 16:35
|
||||
|
@ -19,6 +19,4 @@ public class EmailUpdateBody {
|
||||
private String oldPass;
|
||||
@Email
|
||||
private String newEmail;
|
||||
|
||||
private String code;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.fanxb.bookmark.business.user.entity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 类功能简述:
|
||||
* 类功能简述:记录用户id和要修改的邮件地址
|
||||
* 类功能详述:
|
||||
*
|
||||
* @author fanxb
|
||||
@ -13,4 +13,12 @@ import lombok.Data;
|
||||
public class EmailUpdateRedis {
|
||||
private int userId;
|
||||
private String email;
|
||||
|
||||
public EmailUpdateRedis() {
|
||||
}
|
||||
|
||||
public EmailUpdateRedis(int userId, String email) {
|
||||
this.userId = userId;
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,22 @@
|
||||
package com.fanxb.bookmark.business.user.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fanxb.bookmark.business.user.constant.RedisConstant;
|
||||
import com.fanxb.bookmark.business.user.dao.UserDao;
|
||||
import com.fanxb.bookmark.business.user.entity.EmailUpdateBody;
|
||||
import com.fanxb.bookmark.business.user.entity.EmailUpdateRedis;
|
||||
import com.fanxb.bookmark.business.user.entity.UpdatePasswordBody;
|
||||
import com.fanxb.bookmark.common.constant.Constant;
|
||||
import com.fanxb.bookmark.common.entity.MailInfo;
|
||||
import com.fanxb.bookmark.common.exception.FormDataException;
|
||||
import com.fanxb.bookmark.common.util.HashUtil;
|
||||
import com.fanxb.bookmark.common.util.MailUtil;
|
||||
import com.fanxb.bookmark.common.util.UserContextHolder;
|
||||
import com.fanxb.bookmark.common.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 类功能简述:
|
||||
* 类功能详述:
|
||||
@ -20,8 +25,14 @@ import org.springframework.stereotype.Service;
|
||||
* @date 2019/9/18 15:54
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class BaseInfoService {
|
||||
|
||||
private static final String VERIFY_EMAIL = FileUtil.streamToString(BaseInfoService.class
|
||||
.getClassLoader().getResourceAsStream("verifyEmail.html"));
|
||||
|
||||
private static final String VERIFY_EMAIL_PATH = "/public/verifyEmail?key=";
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@ -46,15 +57,29 @@ public class BaseInfoService {
|
||||
userDao.updateUsernameByUserId(UserContextHolder.get().getUserId(), username);
|
||||
}
|
||||
|
||||
public void updateEmail(EmailUpdateBody body){
|
||||
/**
|
||||
* 功能描述: 预备更新email,需要进行校验
|
||||
*
|
||||
* @param body body
|
||||
* @author fanxb
|
||||
* @date 2019/9/26 17:27
|
||||
*/
|
||||
public void updateEmail(EmailUpdateBody body) {
|
||||
int userId = UserContextHolder.get().getUserId();
|
||||
String realPass=userDao.selectByUserId(userId).getPassword();
|
||||
String realPass = userDao.selectByUserId(userId).getPassword();
|
||||
if (!realPass.equals(HashUtil.getPassword(body.getOldPass()))) {
|
||||
throw new FormDataException("旧密码错误");
|
||||
}
|
||||
MailInfo info = new MailInfo(body.getNewEmail(),"验证邮箱",);
|
||||
MailUtil.sendTextMail();
|
||||
Constant
|
||||
String key = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
String url = VERIFY_EMAIL.replaceAll("XXXX", Constant.serviceAddress + VERIFY_EMAIL_PATH + key);
|
||||
log.debug(url);
|
||||
MailInfo info = new MailInfo(body.getNewEmail(), "验证邮箱", url);
|
||||
MailUtil.sendMail(info, true);
|
||||
EmailUpdateRedis redisBody = new EmailUpdateRedis(userId, body.getNewEmail());
|
||||
RedisUtil.set(RedisConstant.getUpdateEmailKey(key), JSON.toJSONString(redisBody), TimeUtil.DAY_MS);
|
||||
}
|
||||
|
||||
public void verifyEmail(){
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>邮箱验证</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="padding-top:20px;text-align:center">访问 <a href="XXXX">XXXX</a> 验证您的邮箱。请于24小时内完成验证。</div>
|
||||
</body>
|
||||
</html>
|
@ -61,4 +61,15 @@ public class Constant {
|
||||
fileSavePath = path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 服务部署地址
|
||||
*/
|
||||
public static String serviceAddress = "http://localhost";
|
||||
|
||||
@Value("${serviceAddress}")
|
||||
public void setServiceAddress(String address) {
|
||||
serviceAddress = address;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.fanxb.bookmark.common.util;
|
||||
|
||||
import com.fanxb.bookmark.common.exception.CustomException;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 功能描述: 文件相关工具类
|
||||
*
|
||||
* @author fanxb
|
||||
* @date 2019/9/26 16:45
|
||||
*/
|
||||
public class FileUtil {
|
||||
/**
|
||||
* 功能描述: 输入流转字符串,注意:经过此方法流会被关闭
|
||||
*
|
||||
* @param stream 输入流
|
||||
* @param charSet 编码
|
||||
* @return java.lang.String
|
||||
* @author fanxb
|
||||
* @date 2019/9/26 17:03
|
||||
*/
|
||||
public static String streamToString(InputStream stream, String charSet) {
|
||||
try (
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charSet))
|
||||
) {
|
||||
return reader.lines().collect(Collectors.joining());
|
||||
} catch (Exception e) {
|
||||
throw new CustomException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述: 使用utf-8将输入流转成字符串,经过此方法流会被关闭
|
||||
*
|
||||
* @param stream stream
|
||||
* @return java.lang.String
|
||||
* @author fanxb
|
||||
* @date 2019/9/26 17:05
|
||||
*/
|
||||
public static String streamToString(InputStream stream) {
|
||||
return streamToString(stream, "utf-8");
|
||||
}
|
||||
}
|
@ -32,6 +32,14 @@ public class MailUtil {
|
||||
MailUtil.from = from;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述: 发送邮件
|
||||
*
|
||||
* @param info 邮件体
|
||||
* @param isHtml 是否为html邮件
|
||||
* @author fanxb
|
||||
* @date 2019/9/26 16:30
|
||||
*/
|
||||
public static void sendMail(MailInfo info, boolean isHtml) {
|
||||
try {
|
||||
|
||||
|
@ -69,3 +69,6 @@ es:
|
||||
|
||||
# 默认文件上传基路径
|
||||
fileSavePath: ./
|
||||
|
||||
# 服务部署地址
|
||||
serviceAddress: http://localhost
|
||||
|
8
bookMarkService/web/src/main/resources/verifyEmail.html
Normal file
8
bookMarkService/web/src/main/resources/verifyEmail.html
Normal file
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>邮箱验证</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="padding-top:20px;text-align:center">访问 <a href="XXXX">XXXX</a> 验证您的邮箱。请于24小时内完成验证。</div>
|
||||
</body>
|
||||
</html>
|
@ -3,7 +3,8 @@ const proxy = require("http-proxy-middleware");
|
||||
module.exports = function(app) {
|
||||
app.use(
|
||||
proxy("/bookmark/api/**", {
|
||||
target: "http://10.82.17.56:8088/",
|
||||
target: "http://localhost:8088/",
|
||||
// target: "http://ali.tapme.top:8083/",
|
||||
changeOrigin: true
|
||||
})
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user