protected void Page_Load(object sender, System.EventArgs e) { int profileID = -1, i; ProfileCollection profiles; ServingProfile servingProfile; ProfileMember pm; CheckBox cb; Literal lt; BasePage.AddJavascriptInclude(Page, BasePage.JQUERY_INCLUDE); // // Deal with redirects. // if (!Page.IsPostBack) { iRedirect.Value = string.Empty; if (Request.QueryString["requestpage"] != null) { iRedirect.Value = string.Format("default.aspx?page={0}", Request.QueryString["requestpage"]); } if (iRedirect.Value == string.Empty && Request.QueryString["requestUrl"] != null) { iRedirect.Value = Request.QueryString["requestUrl"]; } if (iRedirect.Value == string.Empty) { iRedirect.Value = string.Format("default.aspx?page={0}", RedirectPageIDSetting); } } // // Retrieve the profile ID we are going to work with. // if (ProfileIDSetting.Contains("|")) { profileID = Int32.Parse(ProfileIDSetting.Split('|')[1]); } else { profileID = Int32.Parse(ProfileIDSetting); } // // Walk all the child profiles (only one level deep, non-recursive) // and add them as check-boxes to the page. If the user is already // a member of one of the profiles then that box is checked and // disabled. // profiles = new Profile(profileID).ChildProfiles; for (i = 0; i < profiles.Count; i++) { // // Find the member in the profile if they are already there. // pm = new ProfileMember(profiles[i].ProfileID, ArenaContext.Current.Person); // // Create either a CheckBox or a Radio button depending on module // settings. // if (MaxAnswersSetting == 1) { cb = (CheckBox) new RadioButton(); ((RadioButton)cb).GroupName = "ProfileGroup" + profileID.ToString(); } else { cb = new CheckBox(); } // // Fill in all the control information and add it to the list. // cb.ID = profiles[i].ProfileID.ToString(); cb.Text = profiles[i].Title; cb.CssClass = "sjt_profile"; if (pm.ProfileID != -1) { cb.Enabled = false; cb.Checked = true; cb.CssClass += " sjt_disabled"; } phProfiles.Controls.Add(cb); // // If this is a serving profile then make sure it isn't full. // if (profiles[i].ProfileType == ProfileType.Serving) { servingProfile = new ServingProfile(profiles[i].ProfileID); if (servingProfile.VolunteersNeeded > 0 && servingProfile.ProfileActiveMemberCount >= servingProfile.VolunteersNeeded) { cb.Enabled = false; cb.Text += " (currently full)"; cb.CssClass += " sjt_full"; } } // // Add in a newline character. // lt = new Literal(); lt.Text = "<br />"; phProfiles.Controls.Add(lt); } // // Add in a "none of the above" option if requested. This does // not do anything on submit, but resolves any "I changed my mind // how do I get out" questions. // if (NoneAboveSetting != false) { // // Create either the checkbox or the radio button depending on // the module setting. // if (MaxAnswersSetting == 1) { cb = (CheckBox) new RadioButton(); ((RadioButton)cb).GroupName = "ProfileGroup" + profileID.ToString(); } else { cb = new CheckBox(); } // // Setup the information about the none of the above control. // cb.ID = "-1"; cb.Text = "None of the above"; phProfiles.Controls.Add(cb); // // Add in a newline character. // lt = new Literal(); lt.Text = "<br />"; phProfiles.Controls.Add(lt); } }
private void CreateAccount() { Arena.Security.Login login; string loginID; if (CustomLoginSetting == true) { // Ensure that login ID is unique loginID = tbLoginID.Text; login = new Arena.Security.Login(loginID); if (login.PersonID != -1) { int loginCount = 0; loginID = tbFirstName.Text.Substring(0, 1).ToLower() + tbLastName.Text.Trim().ToLower(); if (loginID != loginID.ToLower()) { login = new Arena.Security.Login(loginID); } while (login.PersonID != -1) { loginCount++; login = new Arena.Security.Login(loginID + loginCount.ToString()); } lblMessage.Text = "The Desired Login ID you selected is already in use in our system. Please select a different Login ID. Suggestion: <b>" + loginID + loginCount.ToString() + "</b>"; pnlMessage.Visible = true; lblMessage.Visible = true; return; } } else { Int32 loginCount = 0; // // Construct a login Id that can be used. // do { if (loginCount == 0) { loginID = tbFirstName.Text + " " + tbLastName.Text; } else { loginID = tbFirstName.Text + " " + tbLastName.Text + loginCount.ToString(); } loginID = loginID.ToLower(); login = new Arena.Security.Login(loginID); loginCount++; } while (login.PersonID != -1); } Lookup memberStatus; try { memberStatus = new Lookup(Int32.Parse(MemberStatusIDSetting)); if (memberStatus.LookupID == -1) { throw new ModuleException(CurrentPortalPage, CurrentModule, "Member Status setting must be a valid Member Status Lookup value."); } } catch (System.Exception ex) { throw new ModuleException(CurrentPortalPage, CurrentModule, "Member Status setting must be a valid Member Status Lookup value.", ex); } int organizationID = CurrentPortal.OrganizationID; string userID = CurrentUser.Identity.Name; if (userID == string.Empty) { userID = "NewAccount.ascx"; } Person person = new Person(); person.RecordStatus = RecordStatus.Pending; person.MemberStatus = memberStatus; if (CampusSetting != string.Empty) { try { person.Campus = new Arena.Organization.Campus(Int32.Parse(CampusSetting)); } catch { person.Campus = null; } } person.FirstName = tbFirstName.Text.Trim(); person.LastName = tbLastName.Text.Trim(); if (tbBirthDate.Text.Trim() != string.Empty) { try { person.BirthDate = DateTime.Parse(tbBirthDate.Text); } catch { } } if (ddlMaritalStatus.SelectedValue != string.Empty) { person.MaritalStatus = new Lookup(Int32.Parse(ddlMaritalStatus.SelectedValue)); } if (ddlGender.SelectedValue != string.Empty) { try { person.Gender = (Gender)Enum.Parse(typeof(Gender), ddlGender.SelectedValue); } catch { } } PersonAddress personAddress = new PersonAddress(); personAddress.Address = new Address( tbStreetAddress.Text.Trim(), string.Empty, tbCity.Text.Trim(), ddlState.SelectedValue, tbZipCode.Text.Trim(), false); personAddress.AddressType = new Lookup(SystemLookup.AddressType_Home); personAddress.Primary = true; person.Addresses.Add(personAddress); PersonPhone phone = new PersonPhone(); phone.Number = tbHomePhone.PhoneNumber.Trim(); phone.PhoneType = new Lookup(SystemLookup.PhoneType_Home); person.Phones.Add(phone); if (tbWorkPhone.PhoneNumber.Trim() != string.Empty) { phone = new PersonPhone(); phone.Number = tbWorkPhone.PhoneNumber.Trim(); phone.Extension = tbWorkPhone.Extension; phone.PhoneType = new Lookup(SystemLookup.PhoneType_Business); person.Phones.Add(phone); } if (tbCellPhone.PhoneNumber.Trim() != string.Empty) { phone = new PersonPhone(); phone.Number = tbCellPhone.PhoneNumber.Trim(); phone.PhoneType = new Lookup(SystemLookup.PhoneType_Cell); phone.SMSEnabled = cbSMS.Checked; person.Phones.Add(phone); } if (tbEmail.Text.Trim() != string.Empty) { PersonEmail personEmail = new PersonEmail(); personEmail.Active = true; personEmail.Email = tbEmail.Text.Trim(); person.Emails.Add(personEmail); } person.Save(organizationID, userID, false); person.SaveAddresses(organizationID, userID); person.SavePhones(organizationID, userID); person.SaveEmails(organizationID, userID); Family family = new Family(); family.OrganizationID = organizationID; family.FamilyName = tbLastName.Text.Trim() + " Family"; family.Save(userID); FamilyMember fm = new FamilyMember(family.FamilyID, person.PersonID); fm.FamilyID = family.FamilyID; fm.FamilyRole = new Lookup(SystemLookup.FamilyRole_Adult); fm.Save(userID); Arena.Security.Login personLogin = new Arena.Security.Login(); personLogin.PersonID = person.PersonID; personLogin.LoginID = loginID; personLogin.Password = tbPassword.Text.Trim(); personLogin.Active = true; personLogin.Save(userID); // Use security system to set the UserID within a client-side Cookie FormsAuthentication.SetAuthCookie(personLogin.LoginID, false); Response.Cookies["portalroles"].Value = string.Empty; if (ProfileIDSetting != string.Empty) { int profileID = -1; int sourceLUID = -1; int statusLUID = -1; try { if (ProfileIDSetting.Contains("|")) { profileID = Int32.Parse(ProfileIDSetting.Split('|')[1]); } else { profileID = Int32.Parse(ProfileIDSetting); } sourceLUID = Int32.Parse(SourceLUIDSetting); statusLUID = Int32.Parse(StatusLUIDSetting); } catch (System.Exception ex) { throw new ModuleException(CurrentPortalPage, CurrentModule, "If using a ProfileID setting for the NewAccount module, " + "then a valid numeric 'ProfileID', 'SourceLUID', and 'StatusLUID' setting must all be used!", ex); } Profile profile = new Profile(profileID); Lookup sourceLu = new Lookup(sourceLUID); Lookup statusLu = new Lookup(statusLUID); if (profile.ProfileID != -1 && sourceLu.LookupID != -1 && statusLu.LookupID != -1) { ProfileMember profileMember = new ProfileMember(); profileMember.ProfileID = profile.ProfileID; profileMember.PersonID = person.PersonID; profileMember.Source = sourceLu; profileMember.Status = statusLu; profileMember.DatePending = DateTime.Now; profileMember.Save(userID); if (profile.ProfileType == ProfileType.Serving) { ServingProfile sProfile = new ServingProfile(profile.ProfileID); ServingProfileMember sMember = new ServingProfileMember(profileMember.ProfileID, profileMember.PersonID); sMember.HoursPerWeek = sProfile.DefaultHoursPerWeek; sMember.Save(); } } else { throw new ModuleException(CurrentPortalPage, CurrentModule, "'ProfileID', 'SourceLUID', and 'StatusLUID' must all be valid IDs"); } } // // If we are letting the user pick their own login ID then just redirect // the browser back to the originating page. Otherwise put up some text to // tell the user what their new login ID is. // if (CustomLoginSetting == true) { Response.Redirect(iRedirect.Value); } else { pnlCreateAccount.Visible = false; lbLoginCreated.Text = "Your account has been created. Your login ID is \"" + loginID + "\".<BR /><BR />You may use this login ID the next time you visit this site.<BR />"; pnlLoginCreated.Visible = true; } }