/android/client-frwk/Examples/MasterGUI/assets/www/javascript/pagespecific/login.js

https://github.com/societies/SOCIETIES-Platform · JavaScript · 195 lines · 100 code · 38 blank · 57 comment · 5 complexity · 2413a15f6ce541376d4a0d198f60c736 MD5 · raw file

  1. /**
  2. * Societies Android app login function(s) namespace
  3. *
  4. * @namespace SocietiesLogin
  5. */
  6. var SocietiesLogin = {
  7. /**
  8. * @methodOf SocietiesLogin#
  9. * @description Validate that viable login credentials have been entered
  10. * @param {Object} username
  11. * @param {Object} password
  12. * @param {Object} domain
  13. * @param {Object} cloudNodeName
  14. * @returns boolean true if credentials viable
  15. */
  16. validateLoginCredentials: function(name, password, cloudNodeName, domain) {
  17. var retValue = true;
  18. console.log("validateLoginCredentials user: " + name);
  19. console.log("validateLoginCredentials pass: " + password);
  20. console.log("validateLoginCredentials cloud node: " + cloudNodeName);
  21. console.log("validateLoginCredentials domain: " + domain);
  22. if (name.length === 0 || password.length === 0 || domain.length === 0 || cloudNodeName.length === 0) {
  23. retValue = false;
  24. alert("validateLoginCredentials: " + "User credentials and CSS related information must be entered");
  25. }
  26. return retValue;
  27. },
  28. /**
  29. * @methodOf SocietiesLogin#
  30. * @description Actions carried in the event that a successful XMPP Domain login occurs. A successful login
  31. * to the XMPP server will then try to login into the defined Cloud server
  32. * @returns null
  33. */
  34. successfulXMPPDomainLogin: function() {
  35. console.log("Login to the chosen XMPP domain");
  36. function success(data) {
  37. SocietiesLocalCSSManagerHelper.connectToLocalCSSManager(SocietiesLogin.successfulCSSCloudLogin);
  38. }
  39. function failure(data) {
  40. alert("successfulXMPPDomainLogin - failure: " + data);
  41. }
  42. window.plugins.SocietiesLocalCSSManager.loginXMPPServer(success, failure);
  43. },
  44. /**
  45. * @methodOf SocietiesLogin#
  46. * @description Displays the CSS credentials
  47. * @returns null
  48. */
  49. displayConnectionInfo: function() {
  50. console.log("displayConnectionInfo");
  51. console.log("Number of plugins" + window.plugins.length);
  52. for (i = 0; i < window.plugins.length; i++) {
  53. console.log("plugin: " + window.plugin[i])
  54. };
  55. SocietiesLogin.getCSSIdentity();
  56. SocietiesLogin.getCSSIdentityPassword();
  57. SocietiesLogin.getCSSIdentityDomain();
  58. SocietiesLogin.getCSSCloudNode();
  59. },
  60. /**
  61. * @methodOf SocietiesLogin#
  62. * @description Gets the CSS Identity app preference value
  63. * @returns null
  64. */
  65. getCSSIdentity: function () {
  66. function success(data) {
  67. console.log("getCSSIdentity - successful: " + data.value);
  68. jQuery("#username").val(data.value);
  69. }
  70. function failure(data) {
  71. alert("getCSSIdentity - failure: " + data);
  72. }
  73. window.plugins.SocietiesAppPreferences.getStringPrefValue(success, failure, "cssIdentity");
  74. },
  75. /**
  76. * @methodOf SocietiesLogin#
  77. * @description Gets the CSS Identity Password app preference value
  78. * @returns null
  79. */
  80. getCSSIdentityPassword: function () {
  81. function success(data) {
  82. console.log("getCSSIdentityPassword - successful: " + data.value);
  83. jQuery("#userpass").val(data.value);
  84. }
  85. function failure(data) {
  86. alert("getCSSIdentityPassword - failure: " + data);
  87. }
  88. window.plugins.SocietiesAppPreferences.getStringPrefValue(success, failure, "cssPassword");
  89. },
  90. /**
  91. * @methodOf SocietiesLogin#
  92. * @description Gets the CSS Identity Password app preference value
  93. * @returns null
  94. */
  95. getCSSIdentityDomain: function () {
  96. function success(data) {
  97. console.log("getCSSIdentityDomain - successful: " + data.value);
  98. jQuery("#identitydomain").val(data.value);
  99. }
  100. function failure(data) {
  101. alert("getCSSIdentityDomain - failure: " + data);
  102. }
  103. window.plugins.SocietiesAppPreferences.getStringPrefValue(success, failure, "daURI");
  104. },
  105. /**
  106. * @methodOf SocietiesLogin#
  107. * @description Gets the CSS Cloud Node preference value. This value is the name
  108. * of the Cloud node and is required as a destination point for XMPP traffic to the
  109. * cloud.
  110. * @returns null
  111. */
  112. getCSSCloudNode: function () {
  113. function success(data) {
  114. console.log("getCSSCloudNode - successful: " + data.value);
  115. jQuery("#cloudnode").val(data.value);
  116. }
  117. function failure(data) {
  118. alert("getCSSCloudNode - failure: " + data);
  119. }
  120. window.plugins.SocietiesAppPreferences.getStringPrefValue(success, failure, "cloudNode");
  121. },
  122. /**
  123. * @methodOf SocietiesLogin#
  124. * @description updates the login user credentials and associated information for future login purposes
  125. * @returns null
  126. */
  127. updateLoginCredentialPreferences: function () {
  128. function success(data) {
  129. console.log("updateLoginCredentialPreferences - successful: " + data.value);
  130. }
  131. function failure(data) {
  132. alert("updateLoginCredentialPreferences - failure: " + data);
  133. }
  134. window.plugins.SocietiesAppPreferences.putStringPrefValue(success, failure, "cssIdentity", jQuery("#username").val());
  135. window.plugins.SocietiesAppPreferences.putStringPrefValue(success, failure, "cssPassword", jQuery("#userpass").val());
  136. window.plugins.SocietiesAppPreferences.putStringPrefValue(success, failure, "daURI", jQuery("#identitydomain").val());
  137. window.plugins.SocietiesAppPreferences.putStringPrefValue(success, failure, "cloudNode", jQuery("#cloudnode").val());
  138. },
  139. /**
  140. * @methodOf SocietiesLogin#
  141. * @description Actions carried in the event that a successful CSS Cloud login occurs
  142. * @returns null
  143. */
  144. successfulCSSCloudLogin: function() {
  145. console.log("Login to CSS Cloud node");
  146. function success(data) {
  147. SocietiesCSSRecord.populateCSSRecordpage(data);
  148. SocietiesLogin.updateLoginCredentialPreferences();
  149. console.log("Current page: " + $.mobile.activePage[0].id);
  150. $.mobile.changePage( ($("#menu")), { transition: "slideup"} );
  151. }
  152. function failure(data) {
  153. alert("successfulCSSCloudLogin - failure: " + data);
  154. }
  155. window.plugins.SocietiesLocalCSSManager.loginCSS(success, failure);
  156. }
  157. }