private void SignIn()
 {
     Arena.Security.Login login = new Arena.Security.Login(this.txtLoginId.Text);
     if (!(login.LoginID != string.Empty))
     {
         this.lblLoginMessage.Text = "The Login ID you entered does not exist in our system!  Please verify that your Login ID and Password have been entered correctly.";
         return;
     }
     if (login.AuthenticateInDatabase(this.txtPassword.Text.Trim()))
     {
         FormsAuthentication.SetAuthCookie(login.LoginID, false);
         base.Response.Cookies["portalroles"].Value = string.Empty;
         this.person = new Person(login.PersonID);
         this.SetInfo();
         this.tdLogin.Visible = false;
         return;
     }
     this.lblLoginMessage.Text = "The Password you entered does not match the correct password for this Login ID!  Please verify that your Login ID and Password have been entered correctly.";
 }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                if (Request["page"] != CurrentPortal.LoginPageID.ToString())
                {
                    signInPnl.Visible = true;
                    if ((String)LogInTextSetting != String.Empty)
                    {
                        LogInPageBtn.Text = (String)LogInTextSetting;
                    }
                    else
                    {
                        LogInPageBtn.Text = "Sign in with credentials";
                    }
                    LogInPageBtn.Visible = true;
                }
                else
                {
                    LogInPageBtn.Visible = false;
                }
                lcName.Visible = false;
            }
            else
            {
                String WelcomeText;
                if ((String)WelcomeTextSetting != String.Empty)
                {
                    WelcomeText = (String)WelcomeTextSetting;
                }
                else
                {
                    WelcomeText = "Welcome ##nickname## ##lastname##";
                }

                signInPnl.Visible    = false;
                LogInPageBtn.Visible = false;
                logOut.Visible       = true;
                lcName.Text          = WelcomeText
                                       .Replace("##nickname##", (string.IsNullOrEmpty(CurrentPerson.NickName) ? CurrentPerson.FirstName : CurrentPerson.NickName))
                                       .Replace("##lastname##", CurrentPerson.LastName);
                lcName.Visible = true;
            }

            if (!Page.IsPostBack)
            {
                Session["googleID"]      = string.Empty;
                Session["RedirectValue"] = string.Empty;
                if (Request["requestUrl"] != null)
                {
                    Session["RedirectValue"] = Request["requestUrl"];
                }

                if (Request.Form["sucessLogOut"] == "true") //this signes out the current user (for now)
                {
                    gSignOut();
                }

                if (Request.Form["idtoken"] != null && Request.Form["googleID"] != null) //if the user signes in via google
                {
                    if (Request.IsAuthenticated)                                         //if already lodded in
                    {
                        if (Session["RedirectValue"] != string.Empty)                    //if redirect paramater exists
                        //Response.Write((String)Session["RedirectValue"]);
                        {
                            Response.Write(Session["RedirectValue"]);
                            Response.End();
                        }
                        else  //prevents reload loop
                        {
                            Response.Write("1");
                            Response.End();
                        }
                    }
                    else
                    {
                        Session["googleID"] = googleValidation(Request.Form["idtoken"], Request.Form["googleID"]);
                        if (Session["googleID"] != "-1") //if validation returned a value

                        {
                            googleDataLayer arenaData = new googleDataLayer();

                            int personID;
                            personID = arenaData.getUserID((String)Session["googleID"]); //lookes up userID from googleID
                            if (personID < 0)
                            {
                                if (personID == -2)      //sql error
                                {
                                    Response.Write("1"); //returning 1 prevents loop
                                    Response.End();
                                }
                                else  //no user found

                                {
                                    String   personName = (String)Request.Form["name"];
                                    String[] splitName  = personName.Split(' ');
                                    String   fname      = splitName[0];
                                    String   lname      = splitName[1];
                                    String   email      = (String)Request.Form["email"];

                                    int memberStatus;
                                    int orgID = CurrentOrganization.OrganizationID;
                                    int campusID;

                                    try { memberStatus = Int32.Parse(MemberStatusSetting); }
                                    catch { throw new ModuleException(CurrentPortalPage, CurrentModule, "Default Member Status ID must be numeric.: "); }
                                    try { campusID = Int32.Parse(DefaultCampusSetting); }
                                    catch { throw new ModuleException(CurrentPortalPage, CurrentModule, "Default Campus ID must be numeric.: "); }

                                    //makes sure the names are in proper format
                                    if (fname == String.Empty)
                                    {
                                        fname = "";
                                    }
                                    if (lname == String.Empty)
                                    {
                                        lname = "";
                                    }

                                    //make a new person
                                    personID = arenaData.newUser(splitName[0], splitName[1], email, memberStatus, orgID, campusID);
                                    //add personID to google list
                                    if (personID > 0)
                                    {
                                        int asscociateGid = arenaData.SaveGoogleID(personID, (String)Session["googleID"]);
                                    }
                                }
                            }
                            if (personID == -1 || personID == -2)
                            {
                                Response.Write("something went wrong");
                                Response.End();
                            }
                            else  //match found

                            //sign in function
                            {
                                String username;
                                username = arenaData.getUserName(personID);
                                if (username == null || username == "-1" || username == "")
                                {
                                    //make a username
                                    username = arenaData.newUserName(personID, CurrentOrganization.OrganizationID);
                                }

                                if (username == "-2")
                                {
                                    Response.Write("1");
                                    Response.End();
                                }
                                else
                                {
                                    //sign in the user
                                    Arena.Security.Login login = new Arena.Security.Login(username);

                                    FormsAuthentication.SetAuthCookie(username, true);
                                    Response.Cookies["portalroles"].Value = string.Empty;
                                    Response.Redirect(Request.ApplicationPath);

                                    if (Session["RedirectValue"] != string.Empty)
                                    {
                                        //Response.Write(Session["RedirectValue"]);
                                        Response.Write("yeeee");
                                        Response.End();
                                    }
                                    else
                                    {
                                        Response.Write("yeee");
                                        //Response.Write(Request.ApplicationPath);
                                        Response.End();
                                    }
                                }
                            }
                        }
                        else
                        {
                            Response.Write("1");
                            Response.End();
                        }
                    }
                }
            }
        } //end page load
Esempio n. 3
0
        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;
            }
        }