コード例 #1
0
        public ActionResult Suspended()
        {
            int accountId            = Thread.CurrentPrincipal.Identity.ToAccountID();
            AccountViewModel account = cacheService.GetAccount(accountId);

            ViewBag.AccountName   = account.AccountName;
            ViewBag.ImageSrc      = account.Image == null ? "" : account.Image.ImageContent;
            ViewBag.StatusMessage = account.StatusMessage;

            return(View("Suspended"));
        }
コード例 #2
0
        public ActionResult Login(string returnUrl, string message, string modelMessage)
        {
            Logger.Current.Informational("In Login returnUrl " + returnUrl + ", message:" + message);
            if (Request.IsAuthenticated)
            {
                GetAccountAuthorizationRequest request = new GetAccountAuthorizationRequest();
                request.name = DomainName;
                GetAccountAuthorizationResponse response = accountService.GetAccountByDomainUrl(request);
                if (response.Exception != null)
                {
                    ExceptionHandler.Current.HandleException(response.Exception, DefaultExceptionPolicies.LOG_ONLY_POLICY);
                    ModelState.AddModelError("", "[|Invalid Account.|]");
                    return(View());
                }
                cachingService.AddAccountPermissions(response.AccountId);
                cachingService.AddUserPermissions(response.AccountId);
                return(RedirectToLocal("", Thread.CurrentPrincipal.Identity.ToRoleID(), Thread.CurrentPrincipal.Identity.ToAccountID(), "", ""));
            }
            if (!String.IsNullOrEmpty(modelMessage))
            {
                ModelState.AddModelError("", modelMessage);
            }
            var defaultHelpURL = ConfigurationManager.AppSettings["helpURL"].ToString();

            ViewBag.SecurityMessage = message;
            if (!string.IsNullOrEmpty(returnUrl) && returnUrl.ToLower().Contains("logoff"))
            {
                returnUrl = null;
            }
            Logger.Current.Verbose("Request for login using domainurl:" + DomainName);
            ViewBag.Page = "Login";
            string loginPage = "Login";
            string masterUrl = DomainName;

            if (!string.IsNullOrWhiteSpace(DomainName))
            {
                GetAccountAuthorizationRequest request = new GetAccountAuthorizationRequest();
                request.name = DomainName;
                var accountID = default(int);
                GetAccountAuthorizationResponse response  = accountService.GetAccountByDomainUrl(request);
                GetSubscriptionSettingsRequest  ssRequest = new GetSubscriptionSettingsRequest();
                if (response != null)
                {
                    ssRequest.SubscriptionId = response.SubscriptionId;
                }
                GetSubscriptionSettingsResponse ssResponse = accountService.GetSubscriptionSettings(ssRequest);
                masterUrl = ssResponse.SubscriptionSettings.Where(p => p.SubscriptionSettingType == SubscriptionSettingTypes.Master).Select(p => p.Value).FirstOrDefault();
                if (masterUrl != null && masterUrl != DomainName)
                {
                    return(Redirect("https://" + masterUrl + "/Login/?modelMessage=" + modelMessage));
                }
                loginPage         = ssResponse.SubscriptionSettings.Where(p => p.SubscriptionSettingType == SubscriptionSettingTypes.Login).Select(p => p.Value).FirstOrDefault();
                ViewBag.LoginUrl  = masterUrl == null ? DomainName : masterUrl;
                ViewBag.LoginPage = loginPage;
                if (response.Exception != null)
                {
                    ExceptionHandler.Current.HandleException(response.Exception, DefaultExceptionPolicies.LOG_ONLY_POLICY);
                    ModelState.AddModelError("", "[|Invalid Account.|]");
                    return(View());
                }
                if (response != null)
                {
                    cachingService.AddAccountPermissions(response.AccountId);
                    Logger.Current.Informational("AccountId :" + response.AccountId);
                    Logger.Current.Informational("Account Name :" + response.AccountName);
                    accountID = response.AccountId;
                    this.Response.Cookies.Add(new HttpCookie("helpURL", !string.IsNullOrEmpty(response.HelpURL) ? response.HelpURL : defaultHelpURL));
                }
                LoginViewModel loginViewModel = new LoginViewModel();
                loginViewModel.AccountId = accountID;
                if (response.SubscriptionId == (int)AccountSubscription.Standard || response.SubscriptionId == (int)AccountSubscription.STAdmin)
                {
                    loginViewModel.AccountName = response.AccountName;
                }
                if (returnUrl != null)
                {
                    ViewBag.ReturnUrl = returnUrl;
                }
                ViewBag.AccountID   = accountID;
                ViewBag.AccountName = response.AccountName;
                if (response.Status == 3)
                {
                    AccountViewModel account = cachingService.GetAccount(accountID);
                    ViewBag.AccountName   = account.AccountName;
                    ViewBag.ImageSrc      = account.Image == null ? "" : account.Image.ImageContent;
                    ViewBag.StatusMessage = account.StatusMessage;
                    return(View("~/Views/Error/Suspended.cshtml"));
                }
                else if (response.Status == 5)
                {
                    AccountViewModel account = cachingService.GetAccount(accountID);
                    ViewBag.AccountName   = account.AccountName;
                    ViewBag.ImageSrc      = account.Image == null ? "" : account.Image.ImageContent;
                    ViewBag.StatusMessage = account.StatusMessage;
                    return(View("~/Views/Error/Maintenance.cshtml"));
                }
                return(View(loginPage, loginViewModel));
            }
            else
            {
                return(View(loginPage));
            }
        }
コード例 #3
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            /*Check if this action has AllowAnonymousAttribute*/
            string actionname = filterContext.ActionDescriptor.ActionName;
            int    AccountID  = Thread.CurrentPrincipal.Identity.ToAccountID();

            if (AccountID > 0 && (actionname != "Suspended" && actionname != "Maintanance"))
            {
                AccountViewModel account = cacheService.GetAccount(AccountID);
                if (account != null)
                {
                    if (account.Status == 3)/*paused*/
                    {
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
                        {
                            controller = "Error",
                            action     = "Suspended"
                        }));
                        return;
                    }
                    else if (account.Status == 5)
                    {
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
                        {
                            controller = "Error",
                            action     = "Maintanance"
                        }));
                        return;
                    }
                }
            }
            var attributes = filterContext.ActionDescriptor.GetCustomAttributes(true);

            #region route data
            var routeData = Request.RequestContext.RouteData;
            this.CurrentArea       = routeData.DataTokens["area"] as string;
            this.CurrentController = routeData.GetRequiredString("controller");
            this.CurrentAction     = routeData.GetRequiredString("action");
            #endregion
            if (attributes.Any(a => a is MenuTypeAttribute))
            {
                TempData[Keys.MENU_TYPE] = ((MenuTypeAttribute)attributes.Where(a => a is MenuTypeAttribute).Single()).Category;
            }
            else
            {
                TempData[Keys.MENU_TYPE] = default(MenuCategory);
            }
            if (attributes.Any(a => a is MenuTypeAttribute))
            {
                TempData[Keys.LEFT_MENU_TYPE] = ((MenuTypeAttribute)attributes.Where(a => a is MenuTypeAttribute).Single()).LeftMenuType;
            }
            else
            {
                TempData[Keys.LEFT_MENU_TYPE] = default(MenuCategory);
            }
            if (attributes.Any(a => a is AllowAnonymousAttribute))
            {
                return;
            }
            /*must login*/
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                Logger.Current.Informational("Request not authenticated 1 " + filterContext.HttpContext.User.Identity.ToUserEmail());
                filterContext.Result = new HttpUnauthorizedResult();
                return;
            }
            /*check authorization*/
            if (attributes.Any(a => a is AppFeatureAttribute) && ((AppFeatureAttribute)attributes.Where(a => a is AppFeatureAttribute).Single()).Feature != AppFeatures.NOT_APPLICABLE && !Thread.CurrentPrincipal.Identity.IsInFeature(((AppFeatureAttribute)attributes.Where(a => a is AppFeatureAttribute).Single()).Feature))
            {
                Logger.Current.Informational("Request not authenticated 2 " + filterContext.HttpContext.User.Identity.ToUserEmail());
                filterContext.Result = new HttpUnauthorizedResult();
            }
        }