Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- var ACS = require('ti.cloud'),
- env = Ti.App.deployType.toLowerCase() === 'production' ? 'production' : 'development',
- username = Ti.App.Properties.getString('acs-username-'+env),
- password = Ti.App.Properties.getString('acs-password-'+env);
- // if not configured, just return
- if (!env || !username || !password) { return; }
- /**
- * Appcelerator Cloud (ACS) Admin User Login Logic
- *
- * fires login.success with the user as argument on success
- * fires login.failed with the result as argument on error
- */
- ACS.Users.login({
- login:username,
- password:password,
- }, function(result){
- if (env==='development') {
- Ti.API.info('ACS Login Results for environment `'+env+'`:');
- Ti.API.info(result);
- }
- if (result && result.success && result.users && result.users.length){
- Ti.App.fireEvent('login.success',result.users[0],env);
- ACS.Objects.query({
- classname: 'car123',
- limit:50
- }, function (e) {
- if (e.success) {
- alert('Success:\n' +
- 'Count: ' + e.car123.length);
- Ti.API.info('Success:\n' +
- 'Count: ' + e.car123.length);
- for (var i = 0; i < e.car123.length; i++) {
- var car123 = e.car123[i];
- Ti.API.info('id: ' + car123.id + '\n' +
- 'make: ' + car123.make + '\n' +
- 'color: ' + car123.color + '\n' +
- 'year: ' + car123.year + '\n' +
- 'created_at: ' + car123.created_at);
- }
- } else {
- alert('Error:\n' +
- ((e.error && e.message) || JSON.stringify(e)));
- }
- });
- } else {
- Ti.App.fireEvent('login.failed',result,env);
- }
- });
- })();
- //Console logs:
- [INFO] : Success:
- [INFO] : Count: 12
- [INFO] : id: 56e0face550a68090a524cde
- [INFO] : make: tata
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:40:46+0000
- [INFO] : id: 56e0fab08d7af309083b984f
- [INFO] : make: kkkk
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:40:16+0000
- [INFO] : id: 56e0faa053586409123c73b0
- [INFO] : make: eerr
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:40:00+0000
- [INFO] : id: 56e0fa8dd1f2370908bd4f04
- [INFO] : make: yoyota
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:39:41+0000
- [INFO] : id: 56e0fa7a8d7af309083b983a
- [INFO] : make: weqwedqweqweqweq
- [INFO] : color: red
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:39:22+0000
- [INFO] : id: 56e0fa5fa778ca090853878e
- [INFO] : make: scqwhgfsqghws
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:38:55+0000
- [INFO] : id: 56e0fa4cd1f2370910bc6fcb
- [INFO] : make: sdadasdissan
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:38:36+0000
- [INFO] : id: 56e0fa3853586409123c736b
- [INFO] : make: wswqs
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:38:16+0000
- [INFO] : id: 56e0fa2640a96d090d931018
- [INFO] : make: abcd
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:37:58+0000
- [INFO] : id: 56e0fa148d7af309083b97d0
- [INFO] : make: pissan
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-03-10T04:37:40+0000
- [INFO] : id: 56cecbc821498909250017e0
- [INFO] : make: nissan
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-02-25T09:39:20+0000
- [INFO] : id: 56cecb86cd9aab0920001776
- [INFO] : make: nissan
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : created_at: 2016-02-25T09:38:14+0000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement