From 13a5f7b7c1bd7733f62f2e76e15ce3660441df98 Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期二, 01 三月 2022 15:36:00 +0800
Subject: [PATCH] [update] [todo 135940] 顧問預約未處理的網址,導到顧問登入頁面

---
 pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java b/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java
index 54391f0..afef2d0 100644
--- a/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java
+++ b/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java
@@ -6,8 +6,8 @@
 import com.pollex.pam.enums.ConsultantDetailEnum;
 import com.pollex.pam.repository.ConsultantRepository;
 import com.pollex.pam.security.token.EServiceAuthenticationToken;
-import com.pollex.pam.service.LoginRecordService;
 import com.pollex.pam.service.dto.EServiceResponse;
+import com.pollex.pam.web.rest.errors.ConsultantDisableException;
 import com.pollex.pam.web.rest.errors.EServiceErrorException;
 import org.apache.http.conn.ssl.NoopHostnameVerifier;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -37,7 +37,10 @@
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 import java.security.cert.X509Certificate;
+import java.time.Instant;
 import java.util.*;
+
+import static com.pollex.pam.enums.ConsultantStatusEnum.DISABLE;
 
 @Component
 public class EServiceAuthenticationProvider {
@@ -51,16 +54,12 @@
     @Autowired
     ConsultantRepository consultantRepository;
 
-    @Autowired
-    LoginRecordService loginRecordService;
-
     public Authentication authenticate(EServiceAuthenticationToken authenticationToken) throws AuthenticationException {
         String account = authenticationToken.getPrincipal();
         String credentials = authenticationToken.getCredentials();
 
         if(applicationProperty.isMockLogin()){
-            loginRecordService.saveEServiceLoginSuccessRecord(account);
-            return getConsultantToken(account, credentials);
+            return getConsultantTokenAndRecordLoginTime(account, credentials);
         }
 
         try {
@@ -70,11 +69,9 @@
                 log.debug("eService response = {}", eServiceResponse);
 
                 if(E_SERVICE_LOGIN_SUCCESS_CODE.equals(eServiceResponse.getIssuccess())){
-                    loginRecordService.saveEServiceLoginSuccessRecord(account);
-                    return getConsultantToken(account, credentials);
+                    return getConsultantTokenAndRecordLoginTime(account, credentials);
                 }
                 else {
-                    loginRecordService.saveEServiceLoginFailRecord(account, eServiceResponse.getMsg());
                     throw new EServiceErrorException(eServiceResponse.getMsg());
                 }
             }
@@ -87,9 +84,16 @@
         }
     }
 
-    private UsernamePasswordAuthenticationToken getConsultantToken(String account, String credential) {
+    private UsernamePasswordAuthenticationToken getConsultantTokenAndRecordLoginTime(String account, String credential) throws ConsultantDisableException {
         Consultant consultant = consultantRepository.findOneByAgentNo(account).orElseThrow(() -> new UsernameNotFoundException("閰脤“����蒂銝��慦�像�蝟餌絞銝�"));
 
+        if(consultant.getStatus() == DISABLE) {
+            throw new ConsultantDisableException();
+        }
+
+        consultant.setLatestLoginTime(Instant.now());
+        consultantRepository.save(consultant);
+
         List<GrantedAuthority> grantedAuths = Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
         UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(account, credential, grantedAuths);
 

--
Gitblit v1.8.0