Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.04 KB | None | 0 0
  1. /************************** LOGIN MODAL [START] ********************/
  2. var modal = '',
  3. util = '',
  4. loginCookieName = 'loginAttempCookie',
  5. loginCookieValue = 'loginEventTriggered',
  6. loginCookieExpiry = 1;
  7.  
  8. var LoginModal = function () {
  9. this.showModal = function () {
  10. $('.overlay').removeClass('hide');
  11. };
  12.  
  13. this.hideModal = function () {
  14. $('.overlay').addClass('hide');
  15. };
  16.  
  17. this.showError = function (errorField, errorMsg) {
  18. if (errorField === 'username') {
  19. $('#username').addClass('error-border');
  20. $('#err-username').html(errorMsg).removeClass('hide');
  21. }
  22.  
  23. if (errorField === 'password') {
  24. $('#password').addClass('error-border');
  25. $('#err-password').html(errorMsg).removeClass('hide');
  26. }
  27.  
  28. };
  29.  
  30. this.hideError = function (errorField) {
  31. if (errorField === 'username') {
  32. $('#username').removeClass('error-border');
  33. $('#err-username').addClass('hide');
  34. }
  35.  
  36. if (errorField === 'password') {
  37. $('#password').removeClass('error-border');
  38. $('#err-password').addClass('hide');
  39. }
  40.  
  41. return this;
  42.  
  43. };
  44.  
  45. this.resetForm = function () {
  46. //clear
  47. $('#username').val('');
  48. $('#password').val('');
  49. $('#input-forgot-pwd').val('');
  50. //input border
  51. $('#username').removeClass('error-border');
  52. $('#password').removeClass('error-border');
  53. $('#input-forgot-pwd').removeClass('error-border');
  54. //input errors
  55. $('#err-username').addClass('hide');
  56. $('#err-password').addClass('hide');
  57. //msg
  58. $('#error-msg-login').addClass('hide');
  59. $('#error-msg-forgot-pwd').addClass('hide');
  60. return this;
  61.  
  62. };
  63.  
  64. this.handleErrorMessage = function () {
  65. var code = util.fetchCookie('SsoCode', '0'),
  66. codeMsg = util.fetchCookie('SsoMsg', ''),
  67. tmpLoginCookie = util.fetchCookie(loginCookieName);
  68.  
  69. code = parseInt(code);
  70.  
  71. if (code === 0 || code === 1) {
  72. }
  73. else {
  74. if (codeMsg !== '' && tmpLoginCookie === loginCookieValue) {
  75. codeMsg = codeMsg.replace(/["']/g, '').trim();
  76. $('#error-msg-login').html(codeMsg).removeClass('hide');
  77. $('.overlay').removeClass('hide'); //show login modal
  78. }
  79. }
  80. util.setCookie(loginCookieName, '', -1);
  81. return this;
  82.  
  83. };
  84.  
  85. this.setDownloadBtn = function () {
  86. var platformDet = navigator.platform.toUpperCase(),
  87. agentName = navigator.userAgent.toUpperCase(),
  88. elem = $('#login-modal-download');
  89.  
  90. if (agentName.indexOf("IPHONE") != -1 || agentName.indexOf("IPAD") != -1) {
  91. elem.attr('href', 'https://itunes.apple.com/us/app/paltalk-video-chat-free/id466970942');
  92. } else if (agentName.indexOf("ANDROID") != -1) {
  93. elem.attr('href', 'https://play.google.com/store/apps/details?id=com.paltalk.chat.android&hl=en');
  94. } else if (agentName.indexOf("WIN") != -1) {
  95. elem.attr('href', 'http://www.paltalk.com/download/help/');
  96. } else if (platformDet.indexOf("MAC") != -1) {
  97. elem.attr('href', 'http://express.paltalk.com');
  98. elem.html('Launch Paltalk');
  99. }
  100. };
  101. };
  102.  
  103. var Util = function () {
  104. this.fetchCookie = function (name, defaultVal) {
  105. cookie_name = name + "=";
  106. cookie_length = document.cookie.length;
  107. cookie_begin = 0;
  108. while (cookie_begin < cookie_length) {
  109. value_begin = cookie_begin + cookie_name.length;
  110. if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) {
  111. var value_end = document.cookie.indexOf(";", value_begin);
  112. if (value_end == -1) {
  113. value_end = cookie_length;
  114. }
  115. return unescape(document.cookie.substring(value_begin, value_end));
  116. }
  117. cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
  118. if (cookie_begin == 0) {
  119. break;
  120. }
  121. }
  122. return defaultVal;
  123.  
  124. };
  125.  
  126. this.setCookie = function (name, value, days) {
  127. var today = new Date(),
  128. expire = new Date();
  129.  
  130. expire.setTime(today.getTime() + 3600000 * 24 * days);
  131.  
  132. if (name !== '' && value !== '') {
  133. document.cookie = name + "=" + escape(value) + ";expires=" + expire.toGMTString();
  134. }
  135. };
  136.  
  137. this.validEmail = function (email) {
  138. var emailRegx = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  139. if (emailRegx.test(email)) {
  140. return true;
  141. }
  142. return false;
  143.  
  144. };
  145.  
  146. this.validLoginInfo = function (username, password) {
  147. var valid = true;
  148.  
  149. username = (username !== undefined) ? $.trim(username) : '';
  150. password = (password !== undefined) ? $.trim(password) : '';
  151.  
  152. /********** validation [START] **********************/
  153. if (username.length === 0 || password.length === 0) {
  154. if (username.length === 0) {
  155. modal.showError('username', 'Nickname should not be blank');
  156. valid = false;
  157. }
  158.  
  159. if (password.length === 0) {
  160. modal.showError('password', 'Password should not be blank');
  161. valid = false;
  162. }
  163. }
  164.  
  165. if (username !== '' && username.length > 0) {
  166. if (username.indexOf("[") >= 0 || username.indexOf("]") >= 0) {
  167. modal.showError('username', 'Invalid char in Nickname is not allowed');
  168. valid = false;
  169. }
  170. }
  171. /********** validation [END] **********************/
  172. return valid;
  173.  
  174. };
  175.  
  176. };
  177. var RegisterLoginModalEvents = function () {
  178.  
  179. $('.overlay').find('i.close').click(function () {
  180. modal.hideModal();
  181. });
  182.  
  183. $('#header-sign-in').click(function () {
  184. modal.resetForm().showModal();
  185. });
  186.  
  187. $('#login-btn').click(function () {
  188. var username = $('#username').val(),
  189. password = $('#password').val(),
  190. valid = false;
  191.  
  192. valid = util.validLoginInfo(username, password);
  193. if (valid) {
  194. util.setCookie(loginCookieName, loginCookieValue, loginCookieExpiry);
  195. $('#LoginForm').submit();
  196. }
  197. });
  198.  
  199. $('#username, #password').focusin(function () {
  200. modal.hideError('username');
  201. modal.hideError('password');
  202. });
  203.  
  204. $('#username, #password').keyup(function (e) {
  205. if (e.keyCode === 13) {
  206. $('#login-btn').trigger('click');
  207. }
  208. });
  209. modal.handleErrorMessage().setDownloadBtn();
  210. };
  211. /************************** LOGIN MODAL [END] ********************/
  212.  
  213. (function () {
  214. modal = new LoginModal();
  215. util = new Util();
  216. RegisterLoginModalEvents();
  217. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement