Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************** LOGIN MODAL [START] ********************/
- var modal = '',
- util = '',
- loginCookieName = 'loginAttempCookie',
- loginCookieValue = 'loginEventTriggered',
- loginCookieExpiry = 1;
- var LoginModal = function () {
- this.showModal = function () {
- $('.overlay').removeClass('hide');
- };
- this.hideModal = function () {
- $('.overlay').addClass('hide');
- };
- this.showError = function (errorField, errorMsg) {
- if (errorField === 'username') {
- $('#username').addClass('error-border');
- $('#err-username').html(errorMsg).removeClass('hide');
- }
- if (errorField === 'password') {
- $('#password').addClass('error-border');
- $('#err-password').html(errorMsg).removeClass('hide');
- }
- };
- this.hideError = function (errorField) {
- if (errorField === 'username') {
- $('#username').removeClass('error-border');
- $('#err-username').addClass('hide');
- }
- if (errorField === 'password') {
- $('#password').removeClass('error-border');
- $('#err-password').addClass('hide');
- }
- return this;
- };
- this.resetForm = function () {
- //clear
- $('#username').val('');
- $('#password').val('');
- $('#input-forgot-pwd').val('');
- //input border
- $('#username').removeClass('error-border');
- $('#password').removeClass('error-border');
- $('#input-forgot-pwd').removeClass('error-border');
- //input errors
- $('#err-username').addClass('hide');
- $('#err-password').addClass('hide');
- //msg
- $('#error-msg-login').addClass('hide');
- $('#error-msg-forgot-pwd').addClass('hide');
- return this;
- };
- this.handleErrorMessage = function () {
- var code = util.fetchCookie('SsoCode', '0'),
- codeMsg = util.fetchCookie('SsoMsg', ''),
- tmpLoginCookie = util.fetchCookie(loginCookieName);
- code = parseInt(code);
- if (code === 0 || code === 1) {
- }
- else {
- if (codeMsg !== '' && tmpLoginCookie === loginCookieValue) {
- codeMsg = codeMsg.replace(/["']/g, '').trim();
- $('#error-msg-login').html(codeMsg).removeClass('hide');
- $('.overlay').removeClass('hide'); //show login modal
- }
- }
- util.setCookie(loginCookieName, '', -1);
- return this;
- };
- this.setDownloadBtn = function () {
- var platformDet = navigator.platform.toUpperCase(),
- agentName = navigator.userAgent.toUpperCase(),
- elem = $('#login-modal-download');
- if (agentName.indexOf("IPHONE") != -1 || agentName.indexOf("IPAD") != -1) {
- elem.attr('href', 'https://itunes.apple.com/us/app/paltalk-video-chat-free/id466970942');
- } else if (agentName.indexOf("ANDROID") != -1) {
- elem.attr('href', 'https://play.google.com/store/apps/details?id=com.paltalk.chat.android&hl=en');
- } else if (agentName.indexOf("WIN") != -1) {
- elem.attr('href', 'http://www.paltalk.com/download/help/');
- } else if (platformDet.indexOf("MAC") != -1) {
- elem.attr('href', 'http://express.paltalk.com');
- elem.html('Launch Paltalk');
- }
- };
- };
- var Util = function () {
- this.fetchCookie = function (name, defaultVal) {
- cookie_name = name + "=";
- cookie_length = document.cookie.length;
- cookie_begin = 0;
- while (cookie_begin < cookie_length) {
- value_begin = cookie_begin + cookie_name.length;
- if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) {
- var value_end = document.cookie.indexOf(";", value_begin);
- if (value_end == -1) {
- value_end = cookie_length;
- }
- return unescape(document.cookie.substring(value_begin, value_end));
- }
- cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
- if (cookie_begin == 0) {
- break;
- }
- }
- return defaultVal;
- };
- this.setCookie = function (name, value, days) {
- var today = new Date(),
- expire = new Date();
- expire.setTime(today.getTime() + 3600000 * 24 * days);
- if (name !== '' && value !== '') {
- document.cookie = name + "=" + escape(value) + ";expires=" + expire.toGMTString();
- }
- };
- this.validEmail = function (email) {
- var emailRegx = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
- if (emailRegx.test(email)) {
- return true;
- }
- return false;
- };
- this.validLoginInfo = function (username, password) {
- var valid = true;
- username = (username !== undefined) ? $.trim(username) : '';
- password = (password !== undefined) ? $.trim(password) : '';
- /********** validation [START] **********************/
- if (username.length === 0 || password.length === 0) {
- if (username.length === 0) {
- modal.showError('username', 'Nickname should not be blank');
- valid = false;
- }
- if (password.length === 0) {
- modal.showError('password', 'Password should not be blank');
- valid = false;
- }
- }
- if (username !== '' && username.length > 0) {
- if (username.indexOf("[") >= 0 || username.indexOf("]") >= 0) {
- modal.showError('username', 'Invalid char in Nickname is not allowed');
- valid = false;
- }
- }
- /********** validation [END] **********************/
- return valid;
- };
- };
- var RegisterLoginModalEvents = function () {
- $('.overlay').find('i.close').click(function () {
- modal.hideModal();
- });
- $('#header-sign-in').click(function () {
- modal.resetForm().showModal();
- });
- $('#login-btn').click(function () {
- var username = $('#username').val(),
- password = $('#password').val(),
- valid = false;
- valid = util.validLoginInfo(username, password);
- if (valid) {
- util.setCookie(loginCookieName, loginCookieValue, loginCookieExpiry);
- $('#LoginForm').submit();
- }
- });
- $('#username, #password').focusin(function () {
- modal.hideError('username');
- modal.hideError('password');
- });
- $('#username, #password').keyup(function (e) {
- if (e.keyCode === 13) {
- $('#login-btn').trigger('click');
- }
- });
- modal.handleErrorMessage().setDownloadBtn();
- };
- /************************** LOGIN MODAL [END] ********************/
- (function () {
- modal = new LoginModal();
- util = new Util();
- RegisterLoginModalEvents();
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement