Advertisement
Guest User

Untitled

a guest
Mar 10th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. (function(){
  2. var ACS = require('ti.cloud'),
  3. env = Ti.App.deployType.toLowerCase() === 'production' ? 'production' : 'development',
  4. username = Ti.App.Properties.getString('acs-username-'+env),
  5. password = Ti.App.Properties.getString('acs-password-'+env);
  6.  
  7. // if not configured, just return
  8. if (!env || !username || !password) { return; }
  9. /**
  10. * Appcelerator Cloud (ACS) Admin User Login Logic
  11. *
  12. * fires login.success with the user as argument on success
  13. * fires login.failed with the result as argument on error
  14. */
  15. ACS.Users.login({
  16. login:username,
  17. password:password,
  18. }, function(result){
  19. if (env==='development') {
  20. Ti.API.info('ACS Login Results for environment `'+env+'`:');
  21. Ti.API.info(result);
  22. }
  23. if (result && result.success && result.users && result.users.length){
  24. Ti.App.fireEvent('login.success',result.users[0],env);
  25.  
  26. ACS.Objects.query({
  27. classname: 'car123',
  28. limit:50
  29.  
  30. }, function (e) {
  31. if (e.success) {
  32. alert('Success:\n' +
  33. 'Count: ' + e.car123.length);
  34.  
  35. Ti.API.info('Success:\n' +
  36. 'Count: ' + e.car123.length);
  37. for (var i = 0; i < e.car123.length; i++) {
  38. var car123 = e.car123[i];
  39. Ti.API.info('id: ' + car123.id + '\n' +
  40. 'make: ' + car123.make + '\n' +
  41. 'color: ' + car123.color + '\n' +
  42. 'year: ' + car123.year + '\n' +
  43. 'created_at: ' + car123.created_at);
  44. }
  45. } else {
  46. alert('Error:\n' +
  47. ((e.error && e.message) || JSON.stringify(e)));
  48. }
  49. });
  50. } else {
  51. Ti.App.fireEvent('login.failed',result,env);
  52. }
  53. });
  54.  
  55. })();
  56.  
  57.  
  58. //Console logs:
  59.  
  60. [INFO] : Success:
  61. [INFO] : Count: 12
  62. [INFO] : id: 56e0face550a68090a524cde
  63. [INFO] : make: tata
  64. [INFO] : color: blue
  65. [INFO] : year: 2005
  66. [INFO] : created_at: 2016-03-10T04:40:46+0000
  67. [INFO] : id: 56e0fab08d7af309083b984f
  68. [INFO] : make: kkkk
  69. [INFO] : color: blue
  70. [INFO] : year: 2005
  71. [INFO] : created_at: 2016-03-10T04:40:16+0000
  72. [INFO] : id: 56e0faa053586409123c73b0
  73. [INFO] : make: eerr
  74. [INFO] : color: blue
  75. [INFO] : year: 2005
  76. [INFO] : created_at: 2016-03-10T04:40:00+0000
  77. [INFO] : id: 56e0fa8dd1f2370908bd4f04
  78. [INFO] : make: yoyota
  79. [INFO] : color: blue
  80. [INFO] : year: 2005
  81. [INFO] : created_at: 2016-03-10T04:39:41+0000
  82. [INFO] : id: 56e0fa7a8d7af309083b983a
  83. [INFO] : make: weqwedqweqweqweq
  84. [INFO] : color: red
  85. [INFO] : year: 2005
  86. [INFO] : created_at: 2016-03-10T04:39:22+0000
  87. [INFO] : id: 56e0fa5fa778ca090853878e
  88. [INFO] : make: scqwhgfsqghws
  89. [INFO] : color: blue
  90. [INFO] : year: 2005
  91. [INFO] : created_at: 2016-03-10T04:38:55+0000
  92. [INFO] : id: 56e0fa4cd1f2370910bc6fcb
  93. [INFO] : make: sdadasdissan
  94. [INFO] : color: blue
  95. [INFO] : year: 2005
  96. [INFO] : created_at: 2016-03-10T04:38:36+0000
  97. [INFO] : id: 56e0fa3853586409123c736b
  98. [INFO] : make: wswqs
  99. [INFO] : color: blue
  100. [INFO] : year: 2005
  101. [INFO] : created_at: 2016-03-10T04:38:16+0000
  102. [INFO] : id: 56e0fa2640a96d090d931018
  103. [INFO] : make: abcd
  104. [INFO] : color: blue
  105. [INFO] : year: 2005
  106. [INFO] : created_at: 2016-03-10T04:37:58+0000
  107. [INFO] : id: 56e0fa148d7af309083b97d0
  108. [INFO] : make: pissan
  109. [INFO] : color: blue
  110. [INFO] : year: 2005
  111. [INFO] : created_at: 2016-03-10T04:37:40+0000
  112. [INFO] : id: 56cecbc821498909250017e0
  113. [INFO] : make: nissan
  114. [INFO] : color: blue
  115. [INFO] : year: 2005
  116. [INFO] : created_at: 2016-02-25T09:39:20+0000
  117. [INFO] : id: 56cecb86cd9aab0920001776
  118. [INFO] : make: nissan
  119. [INFO] : color: blue
  120. [INFO] : year: 2005
  121. [INFO] : created_at: 2016-02-25T09:38:14+0000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement