Esempio n. 1
0
        public ActionResult SetPwd(FormCollection fc)
        {
            string oldPwd        = fc["txtOldPwd"];
            string newPwd        = fc["txtNewPwd"];
            string newConfirmPwd = fc["txtConfirmNewPwd"];

            if (string.IsNullOrEmpty(oldPwd))
            {
                ModelState.AddModelError("OldPwdEmpty", "原密码不能为空");
                return(View());
            }
            if (string.IsNullOrEmpty(newPwd))
            {
                ModelState.AddModelError("NewPwdEmpty", "新密码不能为空");
                return(View());
            }
            if (newPwd != newConfirmPwd)
            {
                ModelState.AddModelError("NewPwdNotMatch", "两次输入的新密码不匹配");
                return(View());
            }
            var userInfo      = OrderAdminService.Get(OrdersAdminContext.Current.UserName);
            var oldEncrptyPwd = Controleng.Common.Utils.MD5(oldPwd);

            if (oldEncrptyPwd != userInfo.UserPwd)
            {
                ModelState.AddModelError("OldPwdNotMatch", "旧密码有误,请重试");
                return(View());
            }
            OrderAdminService.SetPwd(userInfo.Id, newConfirmPwd);

            ModelState.AddModelError("Success", "修改成功");
            return(View());
        }
Esempio n. 2
0
        public ActionResult Login(FormCollection fc)
        {
            bool   error    = false;
            string userName = fc["txtUserName"];
            string userPwd  = fc["txtUserPwd"];

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(userPwd))
            {
                error = true;
                ModelState.AddModelError("UserNameOrUserPwdEmpty", "用户名或密码不能为空!");
            }
            if (!error && ModelState.IsValid)
            {
                //判断用户是否存在
                //判断密码是否正确
                if (!OrderAdminService.IsExistsUserName(userName))
                {
                    ModelState.AddModelError("UserNameNotExists", "用户名不存在,请重试!");
                }
                else if (!OrderAdminService.ValidateForLogin(userName, userPwd))
                {
                    ModelState.AddModelError("UserPwdError", "密码错误,请重试!");
                }
                else
                {
                    //正确
                    var    userInfo     = OrderAdminService.Get(userName);
                    string _cookieValue = string.Format("{0}#{1}", userInfo.UserName, userInfo.RoleType);
                    //MD5加密
                    _cookieValue = Goodspeed.Library.Security.DESCryptography.Encrypt(_cookieValue, System.Configuration.ConfigurationManager.AppSettings["DESKey"]);
                    //Write cookie
                    Controleng.Common.Utils.WriteCookie(OrdersAdminContext.LOGINCOOKIEKEY, _cookieValue, COOKIEEXPIRETIME);
                    Response.Redirect("/");
                }
            }
            return(View());
        }