⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.aspx.cs

📁 该项目管理系统可对项目的过程进行管理和控制
💻 CS
字号:
using System;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using BronzeMonkey.GeneralTaskList;

namespace BronzeMonkey.GeneralTaskList
{
	/// <summary>
	/// Summary description for login.
	/// </summary>
	public class login : System.Web.UI.Page
	{		
		private TaskList tl = new TaskList();
		private UserInformation CurrentUser = new UserInformation();

		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.TextBox txtUserName;
		protected System.Web.UI.WebControls.Label lblLoginInvalid;
		protected System.Web.UI.WebControls.CheckBox chkRememberMe;
		protected System.Web.UI.WebControls.Button btnLogIn;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
				SetInputFocus("txtUserName");
		}

		/// <summary>
		/// Sets up a javascript function to set focus to the user name box when the page loads
		/// </summary>
		private void SetInputFocus(string ControlName)
		{
			StringBuilder sb = new StringBuilder("");
			sb.Append("<script language=javascript>");
			sb.Append("function setFocus(ctl) {");
			sb.Append("  if (document.forms[0][ctl] != null)");
			sb.Append("  { document.forms[0][ctl].focus(); }");
			sb.Append("}");
			sb.Append("setFocus('" + ControlName + "');</script>");

			if (!IsStartupScriptRegistered("InputFocusHandler"))
				RegisterStartupScript("InputFocusHandler", sb.ToString());
		}

		#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);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnLogIn.Click += new System.EventHandler(this.btnLogIn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnLogIn_Click(object sender, System.EventArgs e)
		{
			// Initialize FormsAuthentication, for what it's worth
			FormsAuthentication.Initialize();

			CurrentUser.Username = Server.HtmlEncode(txtUserName.Text);
			CurrentUser.PasswordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(Server.HtmlEncode(txtPassword.Text), "md5");
			CurrentUser.UserID = tl.LogUserIn(CurrentUser.Username, CurrentUser.PasswordHash);
			CurrentUser = tl.GetUserItem(CurrentUser, CurrentUser.UserID);

			// Retrieve the count of the task lists this user is assigned to.
			// do not let them log in if they are not assigned to a task list
			int TaskListCount = 0;
			SqlDataReader dr = tl.GetUserTaskLists(CurrentUser, CurrentUser.UserID);
			while( dr.Read() )
			{
				if (dr["TaskListID"] != null) TaskListCount++;
			}
			dr.Close();

			if (CurrentUser.UserID == 0)
			{
				lblLoginInvalid.Visible = true;
				lblLoginInvalid.Text = "Invalid Username or Password";
			}
			else if (TaskListCount == 0)
			{
				lblLoginInvalid.Visible = true;
				lblLoginInvalid.Text = "User is not assigned to any Task Lists";
			}
			else
			{
				// and log the user in
				lblLoginInvalid.Visible = false;
				Session["CurrentUser"] = CurrentUser;

				FormsAuthentication.RedirectFromLoginPage(CurrentUser.Username, chkRememberMe.Checked, FormsAuthentication.FormsCookiePath);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -