Exemplo n.º 1
0
        public void Identity(HttpRequest req)
        {
            try
            {
                var reqAppRelativePath = req?.AppRelativeCurrentExecutionFilePath?.Replace("~", string.Empty);
                this._requestMethod = req?.HttpMethod;
                if (req != null)
                {
                    this._isRequestTypeAjax = new HttpRequestWrapper(req).IsAjaxRequest();
                }

                if (SessionData.CurrentUser != null)
                {
                    var isAccountSessionValid = AccountManagerBL.ValidAccountSession(SessionData.CurrentUser);
                    if (!isAccountSessionValid)
                    {
                        SessionData.CurrentUser  = null;
                        this._isRequestIdentity  = false;
                        this._responeRedirectUrl = RouteConfig.KnAccountSessionInvalid;
                        return;
                    }
                }

                if (FunctionBL.GetAllFunctionsNoRequiredLogin().Any(
                        t => t.HrefGet == reqAppRelativePath || t.HrefPost == reqAppRelativePath))
                {
                    this._isRequestIdentity = true;
                    return;
                }

                if (FunctionBL.GetAllFunctionsRequiredLogin().Any(
                        t => t.HrefGet == reqAppRelativePath || t.HrefPost == reqAppRelativePath))
                {
                    if (SessionData.CurrentUser == null)
                    {
                        this._isRequestIdentity  = false;
                        this._responeRedirectUrl = RouteConfig.KnLogin;
                        this._returnUrl          = reqAppRelativePath;
                        return;
                    }

                    if (AccountManagerBL.IsAccountRoleDataChanged(SessionData.CurrentUser.Id))
                    {
                        this._isRequestIdentity  = false;
                        this._responeRedirectUrl = RouteConfig.KnReLoginWhenAccountDataChanged;
                        return;
                    }

                    if (SessionData.CurrentUser.AllAccountRoles.Any(
                            t => t.HrefGet == reqAppRelativePath || t.HrefPost == reqAppRelativePath))
                    {
                        this._isRequestIdentity = true;
                    }
                    else
                    {
                        this._isRequestIdentity  = false;
                        this._responeRedirectUrl = RouteConfig.KnAccessDenied;
                    }

                    return;
                }
            }
            catch (Exception)
            {
                // Since handle exception here make no sense cause we treat exception to fail identity
                // Exception Inorged
            }

            this._isRequestIdentity  = false;
            this._responeRedirectUrl = RouteConfig.KnHttpNotFound;
        }