Browse Source

obtenção do token atraves do /Auth e GET no contactList

Christian Matheus Batista Macedo 6 years ago
parent
commit
261c687759
1 changed files with 19 additions and 12 deletions
  1. 19 12
      js/functions.js

+ 19 - 12
js/functions.js

25
         url: urlAPIMkt + uri,
25
         url: urlAPIMkt + uri,
26
         data: data,
26
         data: data,
27
         type: method,
27
         type: method,
28
-        contentType: false,
29
-        processData: false,
28
+        // contentType: false,
29
+        // processData: false,
30
         crossDomain: true,
30
         crossDomain: true,
31
         beforeSend: function(xhr){
31
         beforeSend: function(xhr){
32
           xhr.setRequestHeader('Auth', auth)
32
           xhr.setRequestHeader('Auth', auth)
33
-          xhr.setRequestHeader('Account', account)
33
+          xhr.setRequestHeader('account', account)
34
         },
34
         },
35
         success: function(data) {
35
         success: function(data) {
36
            success(data)
36
            success(data)
40
 
40
 
41
   var accounts = null
41
   var accounts = null
42
 
42
 
43
-  actions.authentication = function() {
43
+  actions.authentication = function(success) {
44
     call('GET', '/account', null, function (data) {
44
     call('GET', '/account', null, function (data) {
45
-      console.log(data);
46
       accounts = data.accounts;
45
       accounts = data.accounts;
47
         if (accounts != null) {
46
         if (accounts != null) {
48
-          actions.validation(accounts[0])
49
-          console.log("ok");
47
+          actions.validation(accounts[0], success)
50
         } else {
48
         } else {
51
           alert("Não possui contas")
49
           alert("Não possui contas")
52
         }
50
         }
53
     })
51
     })
54
   }
52
   }
55
 
53
 
56
-  actions.validation = function (account) {
57
-    var token = account.token
58
-    call('POST', '/account/auth', {"account" : token}, function () {
59
-
54
+  actions.validation = function (data, success) {
55
+    var token = data.token
56
+    call('POST', '/account/auth', { account: token }, function (data) {
57
+      account = data.token
58
+      success()
59
+      console.log(account);
60
     })
60
     })
61
+  }
61
 
62
 
63
+  actions.contactList = function () {
64
+    call('GET', '/contactlist', null, function (data) {
65
+      console.log(data);
66
+    })
62
   }
67
   }
63
 
68
 
64
   return actions
69
   return actions
65
 
70
 
66
 })();
71
 })();
67
 
72
 
68
-mktSuite.authentication()
73
+mktSuite.authentication(function() {
74
+  mktSuite.contactList()
75
+})