Exemplo n.º 1
0
        public ActionResult Index(IndexViewModel Model, string returnUrl)
        {
            AdminManage vAdminManage = new AdminManage();
            AdminUserEF vAdminInfo   = vAdminManage.Login(Model.UserName, Model.Password);

            if (vAdminInfo.ID > 0)
            {
                /////////////////////////////////////////////////////////////////Form验证////////////////////////////////////
                Session["UserInfo"] = vAdminInfo;
                FormsAuthentication.RedirectFromLoginPage(vAdminInfo.UserName, false);
                FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, vAdminInfo.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, "Admin", "/");
                string     HashTicket            = FormsAuthentication.Encrypt(Ticket);
                HttpCookie UserCookie            = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);
                HttpContext.Response.Cookies.Add(UserCookie);
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                if (returnUrl != "" && returnUrl != null)
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Main", "Admin"));
                }
            }
            else
            {
                ModelState.AddModelError("", "用户名或密码错误");
                return(View());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Admin admin = new Admin();

            admin.A_AdminPassWord1 = this.txtPassWord.Text.Trim();
            admin.A_AdminUserName1 = this.txtUserName.Text.Trim();
            bool result = adminmanage.Login(admin);

            if (result)
            {
                FrmMain main = new FrmMain();
                main.Show();
                this.Hide();
                return;
            }
            MessageBox.Show("用户名或密码错误", "登录", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Exemplo n.º 3
0
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     if (UserName.Text == string.Empty)
     {
         Response.Write("<script>alert('名称不能为空!')</script>");
         return;
     }
     else
     {
         DataSet adminds  = null;
         DataSet readerds = null;
         adminmanage.Name = UserName.Text;
         adminmanage.Pwd  = Password.Text;
         adminds          = adminmanage.Login(adminmanage);
         usermanage.ID    = Password.Text;
         usermanage.Name  = UserName.Text;
         readerds         = usermanage.UserLogin(usermanage);
         if (adminds.Tables[0].Rows.Count > 0 && txtCode.Text == Request.Cookies["CheckCode"].Value)
         {
             Session["role"] = "Admin";
             Session["Name"] = UserName.Text;
             Response.Redirect("Default.aspx");
         }
         else if (readerds.Tables[0].Rows.Count > 0 && txtCode.Text == Request.Cookies["CheckCode"].Value)
         {
             Session["Name"]   = UserName.Text;
             Session["readid"] = Password.Text;
             Session["role"]   = "User";
             Response.Redirect("Default.aspx");
         }
         else
         {
             Response.Write("<script>alert('登录名或密码不正确!')</script>");
         }
     }
 }