refactor: 增加微信扫码登录
This commit is contained in:
parent
8741aadccb
commit
c51b14ae1b
@ -35,6 +35,8 @@ public interface IUserExpandDao {
|
|||||||
|
|
||||||
void updateUserId(Map<String, Object> params);
|
void updateUserId(Map<String, Object> params);
|
||||||
|
|
||||||
|
void delete(Map<String, Object> params);
|
||||||
|
|
||||||
UserExpandDTO get(Map<String, Object> params);
|
UserExpandDTO get(Map<String, Object> params);
|
||||||
|
|
||||||
UserExpandPO getPO(Map<String, Object> params);
|
UserExpandPO getPO(Map<String, Object> params);
|
||||||
|
@ -45,6 +45,7 @@ public class LoginWxUpdatePhoneConfig extends SecurityConfigurerAdapter<DefaultS
|
|||||||
@Override
|
@Override
|
||||||
public void configure(HttpSecurity http) throws Exception {
|
public void configure(HttpSecurity http) throws Exception {
|
||||||
super.configure(http);
|
super.configure(http);
|
||||||
|
|
||||||
LoginWxUpdatePhoneAuthFilter loginWxUpdatePhoneAuthFilter = new LoginWxUpdatePhoneAuthFilter(smsService);
|
LoginWxUpdatePhoneAuthFilter loginWxUpdatePhoneAuthFilter = new LoginWxUpdatePhoneAuthFilter(smsService);
|
||||||
loginWxUpdatePhoneAuthFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
|
loginWxUpdatePhoneAuthFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
|
||||||
loginWxUpdatePhoneAuthFilter.setAuthenticationFailureHandler(new LoginFailureHandler(baseProperties.getLoginFailure()));
|
loginWxUpdatePhoneAuthFilter.setAuthenticationFailureHandler(new LoginFailureHandler(baseProperties.getLoginFailure()));
|
||||||
|
@ -28,19 +28,23 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
|
|||||||
@Override
|
@Override
|
||||||
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
|
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
|
||||||
PhoneUpdateVO phoneUpdateVO = getPhoneUpdateVO(request);
|
PhoneUpdateVO phoneUpdateVO = getPhoneUpdateVO(request);
|
||||||
if (StringUtils.isBlank(phoneUpdateVO.getUserId())) {
|
|
||||||
throw new BadCredentialsException("userId不能为空");
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(phoneUpdateVO.getPhone())) {
|
|
||||||
throw new BadCredentialsException("更新手机号不能为空");
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(phoneUpdateVO.getSmsCode())) {
|
|
||||||
throw new BadCredentialsException("手机验证码不能为空");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
if (StringUtils.isBlank(phoneUpdateVO.getUserId())) {
|
||||||
|
throw new BadCredentialsException("userId不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(phoneUpdateVO.getPhone())) {
|
||||||
|
throw new BadCredentialsException("更新手机号不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(phoneUpdateVO.getSmsCode())) {
|
||||||
|
throw new BadCredentialsException("手机验证码不能为空");
|
||||||
|
}
|
||||||
smsService.checkVerifyCode(phoneUpdateVO.getPhone(), phoneUpdateVO.getSmsCode());
|
smsService.checkVerifyCode(phoneUpdateVO.getPhone(), phoneUpdateVO.getSmsCode());
|
||||||
} catch (ParamsException e) {
|
} catch (Exception e) {
|
||||||
throw new UserAuthenticationException(e.getMessage());
|
if (!StringUtils.isBlank(phoneUpdateVO.getErrorRedirectUrl())) {
|
||||||
|
response.sendRedirect("");
|
||||||
|
} else {
|
||||||
|
throw new UserAuthenticationException(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LoginWxUpdatePhoneAuthToken loginWxUpdatePhoneAuthToken = new LoginWxUpdatePhoneAuthToken(phoneUpdateVO.getUserId(), phoneUpdateVO);
|
LoginWxUpdatePhoneAuthToken loginWxUpdatePhoneAuthToken = new LoginWxUpdatePhoneAuthToken(phoneUpdateVO.getUserId(), phoneUpdateVO);
|
||||||
loginWxUpdatePhoneAuthToken.setDetails(authenticationDetailsSource.buildDetails(request));
|
loginWxUpdatePhoneAuthToken.setDetails(authenticationDetailsSource.buildDetails(request));
|
||||||
@ -51,18 +55,21 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
|
|||||||
String userId = request.getParameter("userId");
|
String userId = request.getParameter("userId");
|
||||||
String phone = request.getParameter("phone");
|
String phone = request.getParameter("phone");
|
||||||
String smsCode = request.getParameter("smsCode");
|
String smsCode = request.getParameter("smsCode");
|
||||||
return new PhoneUpdateVO(userId, phone, smsCode);
|
String errorRedirectUrl = request.getParameter("errorRedirectUrl");
|
||||||
|
return new PhoneUpdateVO(userId, phone, smsCode, errorRedirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PhoneUpdateVO {
|
public static class PhoneUpdateVO {
|
||||||
private String userId;
|
private String userId;
|
||||||
private String phone;
|
private String phone;
|
||||||
private String smsCode;
|
private String smsCode;
|
||||||
|
private String errorRedirectUrl;
|
||||||
|
|
||||||
public PhoneUpdateVO(String userId, String phone, String smsCode) {
|
public PhoneUpdateVO(String userId, String phone, String smsCode, String errorRedirectUrl) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.phone = phone;
|
this.phone = phone;
|
||||||
this.smsCode = smsCode;
|
this.smsCode = smsCode;
|
||||||
|
this.errorRedirectUrl = errorRedirectUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserId() {
|
public String getUserId() {
|
||||||
@ -88,6 +95,14 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
|
|||||||
public void setSmsCode(String smsCode) {
|
public void setSmsCode(String smsCode) {
|
||||||
this.smsCode = smsCode;
|
this.smsCode = smsCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getErrorRedirectUrl() {
|
||||||
|
return errorRedirectUrl == null ? "" : errorRedirectUrl.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorRedirectUrl(String errorRedirectUrl) {
|
||||||
|
this.errorRedirectUrl = errorRedirectUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import cn.com.tenlion.operator.pojo.pos.sys.callback.SysCallbackPO;
|
|||||||
import cn.com.tenlion.operator.service.sys.task.SysTaskService;
|
import cn.com.tenlion.operator.service.sys.task.SysTaskService;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import ink.wgink.exceptions.base.SystemException;
|
import ink.wgink.exceptions.base.SystemException;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.quartz.Job;
|
import org.quartz.Job;
|
||||||
import org.quartz.JobDataMap;
|
import org.quartz.JobDataMap;
|
||||||
import org.quartz.JobExecutionContext;
|
import org.quartz.JobExecutionContext;
|
||||||
@ -13,9 +14,11 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class SysCallbackTask implements Job {
|
public class SysCallbackTask implements Job {
|
||||||
|
|
||||||
@ -33,10 +36,16 @@ public class SysCallbackTask implements Job {
|
|||||||
LOG.debug("回调地址:{}", url);
|
LOG.debug("回调地址:{}", url);
|
||||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||||
httpURLConnection.setRequestMethod("POST");
|
httpURLConnection.setRequestMethod("POST");
|
||||||
httpURLConnection.setDoOutput(true);
|
|
||||||
httpURLConnection.setDoInput(true);
|
httpURLConnection.setDoInput(true);
|
||||||
|
httpURLConnection.setDoOutput(true);
|
||||||
httpURLConnection.setConnectTimeout(3000);
|
httpURLConnection.setConnectTimeout(3000);
|
||||||
httpURLConnection.connect();
|
httpURLConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
|
if (!StringUtils.isBlank(sysCallbackPO.getJsonBody())) {
|
||||||
|
try (DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream())) {
|
||||||
|
byte[] input = sysCallbackPO.getJsonBody().getBytes(StandardCharsets.UTF_8);
|
||||||
|
dos.write(input, 0, input.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
int responseCode = httpURLConnection.getResponseCode();
|
int responseCode = httpURLConnection.getResponseCode();
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
||||||
|
@ -468,7 +468,9 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx
|
|||||||
userExpandDao.updateUserId(params);
|
userExpandDao.updateUserId(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByUserIds(List<String> strings) {
|
public void deleteByUserIds(List<String> userIds) {
|
||||||
|
Map<String, Object> params = getHashMap(4);
|
||||||
|
params.put("userIds", userIds);
|
||||||
|
userExpandDao.delete(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,6 +257,16 @@
|
|||||||
user_id = #{userId}
|
user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<delete id="delete" parameterType="map">
|
||||||
|
DELETE FROM
|
||||||
|
sys_user_expand
|
||||||
|
WHERE
|
||||||
|
user_id IN
|
||||||
|
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
||||||
|
#{userId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<select id="get" parameterType="map" resultMap="userExpandDTO">
|
<select id="get" parameterType="map" resultMap="userExpandDTO">
|
||||||
SELECT
|
SELECT
|
||||||
price_additional_pkg,
|
price_additional_pkg,
|
||||||
|
Loading…
Reference in New Issue
Block a user