提交 e889e19d authored 作者: zgy's avatar zgy

优化登录功能

上级 b55beae9
...@@ -40,6 +40,13 @@ ...@@ -40,6 +40,13 @@
<artifactId>yunpian-java-sdk</artifactId> <artifactId>yunpian-java-sdk</artifactId>
<version>1.2.7</version> <version>1.2.7</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-elasticsearch -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!--springframework.boot--> <!--springframework.boot-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -200,11 +207,11 @@ ...@@ -200,11 +207,11 @@
</dependency> </dependency>
<!--net.sf.json-lib--> <!--net.sf.json-lib-->
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>org.apache.httpcomponents</groupId>--> <!-- <groupId>org.apache.httpcomponents</groupId>-->
<!-- <artifactId>httpclient</artifactId>--> <!-- <artifactId>httpclient</artifactId>-->
<!-- &lt;!&ndash;<version>4.5.2</version>&ndash;&gt;--> <!-- &lt;!&ndash;<version>4.5.2</version>&ndash;&gt;-->
<!-- </dependency>--> <!-- </dependency>-->
<!--apache httpclient--> <!--apache httpclient-->
......
...@@ -9,6 +9,7 @@ import com.diaoyun.zion.master.enums.ResultCodeEnum; ...@@ -9,6 +9,7 @@ import com.diaoyun.zion.master.enums.ResultCodeEnum;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apiguardian.api.API;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -104,4 +105,11 @@ public class LoginController extends BaseController { ...@@ -104,4 +105,11 @@ public class LoginController extends BaseController {
result.setData(userInfo); result.setData(userInfo);
return result; return result;
} }
@ApiOperation("验证手机号")
@GetMapping("/checkByPhone/{phone}")
public Result checkByPhone(@ApiParam("手机号") @PathVariable("phone") String phone) {
return tbCfUserInfoService.checkByPhone(phone);
}
} }
...@@ -70,4 +70,5 @@ public interface TbCfUserInfoDao extends BaseDao<TbCfUserInfoEntity> { ...@@ -70,4 +70,5 @@ public interface TbCfUserInfoDao extends BaseDao<TbCfUserInfoEntity> {
String findEmails(); String findEmails();
int updateIsSend(String email); int updateIsSend(String email);
} }
...@@ -4,7 +4,9 @@ import com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity; ...@@ -4,7 +4,9 @@ import com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity;
import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo; import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo;
import com.diaoyun.zion.master.base.Result; import com.diaoyun.zion.master.base.Result;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import io.swagger.annotations.ApiParam;
import org.apache.commons.mail.EmailException; import org.apache.commons.mail.EmailException;
import org.springframework.web.bind.annotation.PathVariable;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
...@@ -186,4 +188,6 @@ public interface TbCfUserInfoService { ...@@ -186,4 +188,6 @@ public interface TbCfUserInfoService {
String findEmails(); String findEmails();
int updateIsSend(String email); int updateIsSend(String email);
Result checkByPhone(String phone);
} }
package com.diaoyun.zion.chinafrica.service.impl; package com.diaoyun.zion.chinafrica.service.impl;
import autovalue.shaded.com.google$.common.collect.$BiMap;
import com.diaoyun.zion.chinafrica.constant.EmailTemplateConstant; import com.diaoyun.zion.chinafrica.constant.EmailTemplateConstant;
import com.diaoyun.zion.chinafrica.constant.KeyConstant; import com.diaoyun.zion.chinafrica.constant.KeyConstant;
import com.diaoyun.zion.chinafrica.dao.TbCfCouponDao; import com.diaoyun.zion.chinafrica.dao.TbCfCouponDao;
...@@ -45,10 +46,7 @@ import java.io.IOException; ...@@ -45,10 +46,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/** /**
* 用户表Service实现类 * 用户表Service实现类
...@@ -301,6 +299,10 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService { ...@@ -301,6 +299,10 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
String phone = "+" + phoneNum.trim(); String phone = "+" + phoneNum.trim();
Result result = new Result(); Result result = new Result();
TbCfUserInfoEntity user = tbCfUserInfoDao.checkUserByPhone(phone); TbCfUserInfoEntity user = tbCfUserInfoDao.checkUserByPhone(phone);
if (user == null) {
result.setData(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage("You haven't registered yet, please register first!");
return result;
}
String phoneCode = (String) captchaRedisCache.get(KeyConstant.CAPTCHA_PHONE + phone); String phoneCode = (String) captchaRedisCache.get(KeyConstant.CAPTCHA_PHONE + phone);
if (phoneCode == null) { if (phoneCode == null) {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode()).setMessage("Verification code failure"); result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode()).setMessage("Verification code failure");
...@@ -308,6 +310,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService { ...@@ -308,6 +310,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
} }
if (user != null && phoneCode.equals(code)) { if (user != null && phoneCode.equals(code)) {
result = loginByPhoneCode(ip, phone); result = loginByPhoneCode(ip, phone);
captchaRedisCache.delete(KeyConstant.CAPTCHA_PHONE + phone);
} else { } else {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode()); result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode());
result.setMessage("Login failed"); result.setMessage("Login failed");
...@@ -567,7 +570,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService { ...@@ -567,7 +570,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
} }
@Override @Override
public String findEmails() { public String findEmails() {
return tbCfUserInfoDao.findEmails(); return tbCfUserInfoDao.findEmails();
} }
...@@ -576,6 +579,20 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService { ...@@ -576,6 +579,20 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
return tbCfUserInfoDao.updateIsSend(email); return tbCfUserInfoDao.updateIsSend(email);
} }
@Override
public Result checkByPhone(String phone) {
Result result = new Result();
Map map = new HashMap();
boolean isRegistered = true;
TbCfUserInfoEntity user = tbCfUserInfoDao.checkUserByPhone("+" + phone.trim());
if (user == null) {
isRegistered = false;
}
map.put("isRegistered", isRegistered);
result.setData(map).setMessage(ResultCodeEnum.SUCCESS.getDesc());
return result;
}
/** /**
* 获取用户类型 * 获取用户类型
......
...@@ -115,6 +115,7 @@ public class SMSUtil { ...@@ -115,6 +115,7 @@ public class SMSUtil {
+ URLEncoder.encode(code, ENCODING); + URLEncoder.encode(code, ENCODING);
String s = SMSUtil.tplSendSms(API_KEY, tpl_id, tpl_value, phone); String s = SMSUtil.tplSendSms(API_KEY, tpl_id, tpl_value, phone);
System.out.println(s); System.out.println(s);
System.out.println(code);
return code; return code;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论