Browse Source

add invitation

huai-sian 3 years ago
parent
commit
5c3f189c1f
5 changed files with 157 additions and 5 deletions
  1. 1 1
      html/invite.html
  2. 146 0
      html/invite.js
  3. 7 2
      html/script_profile.js
  4. 2 1
      html/static/script_slides.js
  5. 1 1
      html/user_profile2.html

+ 1 - 1
html/invite.html

@@ -176,7 +176,7 @@
         integrity="sha512-Y/Pox7RqKmT84klgmJCva3drWoXQWO42oHiWWhb9zd1pkIH60NF2SamgBrFHOTzrzHJhwgPGNGjNJ5ZmxLpUAQ=="
         crossorigin="anonymous" referrerpolicy="no-referrer"></script>
     <script src="static/owl.carousel.min.js"></script>
-    <script src="register.js"></script>
+    <script src="invite.js"></script>
     <script type="text/javascript" src="static/lan.js"></script>
     <script src="static/common.js"></script>
 </body>

+ 146 - 0
html/invite.js

@@ -0,0 +1,146 @@
+const btnRegister = document.querySelector('.btn-register');
+const btnLoginPage = document.querySelector('.btn-login');
+const btnUserProfile = document.querySelector('.btn-userProfile');
+const btnLogout = document.querySelector('.btn-logout');
+const registerPassword = document.querySelector('#register #password');
+const btnLoginPage_d = document.querySelector('.login-top .btn-login');
+const btnUserProfile_d = document.querySelector('.login-top .btn-userProfile');
+const btnLogout_d= document.querySelector('.login-top .btn-logout');
+
+registerPassword.addEventListener('keyup', registerByEnter);
+btnRegister.addEventListener('click', register);
+
+function registerByEnter(e) {
+    if (e.keyCode === 13) {
+        e.preventDefault();
+        console.log('login!');
+        register();
+    }
+};
+
+function validateEmail(email) {
+    const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
+    if(re.test(String(email).toLowerCase()) === false) {
+        $('#register [name = "email"]').addClass('error');
+        if( !$('.error-text').length ) {
+            let msg = '請輸入正確E-mail';
+
+            if (lang == 'en') { 
+                msg = 'Please enter valid Email format.';
+            }
+
+            $('input.error').after('<p class="error-text" set-lan="html:errorEmail">' + msg + '</p>');
+        } 
+    } else {
+        $('#register [name = "email"]').removeClass('error');
+        $('.error-text').remove();
+    }
+    
+    return re.test(String(email).toLowerCase());
+}
+
+function validatePassword(psd) {
+    if(psd.length >=4) {
+        $('#register [name = "password"]').removeClass('error');
+        $('.error-text').remove();
+        return true;
+    } else {
+        $('#register [name = "password"]').addClass('error');
+        if( !$('.error-text').length ) {
+            $('input.error').after('<p class="error-text" set-lan="html:errorPsd">密碼至少為4個字元</p>');
+        } 
+        return false;
+    }
+}
+
+function getpathId() {
+  id = window.location.search.split('?').pop();
+  if(id.split('=')[0] === 'code') {
+    return id.split('=')[1];
+  }
+}
+
+function register() {
+    let url = 'https://www.choozmo.com:8887/register';
+    let userName = $('#register [name = "username"]').val();
+    let email = $('#register [name = "email"]').val();
+    let password = $('#register [name = "password"]').val();
+    let code = getpathId();
+
+    let userObj = {
+      username: userName,
+      email,
+      password
+    }
+
+    if(code) {
+      url = 'https://www.choozmo.com:8887/register_by_invite';
+      userObj = {
+        username: userName,
+        email,
+        password,
+        code: code
+      }
+    }
+
+    // 註冊資料檢查
+    if (username == '' || password == '') {
+        let title = "註冊失敗";
+        let text = "請先輸入您的帳號/密碼";
+
+        if (lang == 'en') { 
+            title = "Login Failed!";
+            text = "Please enter your username and password";
+        }
+
+        Swal.fire({
+            title: title,
+            icon: 'error',
+            text: text,
+            confirmButtonColor: '#3085d6',
+        });
+
+        return;
+    }
+
+    if(userName && validateEmail(email) && validatePassword(password)) {
+        console.log(userObj);
+        const headers = {
+            "accept": "application/json",
+            "Content-Type": "application/json"
+        }
+        axios({
+            method: 'post',
+            url: 'https://www.choozmo.com:8887/register',
+            headers: headers,
+            data: userObj
+        }).then(res => {
+            console.log(res.data.msg);
+            let text;
+            if (lang == 'en') { 
+                text = res.data.msg.eng;
+            } else {
+                text = res.data.msg.zh;
+            }
+            Swal.fire({
+                icon: 'info',
+                text: text,
+                confirmButtonColor: '#3085d6',
+            });
+        }).catch(err => {
+            console.log(err);
+        })
+    }
+}
+
+
+function loginControl() {
+    btnLoginPage.style.display = 'block';
+    btnLogout.style.display = 'none';
+    btnUserProfile.style.display = 'none';
+    btnLoginPage_d.style.display = 'block';
+    btnLogout_d.style.display = 'none';
+    btnUserProfile_d.style.display = 'none';
+}
+
+loginControl();

