    using ASPNET.StarterKit.TimeTracker.BusinessLogicLayer;
    using System.Configuration;
    using System.Web.Security;
    using System;

    namespace TTWebCSVS
    {
        ///
        /// Summary description for Register.
        ///
        public class Register : System.Web.UI.Page
        {
            protected System.Web.UI.WebControls.TextBox Email;
            protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
            protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
            protected System.Web.UI.WebControls.TextBox DisplayName;
            protected System.Web.UI.WebControls.TextBox Password;
            protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
            protected System.Web.UI.WebControls.TextBox ConfirmPassword;
            protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
            protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
            protected System.Web.UI.WebControls.LinkButton RegisterBtn;
            protected System.Web.UI.WebControls.Label Message;

            private void Page_Load(object sender, System.EventArgs e)
            {
                // Put user code to initialize the page here
            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                InitializeComponent();
                base.OnInit(e);
            }

            ///
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            ///
            private void InitializeComponent()
            {
                this.RegisterBtn.Click += new System.EventHandler(this.RegisterBtn_Click);
                this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void RegisterBtn_Click(object sender, System.EventArgs e)
            {
                // Only attempt a login if all form fields on the page are valid
                if (Page.IsValid)
                {
                    //Add New User to Portal User Database
                    TTUser accountSystem = new TTUser(0, Email.Text, TTSecurity.CleanStringRegex(DisplayName.Text), ConfigurationSettings.AppSettings["DefaultRoleForNewUser"]);
                    accountSystem.Password = TTSecurity.Encrypt(Password.Text);

                    if (accountSystem.Save())
                    {
                        // Set the user's authentication name to the userId
                        FormsAuthentication.SetAuthCookie(Email.Text, false);

                        // Redirect browser back to home page
                        Response.Redirect("TimeEntry.aspx");
                    }
                    else
                        Message.Text = "Registration Failed!  <" + "u" + ">" + Email.Text + "<" + "/u" + "> is already registered." + "<" + "br" + ">" + "Please register using a different email address.";
                }
            }
        }
    }