|
@@ -3,11 +3,9 @@ package com.caimei365.user.service.impl;
|
|
import com.caimei365.user.mapper.BaseMapper;
|
|
import com.caimei365.user.mapper.BaseMapper;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.components.RedisService;
|
|
import com.caimei365.user.components.RedisService;
|
|
|
|
+import com.caimei365.user.model.dto.PasswordDto;
|
|
import com.caimei365.user.service.BaseService;
|
|
import com.caimei365.user.service.BaseService;
|
|
-import com.caimei365.user.utils.AliyunSmsUtil;
|
|
|
|
-import com.caimei365.user.utils.CodeUtil;
|
|
|
|
-import com.caimei365.user.utils.ImageCaptchaUtil;
|
|
|
|
-import com.caimei365.user.utils.ValidateUtil;
|
|
|
|
|
|
+import com.caimei365.user.utils.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -107,15 +105,6 @@ public class BaseServiceImpl implements BaseService {
|
|
// 验证手机号
|
|
// 验证手机号
|
|
String result = ValidateUtil.validateMobile(mobile);
|
|
String result = ValidateUtil.validateMobile(mobile);
|
|
if (result != null) {return ResponseJson.error(result);}
|
|
if (result != null) {return ResponseJson.error(result);}
|
|
- if (StringUtils.isNotBlank(profile)) {
|
|
|
|
- // 开发 和 测试环境 固定短信验证码 666666
|
|
|
|
- if("dev".equals(profile) || "beta".equals(profile)){
|
|
|
|
- redisService.set("code:"+mobile, "666666", 1800L);
|
|
|
|
- String codeType = activateCodeType == 1 ? "找回密码" : (activateCodeType == 2 ? "注册机构" : "注册供应商");
|
|
|
|
- log.info(codeType + ",发送到:" + mobile + "的短信验证码("+ profile +")为: 666666");
|
|
|
|
- return ResponseJson.success("发送验证码成功");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
// 检查图片验证码
|
|
// 检查图片验证码
|
|
if (null == isCheckCaptcha || 0 == isCheckCaptcha){
|
|
if (null == isCheckCaptcha || 0 == isCheckCaptcha){
|
|
Boolean checkFlag = checkCaptchaImage(token, imgCode, platformType);
|
|
Boolean checkFlag = checkCaptchaImage(token, imgCode, platformType);
|
|
@@ -126,6 +115,10 @@ public class BaseServiceImpl implements BaseService {
|
|
boolean sendFlag = false;
|
|
boolean sendFlag = false;
|
|
// 生成六位验证码
|
|
// 生成六位验证码
|
|
String randomCode = CodeUtil.generateCodeInt(6);
|
|
String randomCode = CodeUtil.generateCodeInt(6);
|
|
|
|
+ if ("dev".equals(profile) || "beta".equals(profile)){
|
|
|
|
+ // 开发 和 测试环境 固定短信验证码 666666
|
|
|
|
+ randomCode = "666666";
|
|
|
|
+ }
|
|
// 根据手机号查询用户Id
|
|
// 根据手机号查询用户Id
|
|
Integer userId = baseMapper.getUserIdByMobile(mobile);
|
|
Integer userId = baseMapper.getUserIdByMobile(mobile);
|
|
if (1 == activateCodeType) {
|
|
if (1 == activateCodeType) {
|
|
@@ -173,14 +166,6 @@ public class BaseServiceImpl implements BaseService {
|
|
// 验证手机号
|
|
// 验证手机号
|
|
String result = ValidateUtil.validateMobile(mobile);
|
|
String result = ValidateUtil.validateMobile(mobile);
|
|
if (result != null) {return ResponseJson.error(result);}
|
|
if (result != null) {return ResponseJson.error(result);}
|
|
- if (StringUtils.isNotBlank(profile)) {
|
|
|
|
- // 开发 和 测试环境 固定短信验证码 666666
|
|
|
|
- if("dev".equals(profile) || "beta".equals(profile)){
|
|
|
|
- redisService.set("code:"+mobile, "666666", 1800L);
|
|
|
|
- log.info("绑定账号,发送到:" + mobile + "的短信验证码("+ profile +")为: 666666");
|
|
|
|
- return ResponseJson.success("发送验证码成功");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
// 检查图片验证码
|
|
// 检查图片验证码
|
|
if (null == isCheckCaptcha || 0 == isCheckCaptcha){
|
|
if (null == isCheckCaptcha || 0 == isCheckCaptcha){
|
|
Boolean checkFlag = checkCaptchaImage(token, imgCode, platformType);
|
|
Boolean checkFlag = checkCaptchaImage(token, imgCode, platformType);
|
|
@@ -215,6 +200,10 @@ public class BaseServiceImpl implements BaseService {
|
|
}
|
|
}
|
|
// 生成六位验证码
|
|
// 生成六位验证码
|
|
String randomCode = CodeUtil.generateCodeInt(6);
|
|
String randomCode = CodeUtil.generateCodeInt(6);
|
|
|
|
+ if ("dev".equals(profile) || "beta".equals(profile)){
|
|
|
|
+ // 开发 和 测试环境 固定短信验证码 666666
|
|
|
|
+ randomCode = "666666";
|
|
|
|
+ }
|
|
String userName = baseMapper.getUserNameByUserId(userId);
|
|
String userName = baseMapper.getUserNameByUserId(userId);
|
|
// 欢迎成为${name}的运营人员,您的邀请码为${code}。
|
|
// 欢迎成为${name}的运营人员,您的邀请码为${code}。
|
|
boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 11, "{name:"+ userName +",code:"+ randomCode +"}");
|
|
boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 11, "{name:"+ userName +",code:"+ randomCode +"}");
|
|
@@ -231,4 +220,119 @@ public class BaseServiceImpl implements BaseService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取邮箱验证码
|
|
|
|
+ *
|
|
|
|
+ * @param email 邮箱
|
|
|
|
+ * @param status 1:绑定邮箱,2邮箱注册,3邮箱找回秘密
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson getEmailCode(String email, Integer status) {
|
|
|
|
+ // 验证邮箱
|
|
|
|
+ if (!ValidateUtil.validateEmail(email)) {
|
|
|
|
+ return ResponseJson.error("邮箱格式不正确");
|
|
|
|
+ }
|
|
|
|
+ Integer dbUserId = baseMapper.getUserIdByEmail(email);
|
|
|
|
+ try {
|
|
|
|
+ // 生成六位验证码
|
|
|
|
+ String randomCode = CodeUtil.generateCodeInt(6);
|
|
|
|
+ if ("dev".equals(profile) || "beta".equals(profile)){
|
|
|
|
+ // 开发 和 测试环境 固定短信验证码 666666
|
|
|
|
+ randomCode = "666666";
|
|
|
|
+ }
|
|
|
|
+ String html = EmailUtil.setMailCode(status, randomCode);
|
|
|
|
+ String subject = "";
|
|
|
|
+ // status 1:绑定邮箱,2邮箱注册,3邮箱找回秘密
|
|
|
|
+ if (status == 1) {
|
|
|
|
+ if (dbUserId != null) {
|
|
|
|
+ return ResponseJson.error("该邮箱已被使用");
|
|
|
|
+ }
|
|
|
|
+ subject = "采美365网邮箱绑定验证邮件";
|
|
|
|
+ } else if (status == 2) {
|
|
|
|
+ if (dbUserId != null) {
|
|
|
|
+ return ResponseJson.error("该邮箱已被使用");
|
|
|
|
+ }
|
|
|
|
+ subject = "采美365网注册验证邮件";
|
|
|
|
+ } else if (status == 3) {
|
|
|
|
+ if (dbUserId == null) {
|
|
|
|
+ return ResponseJson.error("该邮箱尚未注册");
|
|
|
|
+ }
|
|
|
|
+ subject = "采美365网修改密码验证邮件";
|
|
|
|
+ }
|
|
|
|
+ EmailUtil.sendMail(email, subject, html);
|
|
|
|
+ redisService.set("code:"+email, randomCode, 1800L);
|
|
|
|
+ log.info( "subject,发送到:" + email + "的验证码为: " + randomCode);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return ResponseJson.error("发送验证码失败");
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success("发送验证码成功", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改密码(找回密码)
|
|
|
|
+ *
|
|
|
|
+ * @param passwordDto {
|
|
|
|
+ * mobileOrEmail 手机号或邮箱
|
|
|
|
+ * smsCode 短信验证码(旧:activationCode)
|
|
|
|
+ * password 密码
|
|
|
|
+ * confirmPwd 确认密码
|
|
|
|
+ * status 1:手机号找回,2:邮箱找回
|
|
|
|
+ * }
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson updatePassword(PasswordDto passwordDto) {
|
|
|
|
+ String mobileOrEmail = passwordDto.getMobileOrEmail();
|
|
|
|
+ String smsCode = passwordDto.getSmsCode();
|
|
|
|
+ String passWord = passwordDto.getPassword();
|
|
|
|
+ String confirmPwd = passwordDto.getPassWordConfirm();
|
|
|
|
+ Integer status = passwordDto.getStatus();
|
|
|
|
+ if (status == 1) {
|
|
|
|
+ // 验证手机号
|
|
|
|
+ String result = ValidateUtil.validateMobile(mobileOrEmail);
|
|
|
|
+ if (result != null) {return ResponseJson.error(result);}
|
|
|
|
+ } else {
|
|
|
|
+ // 验证邮箱
|
|
|
|
+ if (!ValidateUtil.validateEmail(mobileOrEmail)) {
|
|
|
|
+ return ResponseJson.error("邮箱格式不正确");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(smsCode)) {
|
|
|
|
+ return ResponseJson.error("请输入验证码");
|
|
|
|
+ }
|
|
|
|
+ String redisSmsCode = (String) redisService.get("code:" + mobileOrEmail);
|
|
|
|
+ // 开发 和 测试环境 固定短信验证码 666666
|
|
|
|
+ if ("dev".equals(profile) || "beta".equals(profile)){
|
|
|
|
+ redisSmsCode = (null != redisSmsCode && !"null".equals(redisSmsCode) ? redisSmsCode : "666666");
|
|
|
|
+ }
|
|
|
|
+ if (!smsCode.equals(redisSmsCode)) {
|
|
|
|
+ return ResponseJson.error("验证码错误");
|
|
|
|
+ }
|
|
|
|
+ // 查找用户表是否存在
|
|
|
|
+ Integer dbUserId;
|
|
|
|
+ if (status == 1) {
|
|
|
|
+ dbUserId = baseMapper.getUserIdByMobile(mobileOrEmail);
|
|
|
|
+ if (dbUserId == null) {
|
|
|
|
+ return ResponseJson.error("该手机号尚未注册");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ dbUserId = baseMapper.getUserIdByEmail(mobileOrEmail);
|
|
|
|
+ if (dbUserId == null) {
|
|
|
|
+ return ResponseJson.error("该邮箱尚未注册");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(passWord)) {
|
|
|
|
+ return ResponseJson.error("请输入新密码");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(confirmPwd)) {
|
|
|
|
+ return ResponseJson.error("请确认密码");
|
|
|
|
+ }
|
|
|
|
+ if (!passWord.equals(confirmPwd)) {
|
|
|
|
+ return ResponseJson.error("两次输入的密码不一致");
|
|
|
|
+ }
|
|
|
|
+ // 设置密码
|
|
|
|
+ String dbPassword = Md5Util.md5(passWord);
|
|
|
|
+ baseMapper.updatePasswordByUserId(dbPassword, dbUserId);
|
|
|
|
+ return ResponseJson.success("密码修改成功", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|