Пример #1
0
        //private static readonly object CacheLockObject = new object();
        public override void OnActionExecuting(HttpActionContext context)
        {
            var result          = false;
            var headerTokenCode = context.Request.Headers.SingleOrDefault(x => x.Key == "TokenCode");

            //var headerUserName = context.Request.Headers.SingleOrDefault(x => x.Key == "UserName");
            //var headerUserInfo = context.Request.Headers.SingleOrDefault(x => x.Key == "UserInfo");
            //var tk = "";
            if (headerTokenCode.Value != null)
            {
                var tokenHeader = headerTokenCode.Value.First();
                //var userNameHeader = headerUserName.Value.First();
                //var tokenClient = EncryptCore.Md5Get(userNameHeader + EncryptCore.PassKey + EncryptCore.TimeToken);
                Project2.Models.UserResult userInfo = CacheUtil.GetCacheObject(tokenHeader);
                if (userInfo != null)
                {
                    //tk = userInfo.TokenCode;
                    if (userInfo.AccessToken == tokenHeader)
                    {
                        result = true;
                    }
                }
            }
            //if (headerUserInfo.Value != null)
            //{
            //    UserInfo userInfo = Libs.DeserializeObject<UserInfo>(headerUserInfo.Value.First());
            //    var tokenHeader = userInfo.TokenCode;
            //    var userNameHeader = userInfo.Username;
            //    var tokenClient = "";
            //    lock (CacheUtil.CacheLockObject)
            //    {
            //        tokenClient = HttpRuntime.Cache[userNameHeader] as string;
            //    }
            //    if (tokenClient == tokenHeader)
            //    {
            //        result = true;
            //    }
            //}
            if (!result)
            {
                //Libs.WriteLog("xxxx", tk);
                //Libs.WriteLog("zzzz", headerTokenCode.Value.First());
                var Rs = new ApiResult <UserResult>()
                {
                };
                Rs.Failed(new ErrorObject {
                    Code        = "400",
                    Description = "Sai TokenCode"
                });
                context.Response = context.Request.CreateResponse(HttpStatusCode.Forbidden, Rs, context.ControllerContext.Configuration.Formatters.JsonFormatter);
            }
        }
Пример #2
0
        public IHttpActionResult GetPaging(BaseCondition <HotelPaging> condition)
        {
            string tokenCode = HttpContext.Current.Request.Headers["TokenCode"] != null ? HttpContext.Current.Request.Headers["TokenCode"].ToString() : "";

            Models.UserResult UserInfo = null;

            if (!string.IsNullOrEmpty(tokenCode))
            {
                UserInfo = CacheUtil.GetCacheObject(tokenCode);
            }
            int UserId = (UserInfo != null && UserInfo.Id > 0) ? UserInfo.Id : 0;

            List <FilterItems> FilterRules = condition.FilterRules;
            List <SortItems>   SortRules   = condition.SortRules;

            if (SortRules != null && SortRules.Count > 0)
            {
                foreach (var item in SortRules.Select((value, i) => new { i, value }))
                {
                    SortItems e     = item.value;
                    int       Index = item.i;
                    if (e.field.ToLower() == "minprice")
                    {
                        condition.SortRules[Index].field = "CAST(MinPrice as Int)";
                        continue;
                    }
                }
            }


            var req = hotelDAL.GetPaging(condition, UserId);

            if (req.Succeeded)
            {
                return(Ok(req));
            }
            else
            {
                return(Content(HttpStatusCode.BadRequest, req));
            }
        }
Пример #3
0
        public IHttpActionResult GetUserByTokenCode(string TokenCode = "")
        {
            var        Rs       = new ApiResult <UserResult>();
            UserResult userInfo = CacheUtil.GetCacheObject(TokenCode);

            if (userInfo != null)
            {
                var Rq = userDAL.GetById(userInfo.Id).Data;

                Rs.Data = new UserResult
                {
                    Id             = Rq.Id,
                    Email          = Rq.Email,
                    AccessToken    = TokenCode,
                    Address        = Rq.Address,
                    DistrictCode   = Rq.DistrictCode,
                    EmailConfirmed = Rq.EmailConfirmed,
                    FirstName      = Rq.FirstName,
                    LastName       = Rq.LastName,
                    PhoneNumber    = Rq.PhoneNumber,
                    ProvinceCode   = Rq.ProvinceCode,
                    RoleDesc       = Rq.RoleDesc,
                    RoleId         = Rq.RoleId,
                    UserAvatar     = Rq.UserAvatar
                };

                return(Ok(Rs));
            }
            else
            {
                Rs.Failed(new ErrorObject
                {
                    Code        = "400",
                    Description = "Sai TokenCode"
                });
                return(Content(HttpStatusCode.Unauthorized, Rs));
            }
        }
Пример #4
0
        public IHttpActionResult Insert(PostOrder Item)
        {
            string tokenCode = HttpContext.Current.Request.Headers["TokenCode"] != null ? HttpContext.Current.Request.Headers["TokenCode"].ToString() : "";

            Models.UserResult UserInfo = null;

            if (!string.IsNullOrEmpty(tokenCode))
            {
                UserInfo = CacheUtil.GetCacheObject(tokenCode);
            }
            int UserId = (UserInfo != null && UserInfo.Id > 0) ? UserInfo.Id : 0;

            ApiResult <NewOrderResult> rs = new ApiResult <NewOrderResult>()
            {
                Data = new NewOrderResult()
            };

            if (Item == null || Item.Order == null)
            {
                rs.Failed(new ErrorObject
                {
                    Code        = "EXCEPTION",
                    Description = "Đéo nhận Data truyền vào."
                });
                return(Content(HttpStatusCode.BadRequest, rs));
            }

            if (!ModelState.IsValid)
            {
                // Lỗi validate dữ liệu trả ra từ model
                foreach (string key in ModelState.Keys)
                {
                    ModelState current = ModelState[key];
                    foreach (ModelError error in current.Errors)
                    {
                        rs.Failed(new ErrorObject()
                        {
                            Code        = key,
                            Description = error.ErrorMessage
                        });
                    }
                }

                return(Content(HttpStatusCode.BadRequest, rs));
            }

            Item.Order.TokenCode = RandomString(15);
            rs = orderDAL.Insert(Item.Order, UserId);

            if (!rs.Succeeded)
            {
                return(Content(HttpStatusCode.BadRequest, rs));
            }

            string Link = ConfigUtil.DomainBaseHttp + "/API/Order/Confirm?Id="
                          + rs.Data.Id.ToString()
                          + "&TokenCode=" + Item.Order.TokenCode
                          + "&SucUrl=" + Item.SucUrl
                          + "&FailUrl=" + Item.FailUrl;

            object EmailData = new
            {
                Link,
                Item.Order.GuestName,
                SetTime = DateTime.Now.ToString(),
                Item.Order.RoomName
            };

            string EmailContent = EmailContentHtml.EmailContentFormat(EmailData, "ConfirmOrder.html");
            bool   e            = EmailUtility.SendMail(ConfigUtil.Email_DisplayName, Item.Order.GuestEmail, "Xác thực Đơn đặt phòng", messages: EmailContent);

            return(Ok(rs));
        }