use of com.fanxb.bookmark.common.exception.CustomException in project bookmark by FleyX.
the class HashUtil method hash.
/**
* Description: 根据type签名str
*
* @param str str
* @param type 签名类别
* @return java.lang.String
* @author fanxb
* @date 2019/7/6 14:40
*/
public static String hash(String str, String type) {
try {
MessageDigest md = MessageDigest.getInstance(type);
md.update(str.getBytes());
return bytesToHexString(md.digest());
} catch (Exception e) {
throw new CustomException(e);
}
}
use of com.fanxb.bookmark.common.exception.CustomException in project bookmark by FleyX.
the class BaseInfoServiceImpl method updateEmail.
@Override
@Transactional(rollbackFor = Exception.class)
public void updateEmail(EmailUpdateBody body) {
int userId = UserContextHolder.get().getUserId();
String oldPassword = userDao.selectByUserIdOrGithubId(userId, null).getPassword();
if (!StrUtil.equals(oldPassword, HashUtil.getPassword(body.getOldPassword()))) {
throw new CustomException("密码校验失败,无法更新email");
}
String secret = UUID.randomUUID().toString().replaceAll("-", "");
String url = VERIFY_EMAIL.replaceAll("XXXX", CommonConstant.serviceAddress + VERIFY_EMAIL_PATH + secret);
log.debug(url);
MailInfo info = new MailInfo(body.getEmail(), "验证邮箱", url);
MailUtil.sendMail(info, true);
RedisUtil.set(RedisConstant.getUpdateEmailKey(secret), String.valueOf(userId), TimeUtil.DAY_MS);
userDao.updateNewEmailByUserId(userId, body.getEmail());
}
use of com.fanxb.bookmark.common.exception.CustomException in project bookmark by FleyX.
the class EsUtil method init.
@PostConstruct
public void init() {
if (!status) {
return;
}
try {
if (client != null) {
client.close();
}
client = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, scheme)));
if (this.indexExist(EsConstant.BOOKMARK_INDEX)) {
return;
}
CreateIndexRequest request = new CreateIndexRequest(EsConstant.BOOKMARK_INDEX);
request.settings(Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 2));
request.mapping(EsConstant.CREATE_BOOKMARK_INDEX, XContentType.JSON);
CreateIndexResponse res = client.indices().create(request, RequestOptions.DEFAULT);
if (!res.isAcknowledged()) {
throw new CustomException("初始化失败");
}
} catch (Exception e) {
log.error("注意初始化es失败:{}:{}", host, port, e);
System.exit(0);
}
}
use of com.fanxb.bookmark.common.exception.CustomException in project bookmark by FleyX.
the class JwtUtil method decode.
/**
* Description: 解密jwt
*
* @param token token
* @param secret secret
* @return java.util.Map<java.lang.String, com.auth0.jwt.interfaces.Claim>
* @author fanxb
* @date 2019/3/4 18:14
*/
public static Map<String, Claim> decode(String token, String secret) {
if (token == null || token.length() == 0) {
throw new CustomException("token为空:" + token);
}
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier jwtVerifier = JWT.require(algorithm).build();
DecodedJWT decodedJWT = jwtVerifier.verify(token);
return decodedJWT.getClaims();
}
use of com.fanxb.bookmark.common.exception.CustomException in project bookmark by FleyX.
the class MailUtil method sendMail.
/**
* 功能描述: 发送邮件
*
* @param info 邮件体
* @param isHtml 是否为html邮件
* @author fanxb
* @date 2019/9/26 16:30
*/
public static void sendMail(MailInfo info, boolean isHtml) {
try {
MimeMessageHelper helper = new MimeMessageHelper(mailSender.createMimeMessage());
helper.setFrom(from);
helper.setTo(info.getReceiver());
helper.setSubject(info.getSubject());
helper.setText(info.getContent(), isHtml);
mailSender.send(helper.getMimeMessage());
} catch (Exception e) {
throw new CustomException("发送邮件失败:" + e.getMessage(), e);
}
}
Aggregations