var rpcLink = '/rpc;jsessionid=c1li5f1eek6g1'; /*------------------------------------------------- CONSTANTS -------------------------------------------------*/ /* * Browser request timeout (in ms). */ var BROWSER_TIMEOUT = 120000; /*------------------------------------------------- FUNCTIONS -------------------------------------------------*/ /*------------------------------------------------- PUBLIC -------------------------------------------------*/ function BaseLoginPageState ( config ) { if( config ) { this.buttonId = config.buttonId; this.progressTextId = config.progressTextId; this.inputElementNames = config.inputElementNames; this.focusElementName = config.focusElementName; this.formId = config.formId; this.formContainerId = config.formContainerId; this.changeStateLinkId = config.changeStateLinkId; this.controller = null; this.changeStateLinkContainerId = config.changeStateLinkContainerId; } // Protected this.timerId = null; this.toSubmit = true; } BaseLoginPageState.prototype.setController = function( controller ) { this.controller = controller; }; BaseLoginPageState.prototype.getDemoTooltip = function( ) { return DEMO_TOOLTIP; }; BaseLoginPageState.prototype.getNote = function( ) { return null; }; BaseLoginPageState.prototype.submitForm = function( ) { var controller = this.controller; var state = this; var form = controller.getForm(); if( controller.isInProgress() ) return; controller.toInProgressState(); this.prepareForSubmit(); this.doSubmit( form ); this.timerId = window.setTimeout( function(){ state.processError(state.getTimeoutMessage()); }, BROWSER_TIMEOUT); }; /* * Performs actions need to be done on page submition * NOTE: method need to be overridden be inheritors */ BaseLoginPageState.prototype.doSubmit = function( form ) { // Do nothing by default }; /* * Performs server remote procedure call. */ BaseLoginPageState.prototype.makeRemoteCall = function(form, serviceMethodName, processSuccessFunc, processErrorFunc, remoteCall) { var state = this; try { if (!isRpcReady( [serviceMethodName] )) { var func = function(){ state.makeRemoteCall(form, serviceMethodName, processSuccessFunc, processErrorFunc, remoteCall);}; window.setTimeout(func, 200); return; } var callback = function(result, exception) { if (!exception && state.toSubmit) processSuccessFunc.call(state, form, result); else processErrorFunc.call(state, exception); }; remoteCall( callback ); } catch (e) { processErrorFunc.call(state, e); } }; /* * Clears form's inputs * NOTE: method need to be overridden be inheritors */ BaseLoginPageState.prototype.clearInputs = function( form ) { // Do nothing by default }; /* * Returns page to initial state and shows the error message. */ BaseLoginPageState.prototype.processError = function(errorMessage) { this.clearServerRequest(); this.controller.hideServerSideMessages(); this.controller.printError( errorMessage ); ClientSideErrors.showClientSideErrorMessage(); }; BaseLoginPageState.prototype.clearServerRequest = function() { this.toSubmit = false; this.controller.toInitialState(); window.clearTimeout(this.timerId); this.timerId = null; this.stopLoad(); }; /* * Do some initializations and functions callings to prepare for form submission. */ BaseLoginPageState.prototype.prepareForSubmit = function() { this.toSubmit = true; ClientSideErrors.hideClientSideErrorMessage(); ClientSideErrors.errorMessageWasShown = false; }; /* * Stops page loading (login action). */ BaseLoginPageState.prototype.stopLoad = function() { try { window.stop(); } catch (e) { // Can be thrown in IE because of window.stop(); statement. window.document.execCommand('Stop'); } }; function LoginState( config ) { BaseLoginPageState.call( this, config ); this.showAdminManagerTooltip = config.showAdminManagerTooltip; this.showPasswordResetTooltip = config.showPasswordResetTooltip; this.isDemoMode = config.showPasswordResetTooltip; // Private this.userPassword = null; } LoginState.prototype = new BaseLoginPageState(); LoginState.prototype.getTitle = function( ) { return 'Please identify yourself'; }; LoginState.prototype.getTooltip = function( ) { var tooltip = ""; if( this.showPasswordResetTooltip ) tooltip += this.getPasswordSuccessfullyResetTooltip(); if( this.showAdminManagerTooltip ) tooltip += this.getAdminManagerTooltip(); return tooltip; }; LoginState.prototype.getAdminManagerTooltip = function( ) { return ADMIN_MANAGER_TOOLTIP; }; LoginState.prototype.getPasswordSuccessfullyResetTooltip = function( ) { this.showPasswordResetTooltip = false; return PASSWORD_SUCCESSFULLY_RESET_TOOLTIP; }; LoginState.prototype.doSubmit = function( form ) { BaseLoginPageState.prototype.doSubmit.call( this, form ); this.rememberPassword(form); this.doGetChallenge(form); }; LoginState.prototype.clearInputs = function( form ) { form.elements['pwd'].value = ""; form.elements['username'].value = ""; }; /* * Remembers typed by user password and cleans appropriate field. */ LoginState.prototype.rememberPassword = function (form) { this.userPassword = form.elements['pwd'].value; form.elements['pwd'].value = ""; }; /* * Do GET-request to get challenge anf if challenge has been got calls doLogin() function. */ LoginState.prototype.doGetChallenge = function(form) { var state = this; this.makeRemoteCall( form, 'LoginService.getChallenge', state.doLogin, state.processGetChallengeError, function( callback ){ jsonrpc.LoginService.getChallenge(callback); } ); }; LoginState.prototype.processGetChallengeError = function(exception) { this.processError( this.getErrorMessage() ); }; /* * Gets message informing about login failure. */ LoginState.prototype.getErrorMessage = function() { return "Failed to login. Please try again later."; }; /* * Gets message informing about timeout exceeding. */ LoginState.prototype.getTimeoutMessage = function() { return "Cannot login for 2 minutes. Please try again later."; }; /* * Posts form to login. */ LoginState.prototype.doLogin = function(form, result) { form.elements['submitted'].value = 1; form.elements['password'].value = MD5(MD5(this.userPassword) + result.challengeValue + trim(form.elements['username'].value).toLowerCase()); this.rewriteJsessionidIfNeeded(form, result.sessionId); form.submit(); }; /* * Rewrites URL jsessionid parameter if URL rewriting is used to keep session. It is needed when session has expired on * the server and to login form action should contain right jsessionid parameter. */ LoginState.prototype.rewriteJsessionidIfNeeded = function(form, newSessionId) { var jsessionidPos = form.action.indexOf("jsessionid"); if (jsessionidPos >= 0) { var formAction = form.action; var currentSessionId = formAction.substring(formAction.indexOf("=", jsessionidPos) + 1); form.action = formAction.replace(currentSessionId, newSessionId); } }; function ForgetPasswordState( config ) { BaseLoginPageState.call(this, config); } ForgetPasswordState.prototype = new BaseLoginPageState(); ForgetPasswordState.prototype.doSubmit = function( form ) { BaseLoginPageState.prototype.doSubmit.call( this, form ); this.doRequestLoginInfo(form); }; ForgetPasswordState.prototype.clearInputs = function( form ) { form.elements['forgetPasswordEmailOrUsername'].value = ""; }; /* * Do request login information to be sent to the user with given username or email address. */ ForgetPasswordState.prototype.doRequestLoginInfo = function(form) { var state = this; this.makeRemoteCall( form, 'PasswordRecoveryService.sendLoginInfo', state.doProcessResponse, state.processRequestLoginInfoError, function( callback ){ var userNameOrEmail = form.elements['forgetPasswordEmailOrUsername'].value; jsonrpc.PasswordRecoveryService.sendLoginInfo(callback, userNameOrEmail); } ); }; ForgetPasswordState.prototype.doProcessResponse = function(form, response) { if( response.success ) { this.clearServerRequest(); this.controller.hideAllMessages(); this.controller.printTooltip( this.getSuccessTooltip( response.message ) ); this.controller.printNote( response.note ); this.controller.hideForm(); } else { this.processRequestLoginInfoError( null, response ); } }; ForgetPasswordState.prototype.processRequestLoginInfoError = function(exception, response) { var controller = this.controller; var state = this; var errorNote = response === undefined ? state.getErrorNote() : response.note; var errorMessage = response === undefined ? state.getErrorMessage() : response.message; this.processError( errorMessage ); window.setTimeout( function(){ controller.printNote( errorNote ); controller.printTooltip( null ); }, 200 ); }; ForgetPasswordState.prototype.getTitle = function( ) { return 'Forgot your password?'; }; ForgetPasswordState.prototype.getTooltip = function( ) { return '
' +
' To login for the first time use the following username and password: ' +
' Username: admin ' +
' Password: manager ' +
'
| ||||||
' +
' Your password was successfully reset. ' +
' Your username has been sent to your email address. ' +
' | ||||
' +
' {0} ' +
' | ||||
' +
' Welcome to actiTIME demo ' +
' To login as an administrator use the following username and password: ' +
' Username: admin ' +
' ' + ' Password: manager To login as a regular user use the following username and password: ' +
' Username: user ' +
' ' + ' Password: user | ||||