public static void SetMainControl(ERMTControl view) { ERMTUserControl currentUserControl = new ERMTUserControl { Name = "new" }; switch (view) { case ERMTControl.About: { About about = new About(); about.ShowDialog(); break; } case ERMTControl.EditRegion: { EditRegion editRegion = new EditRegion(); currentUserControl = editRegion; SetMainControl(editRegion); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.ElectoralCycle: { IndexUserControl indexUserControl = new IndexUserControl { IndexContentType = IndexContentType.ElectoralCycle }; currentUserControl = indexUserControl; SetMainControl(indexUserControl); ApplicationPrincipalForm.LoadLeftButtons("electoralcycle"); indexUserControl.ShowHtml(); break; } case ERMTControl.ElectoralCycleModifyPhase: { ElectoralCycleModifyPhase electoralCycleModifyPhase = new ElectoralCycleModifyPhase(); currentUserControl = electoralCycleModifyPhase; SetMainControl(electoralCycleModifyPhase); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.FactorModify: { FactorModify modifyFactor = new FactorModify(); currentUserControl = modifyFactor; SetMainControl(modifyFactor); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.FactorNew: { FactorNew newFactor = new FactorNew(); currentUserControl = newFactor; SetMainControl(newFactor); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.FactorReorder: { FactorsReorder reorderFactors = new FactorsReorder(); currentUserControl = reorderFactors; SetMainControl(reorderFactors); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.KnowledgeResources: { IndexUserControl indexUserControl = new IndexUserControl { IndexContentType = IndexContentType.KnowledgeResources }; currentUserControl = indexUserControl; SetMainControl(indexUserControl); ApplicationPrincipalForm.LoadLeftButtons("KnowledgeResources"); indexUserControl.ShowHtml(); break; } case ERMTControl.Login: { LoginUserControl loginUserControl = new LoginUserControl(); currentUserControl = loginUserControl; SetMainControl(loginUserControl); break; } case ERMTControl.MarkerTypeCRUD: { MarkerTypeCRUD markerTypeControl = new MarkerTypeCRUD(); currentUserControl = markerTypeControl; SetMainControl(markerTypeControl); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.ModelEdit: { ModelEdit modelEdit = new ModelEdit(); currentUserControl = modelEdit; SetMainControl(modelEdit); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.ModelNew: { ModelNew modelNew = new ModelNew(); currentUserControl = modelNew; SetMainControl(modelNew); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.ModelReorderFactors: { ModelReorderFactors modelReorderFactors = new ModelReorderFactors(); currentUserControl = modelReorderFactors; SetMainControl(modelReorderFactors); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.RiskActionRegister: { RiskAndActionRegister riskActionRegister = new RiskAndActionRegister(true); currentUserControl = riskActionRegister; SetMainControl(riskActionRegister); ApplicationPrincipalForm.LoadLeftButtons("riskandaction"); break; } case ERMTControl.RiskMapping: { //RiskMapping riskMapping = new RiskMapping(); //currentUserControl = riskMapping; //SetMainControl(riskMapping); currentUserControl = ControlCache.RiskMappingInstance; SetMainControl(ControlCache.RiskMappingInstance); ApplicationPrincipalForm.LoadLeftButtons("map"); break; } case ERMTControl.Start: { SetMainControl(ControlCache.StartInstance); currentUserControl = ControlCache.StartInstance; ApplicationPrincipalForm.LoadLeftButtons("Start"); break; } case ERMTControl.TestUserControl: { TestUserControl testUserControl = new TestUserControl(); SetMainControl(testUserControl); break; } case ERMTControl.UserModify: { UserModify userModify = new UserModify(); currentUserControl = userModify; SetMainControl(userModify); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.UserNew: { UserNew userNew = new UserNew(); currentUserControl = userNew; SetMainControl(userNew); ApplicationPrincipalForm.LoadLeftButtons(); break; } case ERMTControl.UserResetPassword: { UserChangePassword ucp = new UserChangePassword(); ucp.ShowDialog(); break; } } if (currentUserControl.Name != "new") { currentUserControl.ShowTitle(); } }
/// <summary> /// Convenience method to trigger application functionality /// based on the "leaf" button pressed. A leaf button is one /// that triggers functions, rather than new sub menus /// </summary> /// <param name="functionalityName"></param> /// <returns></returns> private bool initializeFunctionality(string functionalityName) { bool rt = false; if (!string.IsNullOrEmpty(functionalityName)) { CashlinxPawnSupportSession.Instance.HistorySession.TriggerName = functionalityName; //Check functions here if (functionalityName.Equals("changepassword", StringComparison.OrdinalIgnoreCase)) { var password = string.Empty; var chngPwdForm = new UserChangePassword(PawnLDAPAccessor.Instance.PasswordPolicy, CashlinxPawnSupportSession.Instance.LoggedInUserSecurityProfile.UserCurrentPassword); DialogResult pwdResult = chngPwdForm.ShowDialog(); if (pwdResult == DialogResult.OK) { password = chngPwdForm.EnteredNewPassword; CashlinxPawnSupportSession.Instance.LoggedInUserSecurityProfile.UserCurrentPassword = password; } this.handleEndFlow(null); rt = true; } else if (functionalityName.Equals("resetldap", StringComparison.OrdinalIgnoreCase)) { var frm_reset_pwd = new FrmResetPwd(); frm_reset_pwd.ShowDialog(); this.handleEndFlow(null); rt = true; } else if (functionalityName.Equals("cleartemp", StringComparison.OrdinalIgnoreCase)) { var frm_clear_tmp_status = new ClearTempStatus.FrmClearTempStatus1(); frm_clear_tmp_status.ShowDialog(); this.handleEndFlow(null); rt = true; } else if (functionalityName.Equals("recautotrans", StringComparison.OrdinalIgnoreCase)) { //Need FrmAutoTransfer.cs AutoTransfer.FrmAutoTransfer frm_auto_transfer = new AutoTransfer.FrmAutoTransfer(); frm_auto_transfer.ShowDialog(); this.handleEndFlow(null); rt = true; } else if (functionalityName.Equals("custmaint", StringComparison.OrdinalIgnoreCase)) { //var frm_lookup_customer = new Support.Forms.Customer.LookupCustomer(); //frm_lookup_customer.ShowDialog(); //this.handleEndFlow(null); //rt = true; GlobalDataAccessor.Instance.DesktopSession.ClearSessionData(); GlobalDataAccessor.Instance.DesktopSession.HistorySession.Trigger = functionalityName; GlobalDataAccessor.Instance.DesktopSession.AppController.invokeWorkflow( functionalityName, this, this.endStateNotifier); rt = true; } else if (functionalityName.Equals("hardware", StringComparison.OrdinalIgnoreCase)) { //Need Hardware_Config.cs var myHardware = new HardwareConfig.Hardware_Config(); var frm_get_shop = new FrmGetShop(CashlinxPawnSupportSession.Instance); DialogResult shopResult = frm_get_shop.ShowDialog(); if (shopResult == DialogResult.OK) { Hardware_Config.Instance.StoreID = frm_get_shop.StoreGuid; Hardware_Config.Instance.StoreNumber = frm_get_shop.StoreNumber; var frm_hardware_config = new HardwareConfig.FrmConfig(); // myHardware); frm_hardware_config.ShowDialog(); } this.handleEndFlow(null); rt = true; } else if (functionalityName.Equals("gbedit", StringComparison.OrdinalIgnoreCase)) { functionalityName = "GunBookSearch"; GlobalDataAccessor.Instance.DesktopSession.ClearSessionData(); GlobalDataAccessor.Instance.DesktopSession.HistorySession.Trigger = functionalityName; //GlobalDataAccessor.Instance.DesktopSession.AppController.invokeWorkflow( // functionalityName, this, this.endStateNotifier); GlobalDataAccessor.Instance.DesktopSession.AppController.invokeWorkflow( functionalityName, this, this.endStateNotifier); rt = true; } else { MessageBox.Show("Functionality Not Enabled with this release"); this.handleEndFlow(null); rt = true; } } if (rt == false) { MessageBox.Show("Could not invoke child functionality { " + functionalityName + " }", "MenuFunctionalityError", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(rt); }
//Call to login the user and get their security profile /*__________________________________________________________________________________________*/ public override void PerformAuthorization(bool chgUsrPasswd) { var password = string.Empty; var username = string.Empty; if (!this.skipLDAP) { LoggedInUserSecurityProfile = new UserVO(); this.userState = UserDesktopState.NOTLOGGEDIN; //procMsgFormPwd.Show(); //Ensure the LDAP is connected if (PawnLDAPAccessor.Instance.State == PawnLDAPAccessor.LDAPState.DISCONNECTED) { string loginDN; string pwdPolicyCN; string searchDN; string userIdKey; string userPwd; var conf = SecurityAccessor.Instance.EncryptConfig; var ldapService = conf.GetLDAPService( out loginDN, out searchDN, out userIdKey, out userPwd, out pwdPolicyCN); //Initialize LDAP connection PawnLDAPAccessor.Instance.InitializeConnection( conf.DecryptValue(ldapService.Server), conf.DecryptValue(ldapService.Port), loginDN, userPwd, pwdPolicyCN, searchDN, userIdKey); } var attemptCount = 1; do { bool lockedOut; bool needPasswordChange; bool wantsPasswordChange; //var username = string.Empty; var fullAuth = this.PerformLDAPAuthentication( ref attemptCount, ref username, ref password, out lockedOut, out needPasswordChange, out wantsPasswordChange); int outVal = 1; string errCode = string.Empty, errTxt; if (LoginCancel) { try { Application.Exit(); } catch { throw new ApplicationException( "Application has exited due to security violation"); } finally { throw new ApplicationException( "Application has exited due to security violation"); } } if ((!LoginCancel && fullAuth) || (fullAuth && chgUsrPasswd)) { //Check if the user wants to change the password if (wantsPasswordChange || chgUsrPasswd) { var chngPwdForm = new UserChangePassword( PawnLDAPAccessor.Instance.PasswordPolicy, password); DialogResult pwdResult = chngPwdForm.ShowDialog(); if (pwdResult == DialogResult.OK) { password = chngPwdForm.EnteredNewPassword; } } var retVal = true; //int outVal = 1; //var errCode = "0"; //TODO: Update with reference to shared data procedure project when ready // retVal = ShopProcedures.ExecuteUpdateSelectUserInfoActivated( // username.ToLowerInvariant(), -1, out outVal, out errCode, out errTxt); errCode = "0"; if (retVal == false || outVal == 0 || errCode != "0") { MessageBox.Show( "The system has determined that you are not an active user. " + "Please contact Shop System Support. " + "The application will now exit.", "Application Security", MessageBoxButtons.OK, MessageBoxIcon.Stop); try { Application.Exit(); } catch { throw new ApplicationException( "Application has exited due to security violation"); } finally { throw new ApplicationException( "Application has exited due to security violation"); } } } if (!LoginCancel && fullAuth == false) { if (lockedOut) { //TODO: Link to shared data procedures project when ready //ShopProcedures.ExecuteUpdateSelectUserInfoActivated( // username.ToLowerInvariant(), 0, out outVal, out errCode, out errTxt); MessageBox.Show( "The maximum number of attempted failed logins has been exceeded. " + "The user account is now locked. " + "Please contact Shop System Support. " + "The application will now exit.", "Application Security", MessageBoxButtons.OK, MessageBoxIcon.Stop); try { Application.Exit(); } catch { throw new ApplicationException( "Application has exited due to security violation"); } finally { throw new ApplicationException( "Application has exited due to security violation"); } } if (needPasswordChange) { //Invoke password change form //Do not increment attempt count var uPwdForm = new UserChangePassword( PawnLDAPAccessor.Instance.PasswordPolicy, password); DialogResult pwdResult = uPwdForm.ShowDialog(); if (pwdResult == DialogResult.OK) { this.userState = UserDesktopState.LOGGEDIN; password = uPwdForm.EnteredNewPassword; } else { MessageBox.Show( "You must change your password before you will be " + "allowed to log in to the application. " + "The application will now exit.", "Application Security", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); try { Application.Exit(); } catch { throw new ApplicationException( "Application has exited due to user not changing their password"); } finally { throw new ApplicationException( "Application has exited due to user not changing their password"); } } } } if (!LoginCancel && fullAuth == false) { this.userState = UserDesktopState.NOTLOGGEDIN; DialogResult dR = MessageBox.Show( "You have entered invalid credentials. " + "This is your " + (attemptCount.FormatNumberWithSuffix()) + " attempt. " + "Would you like to retry?", "Application Security", MessageBoxButtons.RetryCancel, MessageBoxIcon.Stop); attemptCount++; if (dR == DialogResult.Cancel) { try { Application.Exit(); } catch { throw new ApplicationException( "Application has exited due to security violation"); } finally { throw new ApplicationException( "Application has exited due to security violation"); } } } else { break; } }while (this.userState != UserDesktopState.LOGGEDIN); } if (!LoginCancel && this.userState == UserDesktopState.LOGGEDIN) { //UpdateDesktopUserName(this.desktopForm); //Get role information //The logged in user's security profile will be stored in LoggedInUserSecurityProfile object after the call //TODO: Change to select store prior to getting user security profile //UpdateDesktopUserName(this.desktopForm); if (userState == UserDesktopState.LOGGEDIN) { //Set the password in the users security profile LoggedInUserSecurityProfile.UserCurrentPassword = password; LoggedInUserSecurityProfile.UserID = username; string errorCode = string.Empty; string errorMesg = string.Empty; if (!SecurityProfileProcedures.GetUserSecurityProfile(FullUserName, "", CurrentSiteId.StoreNumber, "N", this, out errorCode, out errorMesg)) { BasicExceptionHandler.Instance.AddException( "Security Profile could not be loaded for the logged in user. Cannot Authorize", new ApplicationException()); MessageBox.Show( "User's security profile could not be loaded. Exiting the application"); Application.Exit(); } } } procMsgFormPwd.Close(); procMsgFormPwd.Dispose(); }