protected void Page_Load(object sender, EventArgs e)
        {
            //var un = string.Empty;

            if (!string.IsNullOrEmpty(Request.QueryString["un"]))
            {
                un = Request.QueryString["un"];
            }
            else
            {
                un = "*****@*****.**";
            }



            ////litRoles.Text = MembershipManager.isOpenToConnect(un).ToString();
            var membershipManager = new MembershipManager();
            //var sb = new StringBuilder();
            //var output = @"Method: {0}:{1}</br>";
            var member = membershipManager.GetMember(un);
            //var memberId = member.MemberId;

            //sb.Append(string.Format(output, "membershipManager.GetMemberByScreenName(un).Email", membershipManager.GetMemberByScreenName(un).Email));
            //sb.Append(string.Format(output, "membershipManager.GetMember(memberId).Email", membershipManager.GetMember(memberId).Email));
            //sb.Append(string.Format(output, "membershipManager.GetMember('[email protected]').Email", membershipManager.GetMember("[email protected]").Email));
            ////sb.Append(string.Format(output, "membershipManager.GetMember('[email protected]').Email", membershipManager.GetMembers().FirstOrDefault(x => x.Email == "[email protected]").Email));
            //sb.Append(string.Format(output, "membershipManager.GetMembers().FirstOrDefault(x => x.MemberId == memberId).Email", membershipManager.GetMembers().FirstOrDefault(x => x.MemberId == memberId).Email));
            //sb.Append(string.Format(output, "membershipManager.GetUser(memberId).Email", membershipManager.GetUser(memberId).Email));

            //litRoles.Text = sb.ToString();
            litEmail.Text = member.Email;
        }
        protected void btnGo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtEmail.Text))
            {
                var membershipManager = new MembershipManager();
                var member = membershipManager.GetMember(un);

                var success = membershipManager.UpdateEmail(member, txtEmail.Text);

                Response.Write(success.ToString());
            }
        }
        private void doLogin()
        {

            //blow out any existing member when someone tries to sign in
            try
            {
                //Reset session backed my groups from Whats Happening Now
                Session["_selectedGroups"] = null;
               
                //lets make sure to reset all user&member info before we start inflating it
                this.FlushCurrentMemberUser();

                var membershipManager = new MembershipManager();

                var currentMember = new Member();

                if (!string.IsNullOrEmpty(AccessToken))
                {
                    var client = new Facebook.FacebookClient(AccessToken);
                    dynamic me = client.Get("me", new { fields = "email" });

                    currentMember = membershipManager.GetMember(me.email);
                }
                else
                {
                    currentMember = membershipManager.AuthenticateUser(uxEmailAddress.Text, uxPassword.Text);
                }

                if (currentMember != null)
                {
                    this.CurrentMember = currentMember;
                    this.CurrentUser = membershipManager.GetUser(currentMember.MemberId, true);

                    this.ProfileRedirect(Constants.UserPermission.AgreedToTerms, null, true);

                    //Redirect used here for profile??
                    this.ReturnRedirect();

                    var item = Sitecore.Context.Database.GetItem(Constants.Pages.MyAccount);
                    // if you get this far, clear the redirect session URL 

                    Response.Redirect(Sitecore.Links.LinkManager.GetItemUrl(item));
                }
            }
            catch (Exception ex)
            {
                uxError.Text = ex.Message;
            }
        }
        void btnSubmit_Click(object sender, EventArgs e)
        {
            pnlResults.Update();

            MembershipManager mm = new MembershipManager();
            if (!string.IsNullOrEmpty(txtEmail.Text))
            {
                var member = mm.GetMember(txtEmail.Text);
                if (member != null)
                {
                    bool hasChildren = member.Children.Any();
                    pnlChildren.Visible = hasChildren;

                    if (hasChildren)
                    {
                        ddlChildren.DataSource = member.Children;
                        ddlChildren.DataTextField = "Nickname";
                        ddlChildren.DataValueField = "ChildId";
                        ddlChildren.DataBind();
                    }

                    if (member.Interests.Any())
                    {
                        rptInterests.DataSource = member.Interests;
                        rptInterests.DataBind();
                    }
                }
            }
        }
        private void Page_Load(object sender, EventArgs e)
        {
            if (this.CurrentMember == null && this.CurrentUser == null)
            {
                if (!string.IsNullOrEmpty(CurrentPage.SignInPage.Url))
                {
                    Response.Redirect(CurrentPage.SignInPage.Url);
                }
                else
                {
                    Response.Redirect("/");
                }
            }

            if (!IsPostBack)
            {
                //update member
                MembershipManager membershipManager = new MembershipManager();
                this.CurrentMember = membershipManager.GetMember(this.CurrentMember.MemberId);
                this.CurrentUser = membershipManager.GetUser(this.CurrentMember.MemberId, true);

                MyProfileItem context = (MyProfileItem)Sitecore.Context.Item;
                HyperLink myHL = (HyperLink)this.FindControl("uxAddChild");
                myHL.Text = context.AddChildText;

                SetLabels();
                SetRole();

                uxChildList.DataSource = this.CurrentMember.Children;
                uxChildList.DataBind();

                //disable new children if you already have 6 or more
                if (this.CurrentMember.Children.Count >= 6)
                {
                    uxAddChild.Visible = false;
                }

                SetInterests();

                uxEmailAddress.Text = txtEmail.Text = this.CurrentUser.UserName;


                SetJourney();

                uxPassword.Text = replacePassword("digitalpulp!");

                string phoneNumber = string.Empty;

                if (!string.IsNullOrEmpty(this.CurrentMember.MobilePhoneNumber))
                {
                    phoneNumber = this.CurrentMember.MobilePhoneNumber.Replace("-", string.Empty).Trim();

                    //if (phoneNumber.Length == 10 && !phoneNumber.Contains("-"))
                    //{
                    phoneNumber = phoneNumber.Insert(3, "-");
                    phoneNumber = phoneNumber.Insert(7, "-");
                    //}
                }
                else
                {
                    //10 points to Gryffindor if you know where this phone number comes from
                    txtPhoneNumber.Attributes["placeholder"] = "212-555-2368";
                }

                uxPhoneNumber.Text = phoneNumber;
                txtPhoneNumber.Text = phoneNumber;

                uxPrivacyLevel.Text = this.CurrentMember.allowConnections ? DictionaryConstants.OpenToConnect : DictionaryConstants.NotOpenToConnect;

                uxScreenname.Text = this.CurrentMember.ScreenName;

                uxZipcode.Text = this.CurrentMember.ZipCode.Trim();

                uxAddChild.Text = string.Format(uxAddChild.Text, ((ChildCount)this.CurrentMember.Children.Count).ToString());
                uxAddChild.NavigateUrl = MyProfileStepTwoItem.GetCompleteMyProfileStepTwo().GetUrl() + "?" + Constants.QueryStrings.Registration.Mode + "=" + Constants.QueryStrings.Registration.ModeAdd;

                if (Session["PostReloadScript"] != null)
                {
                    string reloadScript = Session["PostReloadScript"].ToString();

                    if (reloadScript != "")
                    {
                        ltlJS.Text = string.Format("<script type=\"text/javascript\">{0}</script>", reloadScript);
                        Session["PostReloadScript"] = null;
                    }
                }

                //top of edit interests
                hypEditCommunityAboutMe.NavigateUrl = String.Format(MyProfileStepFourItem.GetCompleteMyProfileStepFour().GetUrl() + "?{0}={1}", Constants.QueryStrings.Registration.Mode, Constants.QueryStrings.Registration.ModeEdit);

                //jump to edit community
                hypEditCommunity.NavigateUrl = hypCompleteYourProfile.NavigateUrl = String.Format(MyProfileStepFourItem.GetCompleteMyProfileStepFour().GetUrl() + "?{0}={1}#community", Constants.QueryStrings.Registration.Mode, Constants.QueryStrings.Registration.ModeEdit);

                if (!string.IsNullOrEmpty(this.CurrentMember.ScreenName))
                {
                    hypViewAsVisitors.NavigateUrl = MembershipHelper.GetPublicProfileAsVisitorUrl(CurrentMember.ScreenName);
                    hypViewAsMembers.NavigateUrl = MembershipHelper.GetPublicProfileAsMemberUrl(CurrentMember.ScreenName);
                    hypViewAsFriends.NavigateUrl = MembershipHelper.GetPublicProfileUrl(CurrentMember.ScreenName);
                }
                else
                {
                    uxNoProfile.Visible = true;
                    uxPublicView.Visible = false;
                }
            }
        }
        protected void lbSaveEmailPassword_Click(object sender, EventArgs e)
        {
            var action = false;

            try
            {
                if (!string.IsNullOrEmpty(this.txtEmail.Text))
                {
                    if (Regex.IsMatch(this.txtEmail.Text, Constants.Validators.Email))
                    {
                        //matched regex
                        if (this.UpdateEmail())
                        {
                            action = true;
                            
                            var membershipManager = new MembershipManager();

                            this.CurrentMember = membershipManager.GetMember(this.CurrentMember.MemberId);
                            this.CurrentUser = membershipManager.GetUser(this.CurrentMember.MemberId, true);
                        }
                        else
                        {
                            throw new Exception(DictionaryConstants.SomethingFailedError);
                        }
                    }
                    else
                    {
                        //did not match regex and not empty
                        throw new Exception(DictionaryConstants.PasswordErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                litEmailPasswordError.Text += ex.Message;
            }

            try
            {

                if (!string.IsNullOrEmpty(this.txtOldPassword.Text) && !string.IsNullOrEmpty(this.txtNewPassword.Text) && !string.IsNullOrEmpty(this.txtConfirmNewPassword.Text))
                {
                    if (this.txtNewPassword.Text == this.txtConfirmNewPassword.Text 
                        && Regex.IsMatch(this.txtNewPassword.Text, Constants.Validators.Password) 
                        && Regex.IsMatch(this.txtOldPassword.Text, Constants.Validators.Password))
                    {
                        if (this.UpdatePassword())
                        {
                            action = true;
                        }
                        else
                        {
                            throw new Exception(DictionaryConstants.SomethingFailedError);
                        }
                    }
                    else
                    {
                        //new passwords don't match
                        throw new Exception(DictionaryConstants.PasswordMatchError);
                    }
                }
            }
            catch (Exception ex)
            {
                litEmailPasswordError.Text += ex.Message;
            }


            if (action)
            {
                Response.Redirect(Request.RawUrl, true);
            }
        }
        private static int PercentProfileComplete(Guid MemberId)
        {
            int profileCompleteness = 0;
            MembershipManager mmgr = new MembershipManager();
            mmgr.GetMember(MemberId);
            Member m = mmgr.GetMember(MemberId);
                   
            /*
            
             * Show 0%, if the user has only given us their email. 
             * Show 25%, if the user has entered at least one child. 
             * Show 50%, if the user has a community name. 
             * Show 75%, if the user has entered at least one parent interest. 
             * Show 100%, if the user has completed their full profile.
        
             */

            //just so something is here until we get the rules nailed down 
            //I'm making these rules cumulative, as a score, so we don't 
            //end up with someone who has nothing but a parental interest come back at 75%
            if (m.Children.Count > 0)
            {
                profileCompleteness += 25;
            }
            if(!string.IsNullOrEmpty(m.ScreenName))
            {
                profileCompleteness += 25;
            }
            if (m.Interests.Count > 0)
            {
                profileCompleteness += 25;            
            }
            //not sure what next to add in. What means "complete"? 
            //- maybe if their score is 75, then check to see if they have also updated IEP/504 status questions?
            return profileCompleteness;
          }