Browse code

authentication is now at start :)

Louis authored on14/03/2019 23:43:12
Showing2 changed files
1 1
Binary files a/build/synocam_home_switch.pbw and b/build/synocam_home_switch.pbw differ
... ...
@@ -63,7 +63,7 @@ function get_status() {
63 63
       var server=localStorage.getItem('server');
64 64
       url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid;
65 65
       var xhr = new XMLHttpRequest();
66
-      
66
+
67 67
       xhr.open("GET", url,false);
68 68
       xhr.send();
69 69
 
... ...
@@ -107,31 +107,16 @@ function get_status() {
107 107
 
108 108
 function switch_home(bool) {
109 109
   var response;
110
-  sid="";
111 110
   console.log('---- authenticate');
112
-  if (localStorage.getItem('username')  && localStorage.getItem('password') && localStorage.getItem('server') ){
113
-    var username=localStorage.getItem('username');
114
-    var password=localStorage.getItem('password');
115
-    var server=localStorage.getItem('server');
116
-    var url = server + "/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account="+username+"&passwd="+password+"&session=SurveillanceStation&format=sid";
117
-    var xhr = new XMLHttpRequest();
118
-  
119
-    xhr.open("GET", url,false);
120
-    xhr.send();
121
-  
122
-    if(xhr.status == 200) {
123
-      response = JSON.parse(xhr.responseText);
124
-      if (response.success == true){
125
-        sid = response.data.sid;
126
-        console.log('------ sid = '+sid);
127
-      }
128
-    }else {
129
-      console.log('------Request returned error code ' + xhr.status.toString());
130
-    }
131
-  
132
-    if (sid != ""){
133
-      status = "";
134
-      console.log('---- get_status');
111
+  if (sid != ""){
112
+    status = "";
113
+    console.log('---- get_status');
114
+    if (localStorage.getItem('username')  && localStorage.getItem('password') && localStorage.getItem('server') ){
115
+      var username=localStorage.getItem('username');
116
+      var password=localStorage.getItem('password');
117
+      var server=localStorage.getItem('server');
118
+      var xhr = new XMLHttpRequest();
119
+      
135 120
       url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid;
136 121
       
137 122
       xhr.open("GET", url,false);
... ...
@@ -208,10 +193,10 @@ function switch_home(bool) {
208 193
       }else {
209 194
         console.log('------Request returned error code ' + xhr.status.toString());
210 195
       }
196
+    }else{
197
+      Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
211 198
     }
212
-   }else{
213
-    Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
214
-  }
199
+   }
215 200
 
216 201
 }
217 202