Пример #1
0
        protected bool HasErrorsRenderingPage(out ActionResult errorAction, RedirectionHandler redirection = null)
        {
            bool hasError = false;

            errorAction = null;

            var model = new LoginViewModel();

            try
            {
                if (IsUserLogged())
                {
                    if (HasRole())
                    {
                        model = (LoginViewModel)Session["user"];
                    }
                    else
                    {
                        hasError    = true;
                        errorAction = new HttpStatusCodeResult(HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    hasError    = true;
                    errorAction = GetRedirection(RedirectionHandler.LOGIN, redirection);
                }
            }
            catch { }

            return(hasError);
        }
Пример #2
0
        protected RedirectToRouteResult GetRedirection(RedirectionHandler redirection, RedirectionHandler redirectionParams = null)
        {
            object route = null;

            if (redirectionParams != null)
            {
                route = new { e = PageErrorEnum.UNAUTHORIZED, a = redirectionParams.Action, c = redirectionParams.Controller };
            }

            return(RedirectToAction(redirection.Action, redirection.Controller, route));
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="token">OAuth 2.0 token obtained from Egnyte</param>
        /// <param name="domain">Domain on which you connect to egnyte,
        /// i.e.: domain is 'mydomain', when url looks like: mydomain.egnyte.com</param>
        /// <param name="httpClient">You can provide your own httpClient. Optional</param>
        /// <param name="requestTimeout">You can provide timeout for calling Egnyte API,
        /// by default it's 10 minutes. This parameter is optional</param>
        /// <param name="host">Full host name on which you connect to egnyte,
        /// i.e.: host is 'my.custom.host.com', when url looks like: my.custom.host.com</param>
        public EgnyteClient(
            string token,
            string domain           = "",
            HttpClient httpClient   = null,
            TimeSpan?requestTimeout = null,
            string host             = "")
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException(nameof(token));
            }

            if (string.IsNullOrWhiteSpace(domain) && string.IsNullOrWhiteSpace(host))
            {
                throw new ArgumentNullException("domain", "Domain or host has to specified");
            }

            var handler = new RedirectionHandler()
            {
                InnerHandler = new HttpClientHandler()
                {
                    AllowAutoRedirect = false
                }
            };

            httpClient = httpClient ?? new HttpClient(handler);

            httpClient.Timeout = TimeSpan.FromMinutes(10);
            if (requestTimeout.HasValue)
            {
                httpClient.Timeout = requestTimeout.Value;
            }

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            Files       = new FilesClient(httpClient, domain, host);
            Users       = new UsersClient(httpClient, domain, host);
            Links       = new LinksClient(httpClient, domain, host);
            Groups      = new GroupsClient(httpClient, domain, host);
            Permissions = new PermissionsClient(httpClient, domain, host);
            Search      = new SearchClient(httpClient, domain, host);
            Audit       = new AuditClient(httpClient, domain, host);
        }