namespace TTWebCSVS
{
	using System.Web.Security;
	using System;
	using ASPNET.StarterKit.TimeTracker.BusinessLogicLayer;

	/// <summary>
	///		Summary description for SignIn.
	/// </summary>
	public abstract class SignIn : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.TextBox email;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.TextBox password;
		protected System.Web.UI.WebControls.CheckBox RememberCheckbox;
		protected System.Web.UI.WebControls.Button Btnsignin;
		protected System.Web.UI.WebControls.Button register;
		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.
		/// </summary>
		private void InitializeComponent()
		{
			this.Btnsignin.Click += new System.EventHandler(this.Btnsignin_Click);
			this.register.Click += new System.EventHandler(this.register_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void register_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("Register.aspx", false);
		}
		
		private void Btnsignin_Click(object sender, System.EventArgs e)
		{
			// Attempt to Validate User Credentials using UsersDB
			TTUser accountSystem = new TTUser();
			string userId = accountSystem.Login(email.Text, TTSecurity.Encrypt(password.Text));

			if (userId != "" && userId != string.Empty)
			{
				// Use security system to set the UserID within a client-side Cookie
				FormsAuthentication.SetAuthCookie(email.Text, RememberCheckbox.Checked);
				// Redirect browser back to originating page
				FormsAuthentication.RedirectFromLoginPage(email.Text, false);
			}
			else
				Message.Text = "<" + "br" + ">µÇÂ½Ê§°Ü£¡" + "<" + "br" + ">";
		}
	}
}
