Parcourir la Source

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

Christian Matheus Batista Macedo il y a 6 ans
Parent
commit
261c687759
1 fichiers modifiés avec 19 ajouts et 12 suppressions
  1. 19 12
      js/functions.js

+ 19 - 12
js/functions.js

@@ -25,12 +25,12 @@ var mktSuite = (function(){
25 25
         url: urlAPIMkt + uri,
26 26
         data: data,
27 27
         type: method,
28
-        contentType: false,
29
-        processData: false,
28
+        // contentType: false,
29
+        // processData: false,
30 30
         crossDomain: true,
31 31
         beforeSend: function(xhr){
32 32
           xhr.setRequestHeader('Auth', auth)
33
-          xhr.setRequestHeader('Account', account)
33
+          xhr.setRequestHeader('account', account)
34 34
         },
35 35
         success: function(data) {
36 36
            success(data)
@@ -40,29 +40,36 @@ var mktSuite = (function(){
40 40
 
41 41
   var accounts = null
42 42
 
43
-  actions.authentication = function() {
43
+  actions.authentication = function(success) {
44 44
     call('GET', '/account', null, function (data) {
45
-      console.log(data);
46 45
       accounts = data.accounts;
47 46
         if (accounts != null) {
48
-          actions.validation(accounts[0])
49
-          console.log("ok");
47
+          actions.validation(accounts[0], success)
50 48
         } else {
51 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 69
   return actions
65 70
 
66 71
 })();
67 72
 
68
-mktSuite.authentication()
73
+mktSuite.authentication(function() {
74
+  mktSuite.contactList()
75
+})