Ejemplo n.º 1
0
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        if (filterContext == null)
        {
            throw new ArgumentNullException("filterContext");
        }

        HttpRequestBase request   = filterContext.RequestContext.HttpContext.Request;
        string          sessionID = request.QueryString["session_id"];

        if (string.Equals(request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) &&
            !filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
        {
            HttpCookie cookie = filterContext.RequestContext.HttpContext.Request.Cookies["gmcoresid"];
            if (!string.IsNullOrWhiteSpace(sessionID) ||
                (cookie != null && !string.IsNullOrEmpty(cookie.Value) && !CurrentUserSession.IsAuthenticated))
            {
                if (string.IsNullOrWhiteSpace(sessionID))
                {
                    sessionID = cookie.Value;
                }

                using (GamMatrixClient client = new GamMatrixClient())
                {
                    ReplyResponse replyResp = client.IsLoggedIn(new IsLoggedInRequest()
                    {
                        SESSION_ID = sessionID
                    });
                    IsLoggedInRequest resp = replyResp.Reply as IsLoggedInRequest;
                    if (replyResp.Success &&
                        resp != null &&
                        resp.IsLoggedIn &&
                        null != resp.UserProfile.RolesByName.FirstOrDefault(r => string.Equals(r, "Casino Engine Manager", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        CurrentUserSession.IsAuthenticated = true;
                        CurrentUserSession.IsSuperUser     = resp.UserProfile.IsSuperUser;
                        CurrentUserSession.Roles           = resp.UserProfile.RolesByName.ToArray();
                        CurrentUserSession.UserDomainID    = resp.UserProfile.DomainID;
                        CurrentUserSession.UserID          = resp.UserProfile.UserRec.ID;

                        if (!string.IsNullOrWhiteSpace(request.QueryString["d_si"]))
                        {
                            bool showInactiveDomains = string.Equals(request.QueryString["d_si"], "1", StringComparison.InvariantCulture);
                            CurrentUserSession.ShowInactiveDomains = showInactiveDomains;
                        }

                        cookie          = new HttpCookie("gmcoresid", sessionID);
                        cookie.HttpOnly = true;
                        filterContext.RequestContext.HttpContext.Response.Cookies.Add(cookie);
                        filterContext.Result = new RedirectResult(FilterUrlQueryString(request).ToString());
                        return;
                    }
                    else
                    {
                        cookie          = new HttpCookie("gmcoresid", string.Empty);
                        cookie.HttpOnly = true;
                        filterContext.RequestContext.HttpContext.Response.Cookies.Add(cookie);
                    }
                }
            }
        }

        if (!CurrentUserSession.IsAuthenticated)
        {
            filterContext.Result = new ContentResult()
            {
                Content = @"Access Denied.", ContentType = "text/html"
            };
            return;
        }


        //
        long currentDomainID = 0;

        if (long.TryParse(filterContext.RouteData.Values["domainID"] as string, out currentDomainID) &&
            currentDomainID > 0 &&
            CurrentUserSession.UserDomainID == Constant.SystemDomainID)
        {
            DomainManager.CurrentDomainID = currentDomainID;
        }
        else
        {
            DomainManager.CurrentDomainID = CurrentUserSession.UserDomainID;
        }
    }
Ejemplo n.º 2
0
 public GmException(ReplyResponse replyResponse)
     : base(string.Format("{0} - {1}", replyResponse.ErrorCode, replyResponse.ErrorSysMessage))
 {
     this.ReplyResponse = replyResponse;
 }