protected void Page_Load(object sender, EventArgs e) { if (true == string.IsNullOrEmpty((string)Session["UserSid"])) { Session["LastError"] = "NO_ERROR"; Response.Redirect("Logon.aspx"); } else { _patientID = Request.QueryString["p"]; using (AwareQIManager.AwareWebSrv.WSAWARE webSrv = new WSAWARE()) { try { string webResponse = webSrv.GetPatientInfo(int.Parse(_patientID), true); if (-1 < webResponse.IndexOf(" - Unknown")) { _patientName = string.Format("Patient ID {0} not found in VistA!!!", _patientID); } else { if (-1 < webResponse.IndexOf("[")) { _patientName = webResponse.Substring(0, (webResponse.IndexOf("[") - 1)); } else { _patientName = webResponse; } int brkyIdx = _patientName.IndexOf("]"); if (-1 < webResponse.IndexOf("]")) { lblLastandFourValue.Text = webResponse[0] + webResponse.Substring((webResponse.IndexOf("]") - 4), 4); } else { lblLastandFourValue.Text = "Web response in wrong format, missing ending bracket!"; } } } catch (System.InvalidOperationException ex) { _patientName = string.Format("Patient ID {0} not found in VistA!!!", _patientID); lblLastandFourValue.Text = _patientName; } } lblDemIdValue.Text = _patientID; lblDemNameValue.Text = _patientName; } }
protected void btnLogin_Click(object sender, EventArgs e) { lblLogonStatus.Text = "Attempting to logon..."; Session["IsSuperUser"] = ValidateSUlogon().ToString(); _awareHelpers = new AwareHelpers(_appSettings.GetAwareDbConnectionString); try { if (true == _AuthenticateUser(tboxUserName.Text.Substring(0, tboxUserName.Text.IndexOf('\\')), tboxUserName.Text.Substring((tboxUserName.Text.IndexOf('\\') + 1)), tboxPassword.Text)) { if (true == ValidateSUlogon()) { Session["UserSid"] = _TranslateUserNameToSid(tboxUserName.Text); Session["LastError"] = string.Empty; Session["IsSuperUser"] = ValidateSUlogon().ToString(); Response.Redirect("Default.aspx"); } } else { if (false == ValidateAVCodes()) { Session["LastError"] = "Logon credentials were invalid"; Page_Load(sender, e); } } } catch (ArgumentOutOfRangeException ex) { if (false == ValidateAVCodes()) { string svrResponse = string.Empty; using (AwareQIManager.AwareWebSrv.WSAWARE webSrv = new WSAWARE()) { webSrv.UseDefaultCredentials = true; svrResponse = webSrv.Login(tboxUserName.Text, tboxPassword.Text); if (null != webSrv) { webSrv.Dispose(); } } // comment the following 2 lines out when building for release //svrResponse = "1^OCONNOR,CATHERINE C[53902]^53902"; //no see all //svrResponse = "2^OCONNOR,CATHERINE C[53902]^53902"; // see all if (0 < svrResponse.IndexOf(WS_LOGON_INVALID_PAIR)) { Session["LastError"] = WS_LOGON_INVALID_PAIR; Page_Load(sender, e); return; } string[] tokens = svrResponse.Split('^'); Guid prvId = new Guid(); if (false == _awareHelpers.AwareSecurity.DoesProviderExist(tokens[2])) { if (true == _awareHelpers.VistaGroups.DoesVistaGroupExist(tokens[0])) { prvId = _awareHelpers.AwareSecurity.AddProvider(tokens[1], tokens[2], _awareHelpers.VistaGroups.GetVistaGroupId(tokens[0])); Session["UserSid"] = prvId.ToString(); Session["IsVistaLogon"] = "True"; } } else { prvId = _awareHelpers.AwareSecurity.UpdateProvider(tokens[1], tokens[2], _awareHelpers.VistaGroups.GetVistaGroupId(tokens[0])); Session["UserSid"] = prvId.ToString(); Session["IsVistaLogon"] = "True"; } if (true == _awareHelpers.VistaGroups.DoesVistaGroupExist(tokens[0])) { Guid vistaGrp = _awareHelpers.VistaGroups.GetVistaGroupId(tokens[0]); Session["VistaAccessKey"] = tboxUserName.Text; Session["VistaGrpId"] = (Guid)vistaGrp; Session["LastError"] = string.Empty; Session["IsSuperUser"] = ValidateSUlogon().ToString(); Response.Redirect("Default.aspx"); } else { Session["LastError"] = "Logon credentials were invalid"; Page_Load(sender, e); } } else { Guid userId = new Guid(); userId = _awareHelpers.AwareUsers.GetUsersId(tboxUserName.Text); if (userId != new Guid()) { Session["UserSid"] = userId.ToString(); Session["LastError"] = string.Empty; Session["IsSuperUser"] = ValidateSUlogon().ToString(); Response.Redirect("Default.aspx"); } else { Session["LastError"] = "Logon credentials were invalid"; Page_Load(sender, e); } } } }