protected void grdOrg_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Edits") { lblMsg.Text = ""; txtOrgIDConfirm.Text = e.CommandArgument.ToString(); //check to see if selected organization is already in Open Waters T_WQX_ORGANIZATION org = db_WQX.GetWQX_ORGANIZATION_ByID(e.CommandArgument.ToString()); if (org != null) { //Case 1: org is already in Open Waters lblConfirmText.Text = org.ORG_FORMAL_NAME + " (" + org.ORG_ID + ") is already using Open Waters. Click 'Confirm' to notify an Administrator for this Organization to approve your access request."; } else { //Case 2: org doesn't exist in Open Waters lblConfirmText.Text = "This Organization does not yet exist in Open Waters. Click 'Confirm' to request access to this organization. "; } pnl1.Visible = false; pnlNewOrgConfirm.Visible = true; grdOrg.Visible = false; btnAdd.Visible = false; } }
/// <summary> /// Returns the WQX timezone code based on the supplied time zone and date /// </summary> /// <param name="dt">Sample Date</param> /// <param name="TimeZoneName"></param> /// <param name="TimeZoneStandardCode">WQX Standard Code</param> /// <param name="TimeZoneDaylightCode">WQX Daylight Savings Code</param> /// <returns></returns> public static string GetWQXTimeZoneByDate(DateTime dt) { try { string OrgID = (HttpContext.Current.Session["OrgID"] ?? "").ToString(); //see if session has any timezone value if ((HttpContext.Current.Session[OrgID + "_TZ"] ?? "") == "") { //no default time zone found in session, need to retrieve from database string TimeZoneID = ""; T_WQX_ORGANIZATION org = db_WQX.GetWQX_ORGANIZATION_ByID(OrgID); if (org != null) { if ((org.DEFAULT_TIMEZONE ?? "") != "") { TimeZoneID = org.DEFAULT_TIMEZONE; } else { TimeZoneID = db_Ref.GetT_OE_APP_SETTING("Default Timezone"); } } T_WQX_REF_DEFAULT_TIME_ZONE tz = db_Ref.GetT_WQX_REF_DEFAULT_TIME_ZONE_ByName(TimeZoneID); if (tz != null) { HttpContext.Current.Session[OrgID + "_TZ"] = tz.OFFICIAL_TIME_ZONE_NAME; HttpContext.Current.Session[OrgID + "_TZ_S"] = tz.WQX_CODE_STANDARD; HttpContext.Current.Session[OrgID + "_TZ_D"] = tz.WQX_CODE_DAYLIGHT; } } TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(HttpContext.Current.Session[OrgID + "_TZ"].ToString()); if (tzi.IsDaylightSavingTime(dt)) { return(HttpContext.Current.Session[OrgID + "_TZ_S"].ToString()); } else { return(HttpContext.Current.Session[OrgID + "_TZ_D"].ToString()); } } catch { return(""); } }
private void PopulateTabsData() { string OrgID = hdnOrgID.Value.ToString(); //tab 1 T_WQX_ORGANIZATION o = db_WQX.GetWQX_ORGANIZATION_ByID(OrgID); if (o != null) { ddlTimeZone.SelectedValue = o.DEFAULT_TIMEZONE; } //tab 2 PopulateCharTab(OrgID); //tab 3 PopulateTaxaGrid(OrgID); //tab 4 grdTranslate.DataSource = db_WQX.GetWQX_IMPORT_TRANSLATE_byOrg(OrgID); grdTranslate.DataBind(); }
public void Configuration(IAppBuilder app) { //IdentityServer configuration settings if (ConfigurationManager.AppSettings["UseIdentityServer"] == "true") { //********************************************************************************************************* //db_Ref.InsertT_OE_SYS_LOG("DEBUG", "starting up auth"); JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary <string, string>(); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = "Cookies", ExpireTimeSpan = System.TimeSpan.FromMinutes(60), }); app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions { //IMPLICIT ClientId = "open_waters", Authority = ConfigurationManager.AppSettings["IdentityServerAuthority"], //"http://localhost:3892/", //ID Server RedirectUri = ConfigurationManager.AppSettings["IdentityServerRedirectURI"], //"http://localhost:1244/signinoidc", , // PostLogoutRedirectUri = ConfigurationManager.AppSettings["IdentityServerPostLogoutURI"], //"http://localhost:1244/signoutcallbackoidc", ResponseType = "id_token", UseTokenLifetime = false, //CallbackPath = new Microsoft.Owin.PathString("/home/index/"), // Critical to prevent infinite loop** SignInAsAuthenticationType = "Cookies", Scope = "openid profile email", TokenValidationParameters = { NameClaimType = "name" }, Notifications = new OpenIdConnectAuthenticationNotifications() { SecurityTokenValidated = (context) => { //********************************************************************************************************* //db_Ref.InsertT_OE_SYS_LOG("DEBUG", "validating user"); //grab information about User ClaimsIdentity _identity = context.AuthenticationTicket.Identity; var UserID_portal = _identity.FindFirst("sub").Value; int UserIDX = 0; //check if user with this email already in system T_OE_USERS t = db_Accounts.GetT_VCCB_USERByEmail(_identity.Name); if (t == null) { db_Ref.InsertT_OE_SYS_LOG("DEBUG", "No user with email exists - creating with ID=[" + _identity.Name + "]"); //insert new USERS table if not yet there UserIDX = db_Accounts.CreateT_OE_USERS(_identity.Name, "unused", "unused", "temp", "temp", _identity.Name, true, false, System.DateTime.Now, null, null, "portal"); db_Ref.InsertT_OE_SYS_LOG("DEBUG", "New User created IDX" + UserIDX); //Add user to GENERAL USER Role if (UserIDX > 0) { db_Accounts.CreateT_VCCB_USER_ROLE(3, UserIDX, "system"); } } else { //update existing user record UserIDX = t.USER_IDX; //switch "User.Identity.Name" to the username context.AuthenticationTicket.Identity.RemoveClaim(_identity.FindFirst("name")); Claim nameClaim = new Claim("name", t.USER_ID, ClaimValueTypes.String, "LocalAuthority"); context.AuthenticationTicket.Identity.AddClaim(nameClaim); } if (UserIDX > 0) { //now add UserIDX to claims Claim userIDXClaim = new Claim("UserIDX", UserIDX.ToString(), ClaimValueTypes.Integer, "LocalAuthority"); context.AuthenticationTicket.Identity.AddClaim(userIDXClaim); } else { throw new System.IdentityModel.Tokens.SecurityTokenValidationException(); } //delete all orgs for this user to Inactive db_WQX.DeleteT_WQX_USER_ORGS_AllByUserIDX(UserIDX); //now handling jurisdiction associations var authorizedOrgs = _identity.FindAll("open_waters"); foreach (var org in authorizedOrgs) { string[] org_array = org.Value.Split(';'); T_WQX_ORGANIZATION o = db_WQX.GetWQX_ORGANIZATION_ByID(org_array[0]); if (o != null) { db_WQX.InsertT_WQX_USER_ORGS(o.ORG_ID, UserIDX, org_array[1] == "True" ? "A" : "U"); //set their default OPEN WATERS ORG ID (assuming vast majority of users only have rights to 1 org) db_Accounts.UpdateT_OE_USERSDefaultOrg(UserIDX, o.ORG_ID); } } return(Task.FromResult(0)); } } }); app.UseStageMarker(PipelineStage.Authenticate); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //******************************************************************************* //************* Data Collection Metrics Panel *********************************** //******************************************************************************* lblOrg.Text = db_WQX.GetWQX_ORGANIZATION().Count().ToString(); int UserIDX = Utils.GetUserIDX(User); //post login stuff such as setting Default OrgID in session if (Session["UserIDX"].ConvertOrDefault <int>() == 0) { Utils.PostLoginUser(User.Identity.Name); } if (!string.IsNullOrEmpty(Session["OrgID"] as string)) { string orgID = Session["OrgID"].ToString(); pnlOrgSpecific.Visible = true; T_WQX_ORGANIZATION _org = db_WQX.GetWQX_ORGANIZATION_ByID(orgID); if (_org != null) { lblOrgName.Text = _org.ORG_FORMAL_NAME; } lblProject2.Text = db_WQX.GetWQX_PROJECT(true, orgID, false).Count.ToString(); lblSamp.Text = db_WQX.GetWQX_ACTIVITY(true, orgID, null, null, null, null, false, null).Count().ToString(); lblSampPend2.Text = db_WQX.GetWQX_ACTIVITY(true, orgID, null, null, null, null, true, null).Count().ToString(); lblResult.Text = db_WQX.GetT_WQX_RESULTCount(orgID).ToString(); } else { pnlOrgSpecific.Visible = false; } //**************************************************************************** //**************************************************************************** //**************Admin Tasks Panel *************************************** //**************************************************************************** if (HttpContext.Current.User.IsInRole("ADMINS") || db_WQX.CanUserAdminOrgs(UserIDX)) { pnlAdminTasks.Visible = true; DisplayPendingUsersGrid(); } //**************************************************************************** //**************Getting started wizard *************************************** //**************************************************************************** //STEP 1 *********************************** List <T_WQX_ORGANIZATION> o1s = db_WQX.GetWQX_USER_ORGS_ByUserIDX(UserIDX, false); if (o1s.Count == 0) { lblWiz1.Text = "To use Open Waters, you must first be linked with an Organization. This is the water monitoring agency you represent. If you intend to submit your data to EPA, this organization must first be created by EPA in their WQX system. Otherwise, if you never intend to submit your data to EPA, you can create any Organization ID you wish."; spnWiz1.Attributes["class"] = "signup_header_cross"; btnWiz1.Text = "Get Started"; spnWiz2.Attributes["class"] = "signup_header_crossbw"; btnWiz2.Visible = false; spnWiz3.Attributes["class"] = "signup_header_crossbw"; btnWiz3.Visible = false; btnWiz3b.Visible = false; spnWiz4.Attributes["class"] = "signup_header_crossbw"; btnWiz4.Visible = false; btnWiz4b.Visible = false; spnWiz5.Attributes["class"] = "signup_header_crossbw"; btnWiz5.Visible = false; spnWiz6.Attributes["class"] = "signup_header_crossbw"; btnWiz6.Visible = false; btnWiz6b.Visible = false; } else { List <T_WQX_ORGANIZATION> oNotPends = db_WQX.GetWQX_USER_ORGS_ByUserIDX(UserIDX, true); if (oNotPends.Count == 0) { //only organization user is associated with is pending btnWiz1.Visible = false; lblWiz1.Text = "Your request to view/submit data for an organization is pending. You must wait for an administrator to approve your request."; spnWiz1.Attributes["class"] = "signup_header_progress"; spnWiz2.Attributes["class"] = "signup_header_crossbw"; btnWiz2.Visible = false; spnWiz3.Attributes["class"] = "signup_header_crossbw"; btnWiz3.Visible = false; btnWiz3b.Visible = false; spnWiz4.Attributes["class"] = "signup_header_crossbw"; btnWiz4.Visible = false; btnWiz4b.Visible = false; spnWiz5.Attributes["class"] = "signup_header_crossbw"; btnWiz5.Visible = false; spnWiz6.Attributes["class"] = "signup_header_crossbw"; btnWiz6.Visible = false; btnWiz6b.Visible = false; } else { //STEP 1 IS COMPLETE, now try out tests 2-6 btnWiz1.Text = "View"; lblWiz1.Text = "Congrats! You are associated with an Organization. Click to view its details."; spnWiz1.Attributes["class"] = "signup_header_check"; //STEP 2: submit authorization ****************************************** foreach (T_WQX_ORGANIZATION oNotPend in oNotPends) { if (oNotPend.CDX_SUBMIT_IND == true) { spnWiz2.Attributes["class"] = "signup_header_check"; lblWiz2.Text = "Congrats! Your organization is authorized to submit to EPA-WQX."; btnWiz2.Text = "Change Credentials"; } else { spnWiz2.Attributes["class"] = "signup_header_cross"; lblWiz2.Text = "In order to submit data to EPA using Open Waters, you must contact EPA and request that they authorize Open Waters to submit data."; btnWiz2.Text = "Get Started"; } } //STEP 3:Mon Loc****************************************** bool MonLocOK = false; if (db_WQX.GetWQX_MONLOC_MyOrgCount(UserIDX) > 0) { lblWiz3.Text = "One or more monitoring locations have been created. Click to view."; spnWiz3.Attributes["class"] = "signup_header_check"; btnWiz3.Text = "View"; MonLocOK = true; } else { lblWiz3.Text = "Click to enter a monitoring location record."; spnWiz3.Attributes["class"] = "signup_header_cross"; } //STEP 4:Project ****************************************** bool ProjOK = false; if (db_WQX.GetWQX_PROJECT_MyOrgCount(UserIDX) > 0) { lblWiz4.Text = "One or more projects have been created. Click to view."; spnWiz4.Attributes["class"] = "signup_header_check"; btnWiz4.Text = "View"; ProjOK = true; } else { lblWiz4.Text = "Click to manually enter a project record or import records from a spreadsheet or EPA. "; spnWiz4.Attributes["class"] = "signup_header_cross"; } //STEP 5: Organization Starter Data ****************************************** if ((oNotPends[0].DEFAULT_TIMEZONE ?? "").Length > 0) { lblWiz5.Text = "Organization default data (e.g. Default Timezone) has been defined. Click to view."; spnWiz5.Attributes["class"] = "signup_header_check"; } else { lblWiz5.Text = "Click to enter default organization data (e.g. Default Timezone, characteristics) that will be helpful during activity data entry."; spnWiz5.Attributes["class"] = "signup_header_cross"; } //STEP 6: Activity ****************************************** if (ProjOK == true && MonLocOK == true) { if (db_WQX.GetWQX_ACTIVITY_MyOrgCount(UserIDX) > 0) { lblWiz6.Text = "One or more activities have been created. Click to view."; spnWiz6.Attributes["class"] = "signup_header_check"; btnWiz6.Text = "View"; } else { lblWiz6.Text = "Click to enter an activity record."; spnWiz6.Attributes["class"] = "signup_header_cross"; } } else { lblWiz6.Text = "You must enter a monitoring location and a project before you begin to create activities."; spnWiz6.Attributes["class"] = "signup_header_crossbw"; btnWiz6.Visible = false; } } } //**************End Getting started wizard ******************************* } }
protected void Page_Load(object sender, EventArgs e) { if (Session["OrgID"] == null) { Response.Redirect("~/App_Pages/Secure/WQXOrg.aspx"); } if (Request.QueryString["c"] == "1") { pnlCDX.CssClass = "fldErr row"; } //read session variables OrgEditID = Session["OrgID"].ToString(); if (!IsPostBack) { //display left menu as selected ContentPlaceHolder cp = this.Master.Master.FindControl("MainContent") as ContentPlaceHolder; HyperLink hl = (HyperLink)cp.FindControl("lnkOrgList"); if (hl != null) { hl.CssClass = "leftMnuBody sel"; } //populate drop-downs Utils.BindList(ddlTribalCode, dsRefData, "VALUE", "TEXT"); //******************* Populate organization information on form rbCDX.SelectedValue = "1"; T_WQX_ORGANIZATION o = db_WQX.GetWQX_ORGANIZATION_ByID(OrgEditID); if (o != null) { txtOrgID.Text = o.ORG_ID; txtOrgID.ReadOnly = true; txtOrgName.Text = o.ORG_FORMAL_NAME; txtOrgDesc.Text = o.ORG_DESC; ddlTribalCode.SelectedValue = o.TRIBAL_CODE; txtOrgEmail.Text = o.ELECTRONICADDRESS; txtOrgPhone.Text = o.TELEPHONE_NUM; txtOrgPhoneExt.Text = o.TELEPHONE_EXT; txtMailingAddress.Text = o.MAILING_ADDRESS; txtMailCity.Text = o.MAILING_ADD_CITY; txtMailState.Text = o.MAILING_ADD_STATE; txtMailZIP.Text = o.MAILING_ADD_ZIP; //CDX submission information*************************************8 if (o.CDX_SUBMIT_IND == true) { lblCDXSubmitInd.CssClass = "fldPass"; lblCDXSubmitInd.Text = "This Organization is able to submit to EPA."; } else { lblCDXSubmitInd.CssClass = "fldErr"; lblCDXSubmitInd.Text = "This Organization is unable to submit to EPA. Please correct this below."; } txtCDX.Text = o.CDX_SUBMITTER_ID; txtCDXPwd.Text = "--------"; txtCDXPwd.Attributes["value"] = "--------"; if ((o.CDX_SUBMITTER_ID ?? "").Length > 0) { rbCDX.SelectedValue = "1"; } else { rbCDX.SelectedValue = "2"; } } //populate listbox with users already in organization foreach (UserOrgDisplay u in db_WQX.GetT_OE_USERSInOrganization(txtOrgID.Text)) { ListItem li = new ListItem(u.USER_ID.ToString() + (u.ROLE_CD == "A" ? "(Admin)" : "(User)"), u.USER_IDX.ToString()); lbUserInRole.Items.Add(li); } //populate listbox with users not in role foreach (T_OE_USERS u in db_WQX.GetT_OE_USERSNotInOrganization(txtOrgID.Text)) { ListItem li = new ListItem(u.USER_ID.ToString(), u.USER_IDX.ToString()); lbAllUsers.Items.Add(li); } //only make visible if editing existing organization pnlRoles.Visible = (OrgEditID != "-1"); } }
protected void btnConfirm_Click(object sender, EventArgs e) { string OrgID = txtOrgIDConfirm.Text; var emailTo = new List <string>(); //check to see if selected organization is already in Open Waters T_WQX_ORGANIZATION org = db_WQX.GetWQX_ORGANIZATION_ByID(OrgID); if (org == null) { //*************************************************************************** //*************** CASE 1: CREATE NEW ORG //*************************************************************************** T_EPA_ORGS eo = db_WQX.GetT_EPA_ORGS_ByOrgID(OrgID); if (eo != null) { int SuccID = db_WQX.InsertOrUpdateT_WQX_ORGANIZATION(eo.ORG_ID, eo.ORG_FORMAL_NAME, null, null, "", null, "", null, null, null, null, false, null, User.Identity.Name); if (SuccID == 0) { pnlNewOrgConfirm.Visible = false; lblMsg.Text = "This request cannot be completed."; return; } } else { pnlNewOrgConfirm.Visible = false; lblMsg.Text = "This request cannot be completed - Org not found"; return; } List <T_OE_USERS> admins = db_Accounts.GetT_OE_USERSInRole(2); foreach (T_OE_USERS admin in admins) { emailTo.Add(admin.EMAIL); } } else { //*************************************************************************** //*************** CASE 2: ORG ALREADY IN OPEN WATERS //*************************************************************************** //now check to see if there are any Admins for this organization List <T_OE_USERS> uorgs = db_WQX.GetWQX_USER_ORGS_AdminsByOrg(OrgID); if (uorgs.Count > 0) { foreach (T_OE_USERS uorg in uorgs) { emailTo.Add(uorg.EMAIL); } } else { List <T_OE_USERS> admins = db_Accounts.GetT_OE_USERSInRole(2); foreach (T_OE_USERS admin in admins) { emailTo.Add(admin.EMAIL); } } } //Org is now in Open Waters, so user added to Org with pending status db_WQX.InsertT_WQX_USER_ORGS(OrgID, Utils.GetUserIDX(User), "P", User.Identity.Name); //send email with request string msg = "A user has requested to join an organization for which you are an administrator (or you are a global admin)." + "\r\n\r\n"; msg += "The following user account (" + User.Identity.Name + ") has requested to join your organization (" + OrgID + "). Please log into Open Waters and either accept or reject this request." + "\r\n\r\n"; bool eMailSucc = Utils.SendEmail(null, emailTo, null, null, "Open Waters: User Requesting to Join Organization", msg, null); pnlNewOrgConfirm.Visible = false; lblMsg.Text = "Your request has been made. You will be emailed when your request has been approved."; }