Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updated to latest version of SDK, and added session storage

  • Loading branch information...
commit 4c8f379e6931535d47e2dd74ed27518b681a511a 1 parent 7c50db9
Rod Simpson rodsimpson authored
4 index.html
@@ -9,6 +9,7 @@
9 9 <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
10 10 <script src="js/app.js" type="text/javascript"></script>
11 11 <script src="js/usergrid.appSDK.js" type="text/javascript"></script>
  12 + <script src="js/usergrid.session.js" type="text/javascript"></script>
12 13 <script type="text/javascript">
13 14 try {
14 15 // first, set the org and app path.
@@ -18,6 +19,7 @@
18 19 $('#login-section-error')
19 20 .html('There was an error initializing: ' + JSON.stringify(e));
20 21 }
  22 + Usergrid.ApiClient.getOrganizationName();
21 23 </script>
22 24 </head>
23 25 <body>
@@ -30,7 +32,7 @@
30 32 <h3>Messagee is a sample messaging app, like Twitter</h3>
31 33 <p>
32 34 <h4>Log in using your Messagee account.</h4>
33   - Don&apos;t have an account? use our test account (username: testuser / password: testuser), or create a new one!
  35 + Don&apos;t have an account? use our test account (username: myuser / password: mypass), or create a new one!
34 36 </p>
35 37 <span id="login-section-error"></span>
36 38 <form name="form-login" id="form-login">
43 js/app.js
@@ -49,11 +49,6 @@ $(document).ready(function () {
49 49 $('#btn-create-new-account').bind('click', createNewUser);
50 50 $('#btn-update-account').bind('click', updateUser);
51 51
52   - $('#btn-close').bind('click', function() {
53   - //turn the reload timer on
54   - feedReloadTimer = window.setInterval( timerRefreshView, 30000 );
55   - });
56   -
57 52 $('#btn-previous').bind('click', function() {
58 53 if (fullFeedView) {
59 54 fullActivityFeed.getPreviousPage();
@@ -76,12 +71,16 @@ $(document).ready(function () {
76 71 $('#btn-show-create-message').bind('click', function() {;
77 72 $("#content").val('');
78 73 $("#content").focus();
79   - //turn the reload timer off so we don't get interrupted during the update
80   - window.clearInterval( feedReloadTimer );
81 74 });
82 75
83 76 $('#post-message').bind('click', postMessage);
84 77
  78 + //log the user in if they already have a session
  79 + if (Usergrid.ApiClient.isLoggedInAppUser()) {
  80 + appUser = Usergrid.ApiClient.getLoggedInUser();
  81 + showFullFeed();
  82 + }
  83 +
85 84 /**
86 85 * function to log in the app user. The API returns a token,
87 86 * which is stored in Usergrid.ApiClient and used for all future
@@ -139,9 +138,6 @@ $(document).ready(function () {
139 138 * @return none
140 139 */
141 140 function pageUpdateAccount(){
142   - //turn the reload timer off so we don't get interrupted during the update
143   - window.clearInterval( feedReloadTimer );
144   -
145 141 $("#update-name").val(appUser.get('name'));
146 142 $("#update-email").val(appUser.get('email'));
147 143 $("#update-username").val(appUser.get('username'));
@@ -227,7 +223,7 @@ $(document).ready(function () {
227 223 var username = $("#update-username").val();
228 224 var oldpassword = '';
229 225 var newpassword = '';
230   - if (username != "testuser") {
  226 + if (username != "myuser") {
231 227 var oldpassword = $("#update-oldpassword").val();
232 228 var newpassword = $("#update-newpassword").val();
233 229 }
@@ -509,7 +505,6 @@ $(document).ready(function () {
509 505 message.set(actor);
510 506 message.save(
511 507 function () {
512   - feedReloadTimer = window.setInterval( timerRefreshView, 30000 );
513 508 if (fullFeedView) {
514 509 //reset the feed object so when we view it again, we will get the latest feed
515 510 fullActivityFeed.clearQuery();
@@ -561,30 +556,6 @@ $(document).ready(function () {
561 556 //MD5 function - used for parsing emails for Gravatar images
562 557 var MD5=function(s){function L(k,d){return(k<<d)|(k>>>(32-d))}function K(G,k){var I,d,F,H,x;F=(G&2147483648);H=(k&2147483648);I=(G&1073741824);d=(k&1073741824);x=(G&1073741823)+(k&1073741823);if(I&d){return(x^2147483648^F^H)}if(I|d){if(x&1073741824){return(x^3221225472^F^H)}else{return(x^1073741824^F^H)}}else{return(x^F^H)}}function r(d,F,k){return(d&F)|((~d)&k)}function q(d,F,k){return(d&k)|(F&(~k))}function p(d,F,k){return(d^F^k)}function n(d,F,k){return(F^(d|(~k)))}function u(G,F,aa,Z,k,H,I){G=K(G,K(K(r(F,aa,Z),k),I));return K(L(G,H),F)}function f(G,F,aa,Z,k,H,I){G=K(G,K(K(q(F,aa,Z),k),I));return K(L(G,H),F)}function D(G,F,aa,Z,k,H,I){G=K(G,K(K(p(F,aa,Z),k),I));return K(L(G,H),F)}function t(G,F,aa,Z,k,H,I){G=K(G,K(K(n(F,aa,Z),k),I));return K(L(G,H),F)}function e(G){var Z;var F=G.length;var x=F+8;var k=(x-(x%64))/64;var I=(k+1)*16;var aa=Array(I-1);var d=0;var H=0;while(H<F){Z=(H-(H%4))/4;d=(H%4)*8;aa[Z]=(aa[Z]|(G.charCodeAt(H)<<d));H++}Z=(H-(H%4))/4;d=(H%4)*8;aa[Z]=aa[Z]|(128<<d);aa[I-2]=F<<3;aa[I-1]=F>>>29;return aa}function B(x){var k="",F="",G,d;for(d=0;d<=3;d++){G=(x>>>(d*8))&255;F="0"+G.toString(16);k=k+F.substr(F.length-2,2)}return k}function J(k){k=k.replace(/rn/g,"n");var d="";for(var F=0;F<k.length;F++){var x=k.charCodeAt(F);if(x<128){d+=String.fromCharCode(x)}else{if((x>127)&&(x<2048)){d+=String.fromCharCode((x>>6)|192);d+=String.fromCharCode((x&63)|128)}else{d+=String.fromCharCode((x>>12)|224);d+=String.fromCharCode(((x>>6)&63)|128);d+=String.fromCharCode((x&63)|128)}}}return d}var C=Array();var P,h,E,v,g,Y,X,W,V;var S=7,Q=12,N=17,M=22;var A=5,z=9,y=14,w=20;var o=4,m=11,l=16,j=23;var U=6,T=10,R=15,O=21;s=J(s);C=e(s);Y=1732584193;X=4023233417;W=2562383102;V=271733878;for(P=0;P<C.length;P+=16){h=Y;E=X;v=W;g=V;Y=u(Y,X,W,V,C[P+0],S,3614090360);V=u(V,Y,X,W,C[P+1],Q,3905402710);W=u(W,V,Y,X,C[P+2],N,606105819);X=u(X,W,V,Y,C[P+3],M,3250441966);Y=u(Y,X,W,V,C[P+4],S,4118548399);V=u(V,Y,X,W,C[P+5],Q,1200080426);W=u(W,V,Y,X,C[P+6],N,2821735955);X=u(X,W,V,Y,C[P+7],M,4249261313);Y=u(Y,X,W,V,C[P+8],S,1770035416);V=u(V,Y,X,W,C[P+9],Q,2336552879);W=u(W,V,Y,X,C[P+10],N,4294925233);X=u(X,W,V,Y,C[P+11],M,2304563134);Y=u(Y,X,W,V,C[P+12],S,1804603682);V=u(V,Y,X,W,C[P+13],Q,4254626195);W=u(W,V,Y,X,C[P+14],N,2792965006);X=u(X,W,V,Y,C[P+15],M,1236535329);Y=f(Y,X,W,V,C[P+1],A,4129170786);V=f(V,Y,X,W,C[P+6],z,3225465664);W=f(W,V,Y,X,C[P+11],y,643717713);X=f(X,W,V,Y,C[P+0],w,3921069994);Y=f(Y,X,W,V,C[P+5],A,3593408605);V=f(V,Y,X,W,C[P+10],z,38016083);W=f(W,V,Y,X,C[P+15],y,3634488961);X=f(X,W,V,Y,C[P+4],w,3889429448);Y=f(Y,X,W,V,C[P+9],A,568446438);V=f(V,Y,X,W,C[P+14],z,3275163606);W=f(W,V,Y,X,C[P+3],y,4107603335);X=f(X,W,V,Y,C[P+8],w,1163531501);Y=f(Y,X,W,V,C[P+13],A,2850285829);V=f(V,Y,X,W,C[P+2],z,4243563512);W=f(W,V,Y,X,C[P+7],y,1735328473);X=f(X,W,V,Y,C[P+12],w,2368359562);Y=D(Y,X,W,V,C[P+5],o,4294588738);V=D(V,Y,X,W,C[P+8],m,2272392833);W=D(W,V,Y,X,C[P+11],l,1839030562);X=D(X,W,V,Y,C[P+14],j,4259657740);Y=D(Y,X,W,V,C[P+1],o,2763975236);V=D(V,Y,X,W,C[P+4],m,1272893353);W=D(W,V,Y,X,C[P+7],l,4139469664);X=D(X,W,V,Y,C[P+10],j,3200236656);Y=D(Y,X,W,V,C[P+13],o,681279174);V=D(V,Y,X,W,C[P+0],m,3936430074);W=D(W,V,Y,X,C[P+3],l,3572445317);X=D(X,W,V,Y,C[P+6],j,76029189);Y=D(Y,X,W,V,C[P+9],o,3654602809);V=D(V,Y,X,W,C[P+12],m,3873151461);W=D(W,V,Y,X,C[P+15],l,530742520);X=D(X,W,V,Y,C[P+2],j,3299628645);Y=t(Y,X,W,V,C[P+0],U,4096336452);V=t(V,Y,X,W,C[P+7],T,1126891415);W=t(W,V,Y,X,C[P+14],R,2878612391);X=t(X,W,V,Y,C[P+5],O,4237533241);Y=t(Y,X,W,V,C[P+12],U,1700485571);V=t(V,Y,X,W,C[P+3],T,2399980690);W=t(W,V,Y,X,C[P+10],R,4293915773);X=t(X,W,V,Y,C[P+1],O,2240044497);Y=t(Y,X,W,V,C[P+8],U,1873313359);V=t(V,Y,X,W,C[P+15],T,4264355552);W=t(W,V,Y,X,C[P+6],R,2734768916);X=t(X,W,V,Y,C[P+13],O,1309151649);Y=t(Y,X,W,V,C[P+4],U,4149444226);V=t(V,Y,X,W,C[P+11],T,3174756917);W=t(W,V,Y,X,C[P+2],R,718787259);X=t(X,W,V,Y,C[P+9],O,3951481745);Y=K(Y,h);X=K(X,E);W=K(W,v);V=K(V,g)}var i=B(Y)+B(X)+B(W)+B(V);return i.toLowerCase()};
563 558
564   - /**
565   - * A simple method to cause the feed to refresh every 30 seconds
566   - * if you were to want to stop it, use this:
567   - * window.clearInterval( feedReloadTimer );
568   - *
569   - * @method feedReloadTimer
570   - * @return none
571   - */
572   - var feedReloadTimer = window.setInterval( timerRefreshView, 30000 );
573   -
574   - function timerRefreshView(){
575   - /* if (Usergrid.ApiClient.isLoggedInAppUser()) {
576   - if (fullFeedView) {
577   - showFullFeed();
578   - } else {
579   - showMyFeed();
580   - }
581   - } else {
582   - window.location = "#page-login";
583   - return;
584   - } */
585   - return;
586   - }
587   -
588 559 });
589 560
590 561 //abudda abudda abudda that's all folks!
51 js/usergrid.appSDK.js
@@ -25,7 +25,7 @@ window.console.log = window.console.log || function() {};
25 25 //Usergrid namespace encapsulates this SDK
26 26 window.Usergrid = window.Usergrid || {};
27 27 Usergrid = Usergrid || {};
28   -Usergrid.SDK_VERSION = '0.9.6';
  28 +Usergrid.SDK_VERSION = '0.9.7';
29 29
30 30 /**
31 31 * Usergrid.Query is a class for holding all query information and paging state
@@ -1160,8 +1160,8 @@ Usergrid.ApiClient = (function () {
1160 1160 *
1161 1161 */
1162 1162 function init(orgName, appName){
1163   - _orgName = orgName;
1164   - _appName = appName;
  1163 + this.setOrganizationName(orgName);
  1164 + this.setApplicationName(appName);
1165 1165 }
1166 1166
1167 1167 /*
@@ -1215,29 +1215,6 @@ Usergrid.ApiClient = (function () {
1215 1215 }
1216 1216
1217 1217 /*
1218   - * A public method to get the organization UUID to be used by the client
1219   - *
1220   - * @method getOrganizationUUID
1221   - * @public
1222   - * @return {string} the organization UUID
1223   - */
1224   - function getOrganizationUUID() {
1225   - return _orgUUID;
1226   - }
1227   -
1228   - /*
1229   - * A public method to set the organization UUID to be used by the client
1230   - *
1231   - * @method setOrganizationUUID
1232   - * @public
1233   - * @param orgUUID - the organization UUID
1234   - * @return none
1235   - */
1236   - function setOrganizationUUID(orgUUID) {
1237   - _orgUUID = orgUUID;
1238   - }
1239   -
1240   - /*
1241 1218 * A public method to get the application name to be used by the client
1242 1219 *
1243 1220 * @method getApplicationName
@@ -1393,7 +1370,7 @@ Usergrid.ApiClient = (function () {
1393 1370 * @return none
1394 1371 */
1395 1372 function logoutAppUser() {
1396   - this._loggedInUser = null;
  1373 + this.setLoggedInUser(null);
1397 1374 this.setToken(null);
1398 1375 }
1399 1376
@@ -1631,6 +1608,8 @@ Usergrid.ApiClient = (function () {
1631 1608 //store the curl command back in the object
1632 1609 Query.setCurl(curl);
1633 1610
  1611 + var ie = (navigator.appName == 'Microsoft Internet Explorer') ? true:false;
  1612 +
1634 1613 //so far so good, so run the query
1635 1614 var xD = window.XDomainRequest ? true : false;
1636 1615 var xM = window.XMLHttpRequest ? true : false;
@@ -1646,9 +1625,13 @@ Usergrid.ApiClient = (function () {
1646 1625 path = '?access_token='+Usergrid.ApiClient.getToken();
1647 1626 }
1648 1627 }
  1628 + if (ie) {
  1629 +
  1630 +
  1631 + }
1649 1632 xhr.open(method, path, true);
1650 1633 }
1651   - else if (xM)
  1634 + else
1652 1635 {
1653 1636 xhr = new XMLHttpRequest();
1654 1637 xhr.open(method, path, true);
@@ -1656,16 +1639,6 @@ Usergrid.ApiClient = (function () {
1656 1639 xhr.setRequestHeader("Authorization", "Bearer " + Usergrid.ApiClient.getToken());
1657 1640 xhr.withCredentials = true;
1658 1641 }
1659   - } else {
1660   - xhr = new ActiveXObject("MSXML2.XMLHTTP.3.0");
1661   - if (Usergrid.ApiClient.getToken()) {
1662   - if (path.indexOf("?")) {
1663   - path += '&access_token='+Usergrid.ApiClient.getToken();
1664   - } else {
1665   - path = '?access_token='+Usergrid.ApiClient.getToken();
1666   - }
1667   - }
1668   - xhr.open(method, path, true);
1669 1642 }
1670 1643
1671 1644 //add content type = json if there is a json payload
@@ -1741,8 +1714,6 @@ Usergrid.ApiClient = (function () {
1741 1714 runManagementQuery:runManagementQuery,
1742 1715 getOrganizationName:getOrganizationName,
1743 1716 setOrganizationName:setOrganizationName,
1744   - getOrganizationUUID:getOrganizationUUID,
1745   - setOrganizationUUID:setOrganizationUUID,
1746 1717 getApplicationName:getApplicationName,
1747 1718 setApplicationName:setApplicationName,
1748 1719 getToken:getToken,
95 js/usergrid.session.js
... ... @@ -0,0 +1,95 @@
  1 +/**
  2 + * App SDK is a collection of classes designed to make working with
  3 + * the Appigee App Services API as easy as possible.
  4 + * Learn more at http://apigee.com/docs
  5 + *
  6 + * Copyright 2012 Apigee Corporation
  7 + *
  8 + * Licensed under the Apache License, Version 2.0 (the "License");
  9 + * you may not use this file except in compliance with the License.
  10 + * You may obtain a copy of the License at
  11 + *
  12 + * http://www.apache.org/licenses/LICENSE-2.0
  13 + *
  14 + * Unless required by applicable law or agreed to in writing, software
  15 + * distributed under the License is distributed on an "AS IS" BASIS,
  16 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17 + * See the License for the specific language governing permissions and
  18 + * limitations under the License.
  19 + */
  20 +
  21 +window.Usergrid = window.Usergrid || {};
  22 +Usergrid = Usergrid || {};
  23 +(function() {
  24 +
  25 + if (!Storage.prototype.setObject) {
  26 + Storage.prototype.setObject = function(key, value) {
  27 + this.setItem(key, JSON.stringify(value));
  28 + };
  29 + }
  30 + if (!Storage.prototype.getObject) {
  31 + Storage.prototype.getObject = function(key) {
  32 + try {
  33 + return this.getItem(key) && JSON.parse(this.getItem(key));
  34 + } catch(err) {
  35 + }
  36 + return null;
  37 + };
  38 + }
  39 + /**
  40 + * Standardized methods for maintaining user and authentication state in the Application
  41 + * @class UserSession
  42 + * @author Rod Simpson (rod@apigee.com)
  43 + */
  44 + Usergrid.ApiClient.getOrganizationName = function() {
  45 + return localStorage.getItem('organizationName');
  46 + }
  47 + Usergrid.ApiClient.setOrganizationName = function(organizationName) {
  48 + localStorage.setItem('organizationName', organizationName);
  49 + }
  50 +
  51 + Usergrid.ApiClient.getApplicationName = function() {
  52 + return localStorage.getItem('applicationName');
  53 + }
  54 + Usergrid.ApiClient.setApplicationName = function(applicationName) {
  55 + localStorage.setItem('applicationName', applicationName);
  56 + }
  57 +
  58 + Usergrid.ApiClient.getToken = function() {
  59 + return localStorage.getItem('token');
  60 + }
  61 + Usergrid.ApiClient.setToken = function(token) {
  62 + localStorage.setItem('token', token);
  63 + }
  64 +
  65 + Usergrid.ApiClient.getLoggedInUser = function() {
  66 + var data = JSON.parse(localStorage.getItem('user'));
  67 + var user = new Usergrid.Entity('user');
  68 + user.set(data);
  69 + return user;
  70 + }
  71 + Usergrid.ApiClient.setLoggedInUser = function(user) {
  72 + var data = null;
  73 + if (user) {
  74 + //get all the data from the object
  75 + data = user.get();
  76 + }
  77 + //and store it
  78 + localStorage.setItem('user', JSON.stringify(data));
  79 + }
  80 + Usergrid.ApiClient.getLoggedInUser2 = function() {
  81 + return localStorage.getObject('user');
  82 + }
  83 + Usergrid.ApiClient.setLoggedInUser2 = function(user) {
  84 + localStorage.setObject('user', user);
  85 + }
  86 +
  87 +
  88 +
  89 + Usergrid.ApiClient.clearAll= function () {
  90 + localStorage.removeItem('userUUID');
  91 + localStorage.removeItem('userEmail');
  92 + localStorage.removeItem('accessToken');
  93 + }
  94 +
  95 +})(Usergrid);

0 comments on commit 4c8f379

Please sign in to comment.
Something went wrong with that request. Please try again.