protected bool SaveUser(bool updateUser) { bool bErrors = false; bool success; Label lblErrorMessage = null; PERSON person = LocalPerson(); string currentSSOID = LocalPerson().SSO_ID; PERSON currentPerson = new PERSON(); if (isNew) { person.SSO_ID = string.IsNullOrEmpty(tbUserSSOID.Text) ? "" : tbUserSSOID.Text.Trim(); // trim traling blanks when creating new user } else { person = SQMModelMgr.LookupPerson(entities, person.PERSON_ID, "", false); person.SSO_ID = string.IsNullOrEmpty(tbUserSSOID.Text) ? "" : tbUserSSOID.Text; currentPerson.ROLE = person.ROLE; } person.FIRST_NAME = string.IsNullOrEmpty(tbUserFirstName.Text) ? "" : tbUserFirstName.Text; person.LAST_NAME = string.IsNullOrEmpty(tbUserLastName.Text) ? "" : tbUserLastName.Text; person.JOB_TITLE = tbUserTitle.Text; person.PHONE = tbUserPhone.Text; person.EMAIL = tbUserEmail.Text; if (!string.IsNullOrEmpty(ddlUserLanguage.SelectedValue)) { person.PREFERRED_LANG_ID = Convert.ToInt32(ddlUserLanguage.SelectedValue); } if (!string.IsNullOrEmpty(ddlUserTimezone.SelectedValue)) { person.PREFERRED_TIMEZONE = ddlUserTimezone.SelectedValue; } person.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID; if (!string.IsNullOrEmpty(ddlHRLocation.SelectedValue)) { PLANT plant = SQMModelMgr.LookupPlant(Convert.ToDecimal(ddlHRLocation.SelectedValue)); if (plant != null) { person.PLANT_ID = plant.PLANT_ID; person.BUS_ORG_ID = (decimal)plant.BUS_ORG_ID; } } person.NEW_LOCATION_CD = ""; foreach (RadComboBoxItem item in SQMBasePage.GetComboBoxCheckedItems(ddlPlantSelect)) { person.NEW_LOCATION_CD += (item.Value + ","); } person.NEW_LOCATION_CD = person.NEW_LOCATION_CD.TrimEnd(','); person.OLD_LOCATION_CD = ""; foreach (RadComboBoxItem item in SQMBasePage.GetComboBoxCheckedItems(ddlCustPlantSelect)) { person.OLD_LOCATION_CD += (item.Value + ","); } person.OLD_LOCATION_CD = person.OLD_LOCATION_CD.TrimEnd(','); person.STATUS = ddlUserStatus.SelectedValue; // roles were originally a list - let's keep the logic below just in case we need to restore a multi-role strategy //person.PERSON_ROLE.Clear(); person.ROLE = GetSelectedUserRole(); person.RCV_ESCALATION = cbUserRcvEscalation.Checked; person.PERSON_ACCESS.Clear(); string prod = ""; foreach (RadComboBoxItem accessItem in ddlModuleAccess.Items) { if (accessItem.IsSeparator) { prod = accessItem.Value; } if (accessItem.Checked || person.ROLE <= 100) { person = SQMModelMgr.AddPersonAccess(person, prod, accessItem.Value, true); } } SetLocalPerson(person); if (string.IsNullOrEmpty(tbUserSSOID.Text) || string.IsNullOrEmpty(tbUserFirstName.Text) || string.IsNullOrEmpty(tbUserLastName.Text) || string.IsNullOrEmpty(tbUserEmail.Text) || ddlUserRole.SelectedIndex < 0 || string.IsNullOrEmpty(ddlHRLocation.SelectedValue) || string.IsNullOrEmpty(ddlHRLocation.SelectedValue)) { lblErrorMessage = lblErrRequiredInputs; } if (lblErrorMessage == null) { // AW20131106 - need to verify that the SSO_ID and email address are unique in the system lblDuplicateSSOId.Visible = false; lblDuplicateEmail.Visible = false; string strSSOId = tbUserSSOID.Text; string strEmail = tbUserEmail.Text; if (isNew) // || !strSSOId.Equals(person.SSO_ID)) { // verify unique sso_id strSSOId = tbUserSSOID.Text.Trim(); SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities(); SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctxAccess, strSSOId, "", false); if (access != null && access.SSO_ID.ToLower().Equals(strSSOId.ToLower())) { lblErrorMessage = lblDuplicateSSOId; } } if (lblErrorMessage == null && (isNew || !strEmail.Equals(person.EMAIL))) { // verify unique email SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities(); //SQM_ACCESS access = SQMModelMgr.LookupCredentialsByEmail(ctxAccess, strEmail, false); // ABW 20140117 - we want to look up email on person record... PERSON personEmail = SQMModelMgr.LookupPersonByEmail(ctxAccess, strEmail); if (personEmail != null && personEmail.EMAIL.Trim().ToLower().Equals(strEmail.Trim().ToLower())) { lblErrorMessage = lblDuplicateEmail; } } } if (lblErrorMessage != null) { DisplayUser(); DisplayErrorMessage(lblErrorMessage); return(false); } if (updateUser) { List <SETTINGS> MailSettings = SQMSettings.SelectSettingsGroup("MAIL", ""); // ABW 20140805 SETTINGS setting = new SETTINGS(); // ABW 20140805 SetLocalPerson(SQMModelMgr.UpdatePerson(entities, person, SessionManager.UserContext.UserName(), false, currentSSOID)); //selectedUser = SQMModelMgr.UpdatePerson(entities, person, SessionManager.UserContext.UserName(), Convert.ToBoolean(GetFindControlValue("cbIsBuyer", hfBase, out success)), GetFindControlValue("tbBuyerCode", hfBase, out success)); // AW20131106 - send an email for new users with random password generation setting = MailSettings.Find(x => x.SETTING_CD == "MailFromSystem"); // ABW 20140805 string strEmailCompanyName = ""; // ABW 20140805 if (setting != null) // ABW 20140805 { strEmailCompanyName = setting.VALUE; } if (isNew) { // send a confirmation email // string strength = WebConfigurationManager.AppSettings["PasswordComplexity"]; // ABW 20140805 SETTINGS complexity = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordComplexity"); // ABW 20140805 string strength = ""; // ABW 20140805 if (complexity == null) { strength = "4"; } else { strength = complexity.VALUE; } SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities(); SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctxAccess, LocalPerson().SSO_ID, "", false); string key = SQMModelMgr.GetPasswordKey(); string strPassword = WebSiteCommon.Decrypt(access.PASSWORD, key); // ABW 20140805 - Build the email based on fields in the SETTINGS table // the following is standard email //string strEmailBody = lblPasswordEmailBody1a.Text.ToString() + strEmailCompanyName + lblPasswordEmailBody1b.Text.ToString() + " " + selectedUser.SSO_ID + lblPasswordEmailBody2.Text.ToString() + " " + strPassword; //strEmailBody += "<br><br>" + WebSiteCommon.GetXlatValueLong("passwordComplexity", strength) + "<br><br>" + lblPasswordEmailBody3.Text.ToString().Trim(); // the following is for TI only //string strEmailBody = "Risk Management Professional,<br><br>TI Automotive Risk Management is pleased to offer you access to the TI Automotive Risk Management Portal (Portal)<br><br>The Portal will be used to provide tracking for:<br>"; //strEmailBody += "<ul><li>Environmental performance tracking</li><li>Insurer Recommendations response</li><li>Internal Risk Quality Index Recommendations Response</li><li>Safety Alerts</li>"; //strEmailBody += "<br>A new user account has been created for you in the Portal.<br><br>Access the website by clicking on the link: <a href='http://Ti.qai.luxinteractive.com'>Ti.qai.luxinteractive.com</a><br><br>"; //strEmailBody += "Your username has been assigned: <font color='red'>" + selectedUser.SSO_ID + "</font><br>Your temporary password is: <font color='red'>" + strPassword + "</font>"; //strEmailBody += "<br>Once you gain access to the Portal you must change your password. " + WebSiteCommon.GetXlatValueLong("passwordComplexity", strength) + "<br><br>" + lblPasswordEmailBody3.Text.ToString().Trim(); //strEmailBody += "<br><br><b>Michael D. Wildfong</b><br>Global Director Facilities Risk Management<br>TI Automotive<br>1272 Doris Road<br>Auburn Hills, MI 48326<br>t: +1 248 494 5320<br>m: + 1 810 265 1677<br>f: +1 248 494 5302"; //strEmailBody += "<br>e: <a href='mailto:[email protected]'>[email protected]</a>"; // ABW 20140805 - Build the email based on fields in the SETTINGS table string strEmailSubject = ""; setting = MailSettings.Find(x => x.SETTING_CD == "NewUserSubject"); if (setting == null) { strEmailSubject = strEmailCompanyName + " " + lblPasswordEmailSubject.Text.ToString(); } else { strEmailSubject = setting.VALUE.Trim(); } setting = MailSettings.Find(x => x.SETTING_CD == "NewUserWelcome"); string strEmailBody = ""; if (setting == null) { strEmailBody = lblPasswordEmailBody1a.Text.ToString(); } else { strEmailBody = setting.VALUE.Trim(); } strEmailBody += lblPasswordEmailBody1b.Text.ToString() + " " + LocalPerson().SSO_ID + lblPasswordEmailBody2.Text.ToString() + " " + strPassword; setting = MailSettings.Find(x => x.SETTING_CD == "MailURL"); if (setting != null) { strEmailBody += lblPasswordEmailBody2b.Text.ToString() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>"; } complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength); // ABW 20140805 if (complexity != null) { strEmailBody += "<br><br>" + complexity.VALUE + "<br><br>"; } setting = MailSettings.Find(x => x.SETTING_CD == "NewUserSignature"); if (setting == null) { strEmailBody += "<br><br>" + lblPasswordEmailBody3.Text.ToString(); } else { strEmailBody += "<br><br>" + setting.VALUE.Trim(); } // ABW 20140117 - we are now using the email on the Person record Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody.Trim(), "")); thread.IsBackground = true; thread.Start(); } else { bool roleChanged = person.ROLE != currentPerson.ROLE || person.PERSON_ACCESS.Count != currentPerson.PERSON_ACCESS.Count ? true : false; if (roleChanged) { // string strEmailBody = lblUserRoleEmailBodya.Text + strEmailCompanyName + lblUserRoleEmailBodyb.Text + "<br><br>" + lblUserRoleEmailBodyc.Text; // ABW 20140805 - Build the email based on fields in the SETTINGS table string strEmailSubject = ""; setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSubject"); if (setting == null) { strEmailSubject = lblUserRoleEmailSubjecta.Text + strEmailCompanyName + lblUserRoleEmailSubjectb.Text; } else { strEmailSubject = setting.VALUE.Trim(); } setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeWelcome"); string strEmailBody = ""; if (setting == null) { strEmailBody = lblUserRoleEmailBodya.Text + strEmailCompanyName + lblUserRoleEmailBodyb.Text; } else { strEmailBody = setting.VALUE.Trim(); } setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSignature"); if (setting == null) { strEmailBody += "<br><br>" + lblUserRoleEmailBodyc.Text; } else { strEmailBody += "<br><br>" + setting.VALUE.Trim(); } Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody, "")); thread.IsBackground = true; thread.Start(); } if (cbResetPassword.Checked) { // build the email body in 3 segments SETTINGS complexity = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordComplexity"); string strength = ""; if (complexity == null) { strength = "4"; } else { strength = complexity.VALUE; } string strEmailSubject = ""; setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetSubject"); if (setting == null) { strEmailSubject = strEmailCompanyName + " " + lblResetEmailSubject.Text.ToString(); } else { strEmailSubject = setting.VALUE.Trim(); } setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetWelcome"); string strEmailBodya = ""; string strEmailBodyb = ""; string strEmailBodyc = ""; if (setting == null) { strEmailBodya = lblPasswordEmailBody1a.Text.ToString(); } else { strEmailBodya = setting.VALUE.Trim(); } strEmailBodya += lblPasswordEmailBody1b.Text.ToString(); strEmailBodyb = lblPasswordEmailBody2.Text.ToString(); setting = MailSettings.Find(x => x.SETTING_CD == "MailURL"); if (setting != null) { strEmailBodyc += lblPasswordEmailBody2b.Text.ToString() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>"; } complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength); if (complexity != null) { strEmailBodyc += "<br><br>" + complexity.VALUE + "<br><br>"; } setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetSignature"); if (setting == null) { strEmailBodyc += "<br><br>" + lblPasswordEmailBody3.Text.ToString(); } else { strEmailBodyc += "<br><br>" + setting.VALUE.Trim(); } int msg = WebSiteCommon.RecoverPassword(person.EMAIL, person.SSO_ID, strEmailSubject, strEmailBodya, strEmailBodyb, strEmailBodyc); } } isNew = false; if (SQMModelMgr.updateStatus < 0) // report error { AlertUpdateResult(SQMModelMgr.updateStatus); } } else { SetLocalPerson(person); } return(true); }
public UserContext Initialize(string SSOID, string pwd, bool activeOnly) { SQM.Website.PSsqmEntities ctx = new PSsqmEntities(); this.LoginStatus = LoginStatus.SSOUndefined; SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctx, SSOID, pwd, true); if (access != null) { string key = SQMModelMgr.GetPasswordKey(); // AW - for now, we want to allow if the password = the password OR the encrypted password string password = WebSiteCommon.Decrypt(access.PASSWORD, key); //string encrypt = WebSiteCommon.Encrypt(pwd, key); //string ss = encrypt; /* * if ((string.IsNullOrEmpty(pwd) && (SSOID.ToLower() != "admin")) || (pwd != password && pwd != access.PASSWORD)) * this.LoginStatus = LoginStatus.PasswordMismatch; */ //if (!string.IsNullOrEmpty(access.PASSWORD) && (pwd != password && pwd != access.PASSWORD)) if (pwd != password && pwd != access.PASSWORD) { this.LoginStatus = LoginStatus.PasswordMismatch; } else if (activeOnly && access.STATUS == "I") { this.LoginStatus = LoginStatus.Inactive; } else if (access.STATUS == "L") { this.LoginStatus = LoginStatus.Locked; } else { if ((this.Person = SQMModelMgr.LookupPerson(ctx, 0, access.SSO_ID, false)) == null) { this.LoginStatus = LoginStatus.PersonUndefined; } else { this.LoginStatus = LoginStatus.Success; this.HRLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); if (this.HRLocation.Company == null) { this.LoginStatus = LoginStatus.CompanyUndefined; } else { SessionManager.EffLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); if (this.Person.PERSON_RESP.ALT_COMPANY_ID > 0) { this.WorkingLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.PERSON_RESP.ALT_COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.PERSON_RESP.ALT_BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PERSON_RESP.ALT_PLANT_ID)); } else { this.WorkingLocation = new BusinessLocation(); this.WorkingLocation = SessionManager.EffLocation; } //this.WorkingLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); this.PlantAccessList = new List <decimal>(); if (!string.IsNullOrEmpty(Person.NEW_LOCATION_CD)) { decimal plantID; string[] locs = Person.NEW_LOCATION_CD.Split(','); foreach (string locid in locs) { if (decimal.TryParse(locid, out plantID)) { this.PlantAccessList.Add(plantID); } } } access.LAST_LOGON_DT = WebSiteCommon.CurrentUTCTime(); int ctxstatus = 0; SQMModelMgr.UpdateCredentials(ctx, access, "", out ctxstatus); this.Credentials = access; this.TimeZoneID = WebSiteCommon.GetXlatValue("timeZone", this.Person.PREFERRED_TIMEZONE); this.DelegateList = new List <decimal>(); this.DelegateList = SQMModelMgr.SelectDelegateList(ctx, this.Person.PERSON_ID).Select(l => l.PERSON_ID).ToList(); this.EscalationAssignments = SQMModelMgr.SelectPersonEscalationList(ctx, this.Person.PERSON_ID); if (SessionManager.CreateSessionContext(this) == null) { this.LoginStatus = LoginStatus.SessionError; } this.InboxReviews = 0; this.TaskList = new List <TaskItem>(); } } } } return(this); }
public UserContext Initialize(string SSOID, string pwd, bool activeOnly) { SQM.Website.PSsqmEntities ctx = new PSsqmEntities(); this.LoginStatus = LoginStatus.SSOUndefined; SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctx, SSOID, pwd, true); if (access != null) { string key = SQMModelMgr.GetPasswordKey(); // AW - for now, we want to allow if the password = the password OR the encrypted password string password = WebSiteCommon.Decrypt(access.PASSWORD, key); //string encrypt = WebSiteCommon.Encrypt(pwd, key); //string ss = encrypt; /* * if ((string.IsNullOrEmpty(pwd) && (SSOID.ToLower() != "admin")) || (pwd != password && pwd != access.PASSWORD)) * this.LoginStatus = LoginStatus.PasswordMismatch; */ //if (!string.IsNullOrEmpty(access.PASSWORD) && (pwd != password && pwd != access.PASSWORD)) if (pwd != password && pwd != access.PASSWORD) { this.LoginStatus = LoginStatus.PasswordMismatch; } else if (activeOnly && access.STATUS == "I") { this.LoginStatus = LoginStatus.Inactive; } else if (access.STATUS == "L") { this.LoginStatus = LoginStatus.Locked; } else { if ((this.Person = SQMModelMgr.LookupPerson(ctx, 0, access.SSO_ID, false)) == null) { this.LoginStatus = LoginStatus.PersonUndefined; } else { this.LoginStatus = LoginStatus.Success; this.HRLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); if (this.HRLocation.Company == null) { this.LoginStatus = LoginStatus.CompanyUndefined; } else { this.PrivList = SQMModelMgr.SelectPrivGroupPerson(this.Person.PRIV_GROUP, "COMMON"); SessionManager.EffLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); this.WorkingLocation = new BusinessLocation(); this.WorkingLocation = SessionManager.EffLocation; this.PlantAccessList = new List <decimal>(); this.PlantAccessList.Add(this.WorkingLocation.Plant.PLANT_ID); if (!string.IsNullOrEmpty(Person.NEW_LOCATION_CD)) { decimal plantID; string[] locs = Person.NEW_LOCATION_CD.Split(','); foreach (string locid in locs) { if (!string.IsNullOrEmpty(locid)) { if (decimal.TryParse(locid, out plantID) && plantID != this.WorkingLocation.Plant.PLANT_ID) { this.PlantAccessList.Add(plantID); } } } } access.LAST_LOGON_DT = WebSiteCommon.CurrentUTCTime(); int ctxstatus = 0; SQMModelMgr.UpdateCredentials(ctx, access, "", out ctxstatus); this.Credentials = access; this.TimeZoneID = this.HRLocation.Plant.LOCAL_TIMEZONE; this.LocalTime = !string.IsNullOrEmpty(this.TimeZoneID) ? WebSiteCommon.LocalTime(DateTime.UtcNow, this.TimeZoneID) : DateTime.UtcNow; this.Language = SQMModelMgr.LookupLanguage(ctx, "", this.Person.PREFERRED_LANG_ID.HasValue ? (int)this.Person.PREFERRED_LANG_ID : 1, false); if (SessionManager.CreateSessionContext(this) == null) { this.LoginStatus = LoginStatus.SessionError; } this.InboxReviews = 0; } } } } return(this); }
protected bool SaveUser(bool updateUser) { bool bErrors = false; bool success; Label lblErrorMessage = null; PERSON person = LocalPerson(); string currentSSOID = LocalPerson().SSO_ID; PERSON currentPerson = new PERSON(); if (isNew) { person.SSO_ID = string.IsNullOrEmpty(tbUserSSOID.Text) ? "" : tbUserSSOID.Text.Trim(); // trim traling blanks when creating new user } else { person = SQMModelMgr.LookupPerson(entities, person.PERSON_ID, "", false); person.SSO_ID = string.IsNullOrEmpty(tbUserSSOID.Text) ? "" : tbUserSSOID.Text; currentPerson.ROLE = person.ROLE; } person.FIRST_NAME = string.IsNullOrEmpty(tbUserFirstName.Text) ? "" : tbUserFirstName.Text; person.LAST_NAME = string.IsNullOrEmpty(tbUserLastName.Text) ? "" : tbUserLastName.Text; person.MIDDLE_NAME = string.IsNullOrEmpty(tbUserMiddleName.Text) ? "" : tbUserMiddleName.Text; person.JOBCODE_CD = ddlJobCode.SelectedValue; if (string.IsNullOrEmpty(ddlPrivGroup.SelectedValue)) { person.PRIV_GROUP = null; } else { person.PRIV_GROUP = ddlPrivGroup.SelectedValue; } person.PHONE = tbUserPhone.Text; person.EMAIL = tbUserEmail.Text; person.EMP_ID = tbEmpID.Text; person.SUPV_EMP_ID = tbSupvEmpID.Text; if (!string.IsNullOrEmpty(ddlUserLanguage.SelectedValue)) { person.PREFERRED_LANG_ID = Convert.ToInt32(ddlUserLanguage.SelectedValue); } if (!string.IsNullOrEmpty(ddlUserTimezone.SelectedValue)) { person.PREFERRED_TIMEZONE = ddlUserTimezone.SelectedValue; } person.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID; if (!string.IsNullOrEmpty(ddlHRLocation.SelectedValue)) { PLANT plant = SQMModelMgr.LookupPlant(Convert.ToDecimal(ddlHRLocation.SelectedValue)); if (plant != null) { person.PLANT_ID = plant.PLANT_ID; person.BUS_ORG_ID = (decimal)plant.BUS_ORG_ID; } } person.NEW_LOCATION_CD = ""; foreach (RadComboBoxItem item in SQMBasePage.GetComboBoxCheckedItems(ddlPlantSelect)) { if (string.IsNullOrEmpty(person.NEW_LOCATION_CD)) { person.NEW_LOCATION_CD = ","; } person.NEW_LOCATION_CD += (item.Value + ","); } person.OLD_LOCATION_CD = ""; /* quality module reference * foreach (RadComboBoxItem item in SQMBasePage.GetComboBoxCheckedItems(ddlCustPlantSelect)) * { * person.OLD_LOCATION_CD += (item.Value + ","); * } * person.OLD_LOCATION_CD = person.OLD_LOCATION_CD.TrimEnd(','); */ person.STATUS = ddlUserStatus.SelectedValue; // roles were originally a list - let's keep the logic below just in case we need to restore a multi-role strategy //person.PERSON_ROLE.Clear(); person.ROLE = 100; ///// person.RCV_ESCALATION = true; person.LOCKS = ""; if (cbUserEmailLock.Checked) { person.LOCKS += (LockField.email.ToString() + ","); } if (cbPrivGroupLock.Checked) { person.LOCKS += (LockField.priv.ToString() + ","); } if (cbHRLocationLock.Checked) { person.LOCKS += (LockField.plant.ToString() + ","); } if (cbUserLanguageLock.Checked) { person.LOCKS += (LockField.lang.ToString() + ","); } person.LOCKS = person.LOCKS.TrimEnd(','); SetLocalPerson(person); if (string.IsNullOrEmpty(tbUserSSOID.Text) || string.IsNullOrEmpty(tbUserFirstName.Text) || string.IsNullOrEmpty(tbUserLastName.Text) || ddlJobCode.SelectedIndex < 0 || string.IsNullOrEmpty(ddlHRLocation.SelectedValue) || string.IsNullOrEmpty(ddlHRLocation.SelectedValue)) { lblErrorMessage = lblErrRequiredInputs; } if (lblErrorMessage == null) { // AW20131106 - need to verify that the SSO_ID and email address are unique in the system lblDuplicateSSOId.Visible = false; lblDuplicateEmail.Visible = false; string strSSOId = tbUserSSOID.Text; string strEmail = tbUserEmail.Text; if (isNew) // || !strSSOId.Equals(person.SSO_ID)) { // verify unique sso_id strSSOId = tbUserSSOID.Text.Trim(); SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities(); SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctxAccess, strSSOId, "", false); if (access != null && access.SSO_ID.ToLower().Equals(strSSOId.ToLower())) { lblErrorMessage = lblDuplicateSSOId; } } if (lblErrorMessage == null && (isNew || !strEmail.Equals(person.EMAIL))) { // verify unique email SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities(); //SQM_ACCESS access = SQMModelMgr.LookupCredentialsByEmail(ctxAccess, strEmail, false); // ABW 20140117 - we want to look up email on person record... PERSON personEmail = SQMModelMgr.LookupPersonByEmail(ctxAccess, strEmail); if (personEmail != null && personEmail.EMAIL.Trim().ToLower().Equals(strEmail.Trim().ToLower())) { lblErrorMessage = lblDuplicateEmail; } } } if (lblErrorMessage != null) { DisplayUser(); DisplayErrorMessage(lblErrorMessage); return(false); } if (updateUser) { string defaultPwd = ""; string environment = System.Configuration.ConfigurationManager.AppSettings["environment"].ToString(); string altEmail = !string.IsNullOrEmpty(environment) && environment.ToLower() == "dev" ? System.Configuration.ConfigurationManager.AppSettings["altEmail"].ToString() : ""; if (isNew) { SETTINGS pwdInitial = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordDefault"); if (pwdInitial != null) { switch (pwdInitial.VALUE.ToUpper()) { case "LASTNAME": defaultPwd = person.LAST_NAME; break; case "EMPID": defaultPwd = person.EMP_ID; break; default: break; } } } SetLocalPerson(SQMModelMgr.UpdatePerson(entities, person, SessionManager.UserContext.UserName(), false, currentSSOID, defaultPwd)); //selectedUser = SQMModelMgr.UpdatePerson(entities, person, SessionManager.UserContext.UserName(), Convert.ToBoolean(GetFindControlValue("cbIsBuyer", hfBase, out success)), GetFindControlValue("tbBuyerCode", hfBase, out success)); // AW20131106 - send an email for new users with random password generation List <SETTINGS> MailSettings = SQMSettings.SelectSettingsGroup("MAIL", ""); // ABW 20140805 SETTINGS setting = new SETTINGS(); // ABW 20140805 setting = MailSettings.Find(x => x.SETTING_CD == "MailFromSystem"); // ABW 20140805 string strEmailCompanyName = ""; // ABW 20140805 if (setting != null) // ABW 20140805 { strEmailCompanyName = setting.VALUE; } bool sendEmail = false; setting = MailSettings.Find(x => x.SETTING_CD == "SendNewUserEmail"); if (setting != null && setting.VALUE.ToLower().Equals("true")) // ABW 20140805 { sendEmail = true; } List <XLAT> XLATList = SQMBasePage.SelectXLATList(new string[1] { "USER_EMAIL" }, 0); string strEmailSubject = ""; string strEmailBody = ""; LOCAL_LANGUAGE lang = SQMModelMgr.LookupLanguage(new PSsqmEntities(), "", (int)person.PREFERRED_LANG_ID, false); string strTemp = ""; if (isNew && (string.IsNullOrEmpty(defaultPwd) || sendEmail)) // send email notice only when a default password was not set { // send a confirmation email // string strength = WebConfigurationManager.AppSettings["PasswordComplexity"]; // ABW 20140805 SETTINGS complexity = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordComplexity"); // ABW 20140805 string strength = ""; // ABW 20140805 if (complexity == null) { strength = "4"; } else { strength = complexity.VALUE; } SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities(); SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctxAccess, LocalPerson().SSO_ID, "", false); string key = SQMModelMgr.GetPasswordKey(); string strPassword = WebSiteCommon.Decrypt(access.PASSWORD, key); // ABW 20140805 - Build the email based on fields in the SETTINGS table //string strEmailSubject = ""; //setting = MailSettings.Find(x => x.SETTING_CD == "NewUserSubject"); //if (setting == null) // strEmailSubject = strEmailCompanyName + " " + lblPasswordEmailSubject.Text.ToString(); //else // strEmailSubject = setting.VALUE.Trim(); //setting = MailSettings.Find(x => x.SETTING_CD == "NewUserWelcome"); //string strEmailBody = ""; //if (setting == null) // strEmailBody = lblPasswordEmailBody1a.Text.ToString(); //else // strEmailBody = setting.VALUE.Trim(); //strEmailBody += lblPasswordEmailBody1b.Text.ToString() + " " + LocalPerson().SSO_ID + lblPasswordEmailBody2.Text.ToString() + " " + strPassword; //setting = MailSettings.Find(x => x.SETTING_CD == "MailURL"); //if (setting != null) // strEmailBody += lblPasswordEmailBody2b.Text.ToString() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>"; //complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength); // ABW 20140805 //if (complexity != null) // strEmailBody += "<br><br>" + complexity.VALUE + "<br><br>"; //setting = MailSettings.Find(x => x.SETTING_CD == "NewUserSignature"); //if (setting == null) // strEmailBody += "<br><br>" + lblPasswordEmailBody3.Text.ToString(); //else // strEmailBody += "<br><br>" + setting.VALUE.Trim(); // ABW 20160115 - Build the email based on fields in the XLAT table strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserSubject", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailSubject = strEmailCompanyName + " " + lblPasswordEmailSubject.Text.ToString(); } else { strEmailSubject = strTemp.Trim(); } strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserWelcome", lang.NLS_LANGUAGE).DESCRIPTION; strEmailBody = ""; if (strTemp == null || strTemp == "") { strEmailBody = lblPasswordEmailBody1a.Text.ToString(); } else { strEmailBody = strTemp.Trim(); } strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUsername", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBody += lblPasswordEmailBody1b.Text.ToString(); } else { strEmailBody += strTemp.Trim(); } strEmailBody += " " + LocalPerson().SSO_ID; strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyPassword", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBody += lblPasswordEmailBody2.Text.ToString(); } else { strEmailBody += strTemp.Trim(); } strEmailBody += " " + strPassword; strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUrl", lang.NLS_LANGUAGE).DESCRIPTION; string strUrlLabel = ""; if (strTemp == null || strTemp == "") { strUrlLabel = lblPasswordEmailBody2b.Text.ToString(); } else { strUrlLabel = strTemp.Trim(); } setting = MailSettings.Find(x => x.SETTING_CD == "MailURL"); if (setting != null) { strEmailBody += strUrlLabel + " <a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>"; } complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength); // ABW 20140805 if (complexity != null) { strEmailBody += "<br><br>" + complexity.VALUE + "<br><br>"; } strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserSignature", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBody += "<br><br>" + lblPasswordEmailBody3.Text.ToString(); } else { strEmailBody += "<br><br>" + strTemp.Trim(); } // ABW 20140117 - we are now using the email on the Person record /* * Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody.Trim(), "")); * thread.IsBackground = true; * thread.Start(); */ string mailStatus = WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody.Trim(), ""); EHSNotificationMgr.WriteEmailLog(entities, person.EMAIL, "", strEmailSubject, strEmailBody, 0, LocalPerson().PERSON_ID, ("user password notification - is new = " + isNew.ToString()), mailStatus, altEmail); } else { bool roleChanged = person.ROLE != currentPerson.ROLE ? true : false; // ABW 20160115 - send an email based on a parameter setting = MailSettings.Find(x => x.SETTING_CD == "SendChangeUserEmail"); if (setting != null && setting.VALUE.ToLower().Equals("true")) { sendEmail = true; } else { sendEmail = false; } if (roleChanged && sendEmail) { //ABW 20140805 - Build the email based on fields in the SETTINGS table //strEmailSubject = ""; //setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSubject"); //if (setting == null) // strEmailSubject = lblUserRoleEmailSubjecta.Text + strEmailCompanyName + lblUserRoleEmailSubjectb.Text; //else // strEmailSubject = setting.VALUE.Trim(); //setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeWelcome"); //string strEmailBody = ""; //if (setting == null) // strEmailBody = lblUserRoleEmailBodya.Text + strEmailCompanyName + lblUserRoleEmailBodyb.Text; //else // strEmailBody = setting.VALUE.Trim(); //setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSignature"); //if (setting == null) // strEmailBody += "<br><br>" + lblUserRoleEmailBodyc.Text; //else // strEmailBody += "<br><br>" + setting.VALUE.Trim(); //ABW 20160115 - Build the email based on fields in the XLAT table strEmailSubject = ""; strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminRoleChangeSubject", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailSubject = lblUserRoleEmailSubjecta.Text + strEmailCompanyName + lblUserRoleEmailSubjectb.Text; } else { strEmailSubject = strTemp.Trim(); } strEmailBody = ""; strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminRoleChangeWelcome", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBody = lblUserRoleEmailBodya.Text + strEmailCompanyName + lblUserRoleEmailBodyb.Text; } else { strEmailBody = strTemp.Trim(); } setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSignature"); strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminRoleChangeSignature", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBody += "<br><br>" + lblUserRoleEmailBodyc.Text; } else { strEmailBody += strTemp.Trim(); } /* * Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody, "")); * thread.IsBackground = true; * thread.Start(); */ string mailStatus = WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody, ""); EHSNotificationMgr.WriteEmailLog(entities, person.EMAIL, "", strEmailSubject, strEmailBody, 0, LocalPerson().PERSON_ID, "user role changed", mailStatus, altEmail); } if (cbResetPassword.Checked) // always send an email when the password changes { // build the email body in 3 segments SETTINGS complexity = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordComplexity"); string strength = ""; if (complexity == null) { strength = "4"; } else { strength = complexity.VALUE; } // ABW 20140805 - Build the email based on fields in the SETTINGS table //string strEmailSubject = ""; //setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetSubject"); //if (setting == null) // strEmailSubject = strEmailCompanyName + " " + lblResetEmailSubject.Text.ToString(); //else // strEmailSubject = setting.VALUE.Trim(); //setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetWelcome"); //string strEmailBodya = ""; //string strEmailBodyb = ""; //string strEmailBodyc = ""; //if (setting == null) // strEmailBodya = lblPasswordEmailBody1a.Text.ToString(); //else // strEmailBodya = setting.VALUE.Trim(); //strEmailBodya += lblPasswordEmailBody1b.Text.ToString(); //strEmailBodyb = lblPasswordEmailBody2.Text.ToString(); //setting = MailSettings.Find(x => x.SETTING_CD == "MailURL"); //if (setting != null) // strEmailBodyc += lblPasswordEmailBody2b.Text.ToString() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>"; //complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength); //if (complexity != null) // strEmailBodyc += "<br><br>" + complexity.VALUE + "<br><br>"; //setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetSignature"); //if (setting == null) // strEmailBodyc += "<br><br>" + lblPasswordEmailBody3.Text.ToString(); //else // strEmailBodyc += "<br><br>" + setting.VALUE.Trim(); // ABW 20160115 - Build the email based on fields in the XLAT table strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminPasswordResetSubject", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailSubject = strEmailCompanyName + " " + lblPasswordEmailSubject.Text.ToString(); } else { strEmailSubject = strTemp.Trim(); } string strEmailBodya = ""; string strEmailBodyb = ""; string strEmailBodyc = ""; strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminPasswordResetWelcome", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBodya = lblResetEmailBody1a.Text.ToString(); } else { strEmailBodya = strTemp.Trim(); } strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUsername", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBodya += lblPasswordEmailBody1b.Text.ToString(); } else { strEmailBodya += strTemp.Trim(); } strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyPassword", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBodyb = lblPasswordEmailBody2.Text.ToString(); } else { strEmailBodyb = strTemp.Trim(); } strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUrl", lang.NLS_LANGUAGE).DESCRIPTION; string strUrlLabel = ""; if (strTemp == null || strTemp == "") { strUrlLabel = lblPasswordEmailBody2b.Text.ToString(); } else { strUrlLabel = strTemp.Trim(); } setting = MailSettings.Find(x => x.SETTING_CD == "MailURL"); if (setting != null) { strEmailBodyc += strUrlLabel.Trim() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>"; } complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength); if (complexity != null) { strEmailBodyc += "<br><br>" + complexity.VALUE + "<br><br>"; } strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserSignature", lang.NLS_LANGUAGE).DESCRIPTION; if (strTemp == null || strTemp == "") { strEmailBodyc += "<br><br>" + lblPasswordEmailBody3.Text.ToString(); } else { strEmailBodyc += "<br><br>" + strTemp.Trim(); } int msg = WebSiteCommon.RecoverPassword(person.EMAIL, person.SSO_ID, strEmailSubject, strEmailBodya, strEmailBodyb, strEmailBodyc); EHSNotificationMgr.WriteEmailLog(entities, person.EMAIL, "", strEmailSubject, strEmailBodya, 0, LocalPerson().PERSON_ID, "recover password", msg.ToString(), altEmail); } } isNew = false; if (SQMModelMgr.updateStatus < 0) // report error { AlertUpdateResult(SQMModelMgr.updateStatus); } } else { SetLocalPerson(person); } return(true); }