Beispiel #1
0
        public ResponseItem Put(yy_User value)
        {
            var _Operator = DB.yy_User.Find(value.ID);

            if (_Operator != null)
            {
                if (!_Operator.UserPwd.Equals(value.UserPwd))
                {
                    value.UserPwd     = MD5(value.UserPwd);
                    _Operator.UserPwd = value.UserPwd;
                }
                _Operator.Address    = value.Address;
                _Operator.CityID     = value.CityID;
                _Operator.CountryID  = value.CountryID;
                _Operator.CreateDate = value.CreateDate;
                _Operator.DistrictID = value.DistrictID;
                _Operator.Gender     = value.Gender;
                _Operator.LockFlag   = value.LockFlag;
                _Operator.Mail       = value.Mail;
                _Operator.Mobile     = value.Mobile;
                _Operator.Permission = value.Permission;
                _Operator.ProvinceID = value.ProvinceID;
                _Operator.Role       = value.Role;
                _Operator.HeadImgUrl = value.HeadImgUrl;
                DB.SaveChanges();
                return(new ResponseItem(0, ""));
            }
            return(new ResponseItem(1, "不存在的用户。"));
        }
Beispiel #2
0
        public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            #region 如果无需权限验证直接跳过

            if (actionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>().Count > 0)
            {
                base.OnActionExecuting(actionContext);

                return;
            }

            #endregion 如果无需权限验证直接跳过

            String UserStr = String.Empty;

            try
            {
                var cookies = actionContext.Request.Headers.GetCookies().FirstOrDefault().Cookies;

                if (cookies != null)
                {
                    var UserCK = cookies.Where(p => p.Name == Const.SessionId).FirstOrDefault();
                    if (UserCK != null && !String.IsNullOrEmpty(UserCK.Value))
                    {
                        try
                        {
                            _User = JsonConvert.DeserializeObject <yy_User>(
                                HttpUtility.UrlDecode(UserCK.Value)
                                );
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("OnActionExecuting:" + ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("OnActionExecuting:" + ex.Message);
            }

            if (User == null)
            {
                actionContext.Response = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    Content = new StringContent("无效的用户",
                                                Encoding.UTF8,
                                                "application/json")
                };

                return;
            }

            //String ActionPath = "/" + actionContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower() + "/" + actionContext.ActionDescriptor.ActionName.ToLower();
            //如果没有权限访问当前API方法
            //如果需要验证每一个API的权限可继续验证,这里暂时不需要了
        }
Beispiel #3
0
        public ResponseItem ShowHide(yy_User value)
        {
            var _News = DB.yy_User.Find(value.ID);

            if (_News != null)
            {
                _News.LockFlag = value.LockFlag;
                DB.SaveChanges();

                return(new ResponseItem(0, ""));
            }

            return(new ResponseItem(2, "不存在的用户。"));
        }
Beispiel #4
0
        public ResponseItem Post(yy_User value)
        {
            var ExistsUser = DB.yy_User.Where(x => x.UserName == value.UserName).FirstOrDefault();

            if (ExistsUser != null)
            {
                return(new ResponseItem(1, "已存在的用户账号。"));
            }
            try
            {
                DB.yy_User.Add(value);
                DB.SaveChanges();
                return(new ResponseItem(0, "添加用户成功。"));
            }
            catch (Exception ex)
            {
                return(new ResponseItem(2, ex.Message));
            }
        }