Переглянути джерело

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/HHH_Home_Decoration_2 into master

jeter20131220 3 роки тому
батько
коміт
211abd20dd
2 змінених файлів з 58 додано та 41 видалено
  1. 6 6
      api/main.py
  2. 52 35
      desktop11/index.html

+ 6 - 6
api/main.py

@@ -86,12 +86,12 @@ async def create_req_detail(req:deco_request_detail):
     
     return_code = 0
     #return code 0=good, 1=email duplication, 2=phone duplication, 3= both duplicate
-    # if email_cnt>0 and phone_cnt==0:
-    #     return_code = 1
-    # if email_cnt==0 and phone_cnt>0:
-    #     return_code = 2
-    # if email_cnt>0 and phone_cnt>0:
-    #     return_code = 3
+    if email_cnt>0 and phone_cnt==0:
+        return_code = 1
+    if email_cnt==0 and phone_cnt>0:
+        return_code = 2
+    if email_cnt>0 and phone_cnt>0:
+        return_code = 3
     
     if return_code ==0 :
         request_table = db['deco_request']

+ 52 - 35
desktop11/index.html

@@ -30,6 +30,48 @@
 </head>
 
 <body id="top">
+<script>
+function statusChangeCallback(response) {  // Called with the results from FB.getLoginStatus().
+    if (response.status === 'connected') {  // 已登入
+        testAPI();  
+    }
+}
+
+function checkLoginState() {                 // Called when a person is finished with the Login Button.
+    FB.getLoginStatus(function(response) {   // See the onlogin handler
+        statusChangeCallback(response);
+    });
+}
+
+window.fbAsyncInit = function() {
+    FB.init({
+        appId      : '1388696554848391',
+        cookie     : true,            // Enable cookies to allow the server to access the session.
+        xfbml      : true,            // Parse social plugins on this webpage.
+        version    : 'v11.0'          // Use this Graph API version for this call.
+    });
+
+    FB.getLoginStatus(function(response) {   // Called after the JS SDK has been initialized.
+        statusChangeCallback(response);      // Returns the login status.
+    });
+};
+
+function testAPI() {
+    FB.api('/me/?fields=id,name,email', function(response) {
+        console.log('FB API回傳資料: ' + JSON.stringify(response));
+
+        if (response.id) {           
+            // 設定欄位預設值
+            document.getElementById("email").value = response.email;
+            document.getElementById("name").value = response.name;
+
+            // 隱藏FB登入按鈕
+            document.getElementById("fb_login").style.display = 'none';
+        }
+    });
+};
+</script>
+
     <div class="container-fluid" style="padding:0;margin:0 ">
         <div class="banner container-fluid" style="padding:0; margin:0 ">
             <!-- <section id="banner"> -->
@@ -363,10 +405,16 @@
                         </div>
                         <hr>
                         <div id="form-right">
-                            <div id="facebook" onclick='callFB()'>
+                            <!-- <div id="facebook" onclick='callFB()'>
                                 <img src="./img/logo/facebook.webp" alt="">
                                 使用FB填入信箱與姓名
+                            </div> -->
+                            
+                            <div id="fb_login">
+                                <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">使用FB填入信箱與姓名</fb:login-button>
+                                <div id="status"></div>
                             </div>
+                            
                             <input type="text" name="email" id="email" placeholder="請輸入信箱" required>
                             <input type="text" name="name" id="name" placeholder="請輸入姓名" required>
                             <input type="text" name="phone" id="phone" placeholder="請輸入電話" required>
@@ -400,40 +448,8 @@
 
 
 
-
-
-
-
-
-
-<!-- <script>
-window.fbAsyncInit = function() {
-    FB.init({
-    appId      : '582473075602626',
-    cookie     : true,
-    xfbml      : true,
-    version    : '{api-version}'
-    });
-    
-    FB.AppEvents.logPageView();   
-    
-};
-
-(function(d, s, id){
-    var js, fjs = d.getElementsByTagName(s)[0];
-    if (d.getElementById(id)) {return;}
-    js = d.createElement(s); js.id = id;
-    js.src = "https://connect.facebook.net/en_US/sdk.js";
-    fjs.parentNode.insertBefore(js, fjs);
-}(document, 'script', 'facebook-jssdk'));
-
-FB.getLoginStatus(function(response) {
-    statusChangeCallback(response);
-});
-</script> -->
-
-
-
+    <!-- Load the JS SDK asynchronously -->
+    <script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js"></script>
 
     <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
         integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
@@ -443,6 +459,7 @@ FB.getLoginStatus(function(response) {
         crossorigin="anonymous"></script>
 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
+
     <script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
 
     <script src="./goto.js"></script>