Example #1
0
 public JsonResult InsertRolePermissions(string rolePermissionViewodel)
 {
     RolePermissionsViewModel PermissionViewodel = JsonConvert.DeserializeObject<RolePermissionsViewModel>(rolePermissionViewodel);
     InsertRolePermissionsResponse response = roleService.InsertRolePermissions(new InsertRolePermissionsRequest()
     {
         rolePermissionsViewModel = PermissionViewodel
     });
     if (response.Exception == null)
     {
         int accountId = this.Identity.ToAccountID();
         cachingService.AddUserPermissions(accountId);
     }
     return Json(new
     {
         success = true,
         response = ""
     }, JsonRequestBehavior.AllowGet);
 }
Example #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));
            }
        }