+ 7 - 2
html/script_profile.js

@@ -11,6 +11,7 @@ function getCookie(name) {
 }
 
 let userBasics = JSON.parse(localStorage.getItem('user_profile')) || [];
+let inviteCode;
 
 function checkLocal() {
   if(userBasics.length == 0){ return };
@@ -82,7 +83,12 @@ function renderView() {
               }
             });
           }
+        $('.fb-share-button').attr('data-href', `https://video.choozmo.com?code=${userInfo.user_info.invite_code}`);
+        console.log($('.fb-share-button').attr('data-href'));
+        $('.share-twitter').attr('href',
+        `https://twitter.com/intent/tweet?text=I%20just%20created%20a%20video%20in%205%20minutes.%20Check%20it%20out%20%F0%9F%91%89%20https%3A%2F%2Fvideo.choozmo.com/invite.html?code=${userInfo.user_info.invite_code}&related=ai_cmm`)
         
+        inviteCode = userInfo.user_info.invite_code;
         const str = `<img src="static/img/undraw_male_avatar_323b.svg" alt="">
         <p class="card-profile-txt">User Profile</p>
         <p class="card-profile-cnt">${userInfo.user_info.userName}</p>
@@ -384,8 +390,7 @@ function deleteDraft(id) {
 $('.share-email').click(function() {
   var link = `mailto:me@example.com?subject=
   ${encodeURIComponent("Check out AI Spokesgirl")}
-  &body=${encodeURIComponent('I just created a video in 5 minutes, check out this amazing video making tool. https://video.choozmo.com/')}`;
-    
+  &body=${encodeURIComponent(`I just created a video in 5 minutes, check out this amazing video making tool. https://video.choozmo.com/invite.html?code=${inviteCode}`)}`;
     window.location.href = link;
 });
 

+ 2 - 1
html/static/script_slides.js

@@ -191,8 +191,9 @@ $("#send_slide").click(function () {
   var step;
   multiLang = 0
   if ($('#multiLang').prop("checked")) {multiLang = 1;}
-  dataOBJ = {'slide_url':$('#slide_raw_url').val(),"avatar": avatar,"multiLang":multiLang, "client_id": client_id }
+  dataOBJ = {'slide_url':$('#slide_raw_url').val(),"avatar": avatar,"multiLang":multiLang, "client_id": client_id, "url_type": 0 }
   objstr = JSON.stringify(dataOBJ);
+  console.log(objstr)
   jwt_token =  get_jwt_token()
   var xhr = new XMLHttpRequest();
   xhr.open("POST", "https://www.choozmo.com:8887/make_anchor_video_gSlide");

+ 1 - 1
html/user_profile2.html

@@ -327,7 +327,7 @@
                                                             <span class="facebook"
                                                                 style="position: relative; bottom:2px;">Facebook</span>
                                                         </div>
-                                                        <a class="mx-2 mx-lg-4 text-center"
+                                                        <a class="mx-2 mx-lg-4 text-center share-twitter"
                                                             href="https://twitter.com/intent/tweet?text=I%20just%20created%20a%20video%20in%205%20minutes.%20Check%20it%20out%20%F0%9F%91%89%20https%3A%2F%2Fvideo.choozmo.com/&related=ai_cmm"
                                                             target="_blank">
                                                             <img width="28" class="me-2"