コード例 #1
0
        public ActionResult DoLogin(UserDetails u, String uIdentity)
        {
            if (ModelState.IsValid)
            {
                AuthenticationBusinessLayer bal = new AuthenticationBusinessLayer();
                UserStatus status  = bal.GetUserValidity(u, uIdentity);
                bool       IsAdmin = false;
                if (status == UserStatus.AuthenticatedAdmin)
                {
                    IsAdmin = true;
                }
                else if (status == UserStatus.AuthentucatedUser)
                {
                    IsAdmin = false;
                }
                else
                {
                    ModelState.AddModelError("CredentialError", "Invalid Username or Password");
                    return(View("Login"));
                }
                FormsAuthentication.SetAuthCookie(u.UserName, false);
                Session["IsAdmin"] = IsAdmin;
                if (IsAdmin == true)
                {
                    Admin admin = new Admin();
                    admin = bal.SearchAdmin(u.UserName);
                    Session["UserName"] = admin.Aname;
                    Session["UserID"]   = admin.AdminID;
                    return(RedirectToAction("Manager", "Administer"));
                }
                else
                {
                    User user = new User();
                    user = bal.SearchUser(u.UserName);
                    Session["UserName"]      = user.UName;
                    Session["UserID"]        = user.UserID;
                    Session["UserAuthority"] = user.UAuthority;
                    return(RedirectToAction("Index", "Index"));
                }



                //New Code End
            }
            else
            {
                return(View("Login"));
            }
        }
コード例 #2
0
        public ActionResult doRegister(User u)
        {
            AuthenticationBusinessLayer abl = new AuthenticationBusinessLayer();

            if (abl.SearchUser(u.UName) == null)
            {
                abl.SaveUser(u);
                UserDetails ud = new UserDetails();
                ud.UserName = u.UName;
                ud.Password = u.UPassword;

                return(DoLogin(ud, "User"));
            }
            else
            {
                return(Content("该用户名已存在!"));
            }
        }
コード例 #3
0
        public ActionResult ChangePassword(String btnSubmit, String NewPassword, User u)
        {
            AuthenticationBusinessLayer abl = new AuthenticationBusinessLayer();

            switch (btnSubmit)
            {
            case "提交":
                if (abl.GetUPhone(u.UName).Equals(u.UPhone))
                {
                    abl.SavePassword(u.UName, NewPassword);
                    return(RedirectToAction("Login"));
                }
                else
                {
                    return(Content("手机号验证失败!"));
                }

            case "取消":
                return(RedirectToAction("Login"));
            }
            return(new EmptyResult());
        }