public ActionResult Login(string account, string pwd)
        {
            var model = new BaseReturnModel()
            {
                IsSuccess = false,
                ReturnMsg = "用户名或密码有误"
            };

            try
            {
                var entity = _adminUserInfoService.GetByUserName(account);
                if (entity != null)
                {
                    if (entity.Password.Equals(EncryptHelper.Md5(pwd, entity.PwdSalt)))
                    {
                        _currentWebContext.SetLogin(entity, true);
                        model.IsSuccess = true;
                        model.ReturnMsg = "成功登录";
                    }
                }
            }
            catch (Exception ex)
            {
                model.IsSuccess = false;
                model.ReturnMsg = ex.Message;
            }

            return(Json(model));
        }
示例#2
0
        private AdminUserInfoModel GetAdminUserInfo()
        {
            if (HttpContext.Current == null)
            {
                return(null);
            }

            var cookie = HttpContext.Current.Request.Cookies[_cookieIdStr];

            if (cookie == null || string.IsNullOrEmpty(cookie.Value))
            {
                return(null);
            }
            FormsAuthenticationTicket ticket = null;

            try
            {
                ticket = FormsAuthentication.Decrypt(cookie.Value);
                if (ticket.Expired)
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }

            if (ticket == null)
            {
                return(null);
            }

            var userName = ticket.UserData;

            if (string.IsNullOrWhiteSpace(userName))
            {
                return(null);
            }

            if (_loginAdminUser != null && _loginAdminUser.UserName.ToLower().Equals(userName.ToLower()))
            {
                return(_loginAdminUser);
            }

            return(_adminUserInfoService.GetByUserName(userName));
        }