Ejemplo n.º 1
0
        private void loadPage(object sender, EventArgs e)
        {
            lHeader.Text = "<h2>Get started with<b> Cheveux</b></h2>";

            #region Previous Page
            string PreviousPage = Request.QueryString["PreviousPage"];
            //set the create acount URL
            if (PreviousPage != null)
            {
                lCreateAccount.Text     = "<a href='../Authentication/NewAccount.aspx?Type=Email&PreviousPage=" + PreviousPage + "'>Create account</a>";
                lblDiferentAccount.Text = "<a href='../Authentication/Accounts.aspx?Type=All&PreviousPage=" + PreviousPage + "'>Use another account</a>";
            }
            else
            {
                lCreateAccount.Text     = "<a href='../Authentication/NewAccount.aspx?Type=Email'>Create account</a>";
                lblDiferentAccount.Text = "<a href='../Authentication/Accounts.aspx?Type=All'>Use another account</a>";
            }
            #endregion

            #region Logout/Reset/Change Pass
            //check if the user has requested a logout or login
            String action = Request.QueryString["action"];
            //login
            if (action == "Logout")
            {
                //log out
                //log the user out on googles servers
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "signOut()", true);
                //remove the 'reg' cookie
                cookie         = new HttpCookie("reg");
                cookie.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(cookie);
                //remove the 'CheveuxUserID' cookie
                cookie         = new HttpCookie("CheveuxUserID");
                cookie.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(cookie);
                //retun the usere to the home page
                Response.Redirect("../Default.aspx");
            }
            else if (action == "Reset")
            {
                lHeader.Text = "<h2><b> Cheveux</b></h2>";
                //check if the user has requested to reset thier passowrd or request a reset code
                code = Request.QueryString["code"];
                if (code == null)
                {
                    //Display the rest email Form
                    divEmailAcount.Visible     = false;
                    divAccountType.Visible     = false;
                    divGetRestCode.Visible     = true;
                    divGetEmailToReset.Visible = true;
                }
                else
                {
                    //Display the rest Pasword Form
                    string[] codeArray    = code.Split('|');
                    DateTime codeGenerate = DateTime.Now.AddYears(-10);
                    try
                    {
                        codeGenerate = Convert.ToDateTime(codeArray[0].ToString() + " " + codeArray[1].ToString());
                    }
                    catch (Exception err)
                    {
                        function.logAnError("Bad Pass word reset code: " + code + ". Error: " + err);
                        //if the code has expierd
                        //Display the rest email Form
                        lEamailResetError.Text     = "The Rest Request Has Expired, Try Again.";
                        lEamailResetError.Visible  = true;
                        divEmailAcount.Visible     = false;
                        divAccountType.Visible     = false;
                        divGetRestCode.Visible     = true;
                        divGetEmailToReset.Visible = true;
                    }
                    if (codeGenerate.AddMinutes(10) >= DateTime.Now)
                    {
                        //check if the account exist and the code is valid
                        restPassAccount = handler.GetAccountForRestCode(code);
                        if (restPassAccount != null)
                        {
                            divEmailAcount.Visible         = false;
                            divAccountType.Visible         = false;
                            divResetPasword.Visible        = true;
                            divResetPaswordtxtPass.Visible = true;
                            //get the user name and display it in the label
                            lPaswordResetUsernameLable.Text = restPassAccount.UserName.ToString();
                        }
                        else
                        {
                            //if the code has expierd
                            //Display the rest email Form
                            lEamailResetError.Text     = "The Rest Request Has Expired, Try Again.";
                            lEamailResetError.Visible  = true;
                            divEmailAcount.Visible     = false;
                            divAccountType.Visible     = false;
                            divGetRestCode.Visible     = true;
                            divGetEmailToReset.Visible = true;
                        }
                    }
                    else
                    {
                        //if the code has expierd
                        //Display the rest email Form
                        lEamailResetError.Text     = "The Rest Request Has Expired, Try Again.";
                        lEamailResetError.Visible  = true;
                        divEmailAcount.Visible     = false;
                        divAccountType.Visible     = false;
                        divGetRestCode.Visible     = true;
                        divGetEmailToReset.Visible = true;
                    }
                }
            }
            else if (action == "ChangePass")
            {
                lHeader.Text = "<h2> Change Password </h2>";
                try
                {
                    HttpCookie UserID = Request.Cookies["CheveuxUserID"];
                    divEmailAcount.Visible         = false;
                    divAccountType.Visible         = false;
                    divexistingPass.Visible        = true;
                    divResetPasword.Visible        = true;
                    divResetPaswordtxtPass.Visible = true;
                    //get the user name and display it in the label
                    lPaswordResetUsernameLable.Text = handler.GetUserDetails(UserID["ID"]).UserName.ToString();
                }
                catch (Exception)
                {
                    Response.Redirect("Accounts.aspx?PreviousPage=Profile.aspx");
                }
            }
            #endregion

            #region login Type Email
            //check if the user has requested to sign in with email
            string singInType = Request.QueryString["Type"];

            #region Remember Me
            string email = null;
            if (!Page.IsPostBack && singInType == null)
            {
                cookie = Request.Cookies["CheveuxRememberMe"];
                if (cookie != null)
                {
                    email      = cookie["EM"].ToString();
                    singInType = "Email";
                }
                else
                {
                    cbRememberMe.Checked = false;
                }
            }
            #endregion

            if (singInType == "Email")
            {
                //hide sign in with div and show sign in with email
                divAccountType.Visible = false;
                divEmailAcount.Visible = true;
                //check for any othe alerts
                string alert = Request.QueryString["Alert"];
                if (alert != null && alert != "")
                {
                    lError.Visible = true;
                    lError.Text    = alert;
                }
            }

            #region Remember Me
            if (email != null)
            {
                txtEmailUsername.Text = email;
                cbRememberMe.Checked  = true;
                displayPassword(sender, e);
            }
            #endregion
            #endregion
        }