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 '
Please enter your email address or username below to get password reset instructions.
'; }; ForgetPasswordState.prototype.getErrorMessage = function() { return "Cannot recover login info.
Please make sure that everything is typed in correctly."; }; ForgetPasswordState.prototype.getTimeoutMessage = function() { return "Cannot send login info for 2 minutes. Please try again later."; }; ForgetPasswordState.prototype.getErrorNote = function() { return messageResource.getMessage("password_recovery.forgot_your_password.send_info.failed.note.without_email"); }; ForgetPasswordState.prototype.getSuccessTooltip = function( message ) { var noteTemplate = LOGIN_INFO_SUCCESSFULLY_SENT_TOOLTIP; return formatMessage( noteTemplate, [ message ], 0 ); }; function ResetPasswordState( config ) { BaseLoginPageState.call(this, config); this.tooltipText = config.tooltipText; this.newPassword = null; this.newPasswordConfirm = null; this.newPasswordText = null; this.newPasswordConfirmText = null; } ResetPasswordState.prototype = new BaseLoginPageState(); ResetPasswordState.prototype.initFieldControllers = function( ) { if( this.newPassword ) return; this.newPassword = document.getElementById( "newPassword" ); this.newPasswordConfirm = document.getElementById( "newPasswordConfirm" ); this.newPasswordText = document.getElementById( "newPwd" ); this.newPasswordConfirmText = document.getElementById( "newPwdConfirm" ); }; ResetPasswordState.prototype.doSubmit = function( form ) { BaseLoginPageState.prototype.doSubmit.call( this, form ); this.doResetPassword( form ); }; ResetPasswordState.prototype.doResetPassword = function( form ) { var state = this; var submitFunc = function(){ state.initFieldControllers(); var errorMessage = state.verifyPasswords(); if( errorMessage ){ state.processError( errorMessage ); return; } state.newPassword.value = MD5( state.newPasswordText.value ); state.newPasswordConfirm.value = MD5( state.newPasswordConfirmText.value ); state.clearInputs( form ); state.clearServerRequest(); form.submit(); }; window.setTimeout(submitFunc, 200); }; ResetPasswordState.prototype.clearInputs = function( form ) { form.elements['newPwd'].value = ""; form.elements['newPwdConfirm'].value = ""; }; ResetPasswordState.prototype.verifyPasswords = function() { var password = this.newPasswordText.value; var passwordConfirm = this.newPasswordConfirmText.value; if( !(password.length > 0) ) return 'Please enter both a new password and its confirmation. '; if( !(password == passwordConfirm) ) return 'New password does not match its confirmation. Please try again. '; return null; }; ResetPasswordState.prototype.getTitle = function( ) { return 'Reset Your actiTIME Password'; }; ResetPasswordState.prototype.getTooltip = function( ) { return '
' + this.tooltipText + '
'; }; ResetPasswordState.prototype.getTimeoutMessage = function() { return "Cannot save new password for
2 minutes. Please try again later."; }; function ErrorState( config ) { BaseLoginPageState.call(this, config); this.message = config.message; } ErrorState.prototype = new BaseLoginPageState(); ErrorState.prototype.getTitle = function( ) { return null; }; ErrorState.prototype.getTooltip = function( ) { return '
' + this.message + '
'; }; ErrorState.prototype.getErrorMessage = function() { return message; }; var ADMIN_MANAGER_TOOLTIP = '
' + '
To login for the first time use the following username and password:
' + '
 
' + '
Username: admin
' + '
Password: manager
' + '
 
' + ' ' + ' ' + ' ' + ' ' + ' ' + '
It is strongly recommended to change the default password to keep your data secure.
' + '
 
' + '
' + '
'; var PASSWORD_SUCCESSFULLY_RESET_TOOLTIP = '
' + '
Your password was successfully reset.
' + '
Your username has been sent to your email address.
' + '
'; var LOGIN_INFO_SUCCESSFULLY_SENT_TOOLTIP = '
' + '
{0}
' + '
'; var DEMO_TOOLTIP = '
' + '
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
' + '
 
' + '
' + '
';