Browse Source

Changed on Login Stuff and visibility control.

jason.lu 6 years ago
parent
commit
e2c290eb9e
3 changed files with 83 additions and 24 deletions
  1. 39 0
      js/basic.js
  2. 21 0
      js/entrance.js
  3. 23 24
      sign-in1.html

+ 39 - 0
js/basic.js

@@ -333,5 +333,44 @@ function get_factor(a,b){
     }
 }
 
+function setCookieWithTimeout(name, value, liveMinutes) {
+    if (liveMinutes == undefined || liveMinutes == null) {
+        liveMinutes = 60 * 2;
+    }
+    if (typeof (liveMinutes) != 'number') {
+        liveMinutes = 60 * 2;//默认120分钟
+    }
+    var minutes = liveMinutes * 60 * 1000;
+    var exp = new Date();
+    exp.setTime(exp.getTime() + minutes + 8 * 3600 * 1000);
+    //path=/表示全站有效,而不是当前页
+    document.cookie = name + "=" + value + ";path=/;expires=" + exp.toUTCString();
+}
+
+function setCookie(c_name,value,expiredays)
+{
+    var exdate=new Date()
+    exdate.setDate(exdate.getDate()+expiredays)
+    document.cookie=c_name+ "=" +escape(value)+
+        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
+}
+
+function getCookie(c_name)
+{
+    if (document.cookie.length>0)
+    {
+        c_start=document.cookie.indexOf(c_name + "=")
+        if (c_start!=-1)
+        {
+            c_start=c_start + c_name.length+1
+            c_end=document.cookie.indexOf(";",c_start)
+            if (c_end==-1) c_end=document.cookie.length
+            return unescape(document.cookie.substring(c_start,c_end))
+        }
+    }
+    return "";
+}
+
+
 $(document).ready(on_document_load);
 get_server_url();

+ 21 - 0
js/entrance.js

@@ -4,6 +4,27 @@ var periodID = [];
 var periodname = [];
 var userId = utils_get_param("userId");
 
+
+if(userId == null){
+    var use = getCookie("doibyUser");
+    if(use == null){
+        // No Login
+        location.href="sign-in1.html?from=entrance-1";
+    }else{
+        userId = use;
+    }
+}else{
+    // 没问题
+    // 是否存在
+
+    var use = getCookie("doibyUser");
+    if(use == null){
+        // No Login
+    }else{
+        location.href="sign-in1.html?from=entrance-2";
+    }
+}
+
 function page_document_load() {
     new_data_group("denglu",function(gp){
         if(gp.counter === 2){

+ 23 - 24
sign-in1.html

@@ -92,34 +92,33 @@
     <script src="plugins/jquery-validation/jquery.validate.js"></script>
 
     <!-- Custom Js -->
-    <script src="js/admin.js"></script>
+    <script src="js/basic.js"></script>
     <script src="js/pages/examples/sign-in.js"></script>
-
     <script>
-        SV = "";
-        if(location.host.indexOf("niimei") == -1){
-            SV = "http://172.30.84.3:8803"
+    function gotoLogin(){
+        var password = $('input[name="password"]').val();
+        var username = $('input[name="username"]').val();
+        get_data("/server/fcWorker/login?u=" + username +
+                "&p="+ password, onlogin_finish);
+    }
+
+    function onlogin_finish(obj){
+
+        console.log("Login Outcome::");
+        console.log(obj);
+
+        obj = first_parse(this, obj);
+
+        if(obj.list === undefined || obj.list.length < 1){
+            send_alert("用户名密码错误");
+        }else{
+            // TODO: 判断是否存在flowMaster,是否有权限
+            setCookieWithTimeout("doibyUser", obj.list[0].userId);
+            alert("Cookie : " + getCookie("doibyUser"));
+            location.href = "denglu.html?userId=" + obj.list[0].userId;
         }
-        function gotoLogin(){
-            $.ajax({
-                url : SV+"/server/fcWorker/login?u="+$('input[name="username"]').val()+
-                "&p="+$('input[name="password"]').val()
-            }).done(function(obj){
-                console.log(obj);
-                alert(obj);
-                if(typeof obj == "string"){
-                    obj = JSON.parse(obj);
-                }
-                if(obj.ret != "10000" || obj.model.list == undefined || obj.model.list.length <= 0){
-                    alert("登录失败");
-                    return;
-                }
-                location.href="denglu.html?userId="+obj.model.list[0].userId;
-            }).fail(function(fa){
-                console.log(fa);
-                alert("登陆失败");
-            });
     }
+
     </script>
 </body>