public ActionResult SubmitSite(SiteSelectionViewModel model)
        {
            var redirMsg = $"Redirecting to {Url.Action("Signin", "Account")}.";
            var selectedSiteIsUnusable = string.IsNullOrWhiteSpace(model.SelectedSite);

            if (!ModelState.IsValid || selectedSiteIsUnusable)
            {
                LogError($"Model state is not valid or submitted site is null or whitespace. {redirMsg}");
                return(RedirectToAction("Signin", "Account"));
            }

            if (!IsLoginDataAvailable)
            {
                LogError($"Login data not available in session or the stored object is null. {redirMsg}");
                return(RedirectToAction("Signin", "Account"));
            }

            SigninResponse signinResponse;

            CurrentLoginData.SelectedSite = model.SelectedSite;

            LogMessage($"Signing in to {CurrentLoginData.SelectedSite}");

            if (CurrentLoginData.SelectedSite != TsCurrentSiteName)
            {
                if (TsUserToken != null)
                {
                    LogMessage($"User {TsUserName} was logged in before as user token was found. Going with switch site API method.");
                    signinResponse = _tService.TrySwitchSite(CurrentLoginData.Username, CurrentLoginData.SelectedSite, TsUserToken);
                }
                else
                {
                    LogMessage($"Token not found for user {TsUserName}. Going with sign in API method.");
                    signinResponse = _tService.TrySignin(CurrentLoginData.Username, CurrentLoginData.Password, CurrentLoginData.SelectedSite);
                }
                signinResponse.TrustedToken = _tService.TryGetTrustedToken(CurrentLoginData.Username, CurrentLoginData.SelectedSite);
                SetSessionValues(signinResponse);
            }

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public ActionResult SiteSelection()
        {
            //var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));

            string UserId   = User.Identity.GetUserId();
            string UserName = User.Identity.GetUserName();

            //using (StreamWriter writer = new StreamWriter(Server.MapPath("/release_notification_emails.txt"), true))
            //{
            //    writer.WriteLine("Tracking STart");
            //    writer.WriteLine("User Id : " + UserId);
            //    writer.WriteLine("User Name : " + UserName);
            //}

            var userInRoles = _userRolesService.GetUserRolesList(UserId);

            if (userInRoles.Count() == 0)
            {
                string URoles = (string)System.Web.HttpContext.Current.Session["LoginUserRole"];

                if (userInRoles.Count() <= 0 && !(_userRolesService.TryInsertUserRole(UserId, UserName, URoles)))
                {
                    AuthenticationManager.SignOut();
                    FormsAuthentication.SignOut();
                    Session.Abandon();
                    return(View("NoRoles"));
                }



                Session.Remove("LoginUserRole");
            }


            SiteSelectionViewModel vm = new SiteSelectionViewModel();

            AssignSession();

            IEnumerable <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"];

            //Testing Block

            var temp = _userRolesService.GetRolesList().ToList();

            var RoleIds = string.Join(",", from p in temp
                                      where UserRoles.Contains(p.Name)
                                      select p.Id.ToString());

            //End


            if (UserRoles.Contains("Admin"))
            {
                var SiteList = _siteSelectionService.GetSiteList().ToList();
                ViewBag.SiteList = SiteList;
                var DivList = _siteSelectionService.GetDivisionList().ToList();
                ViewBag.DivisionList = DivList;

                if (SiteList.Count == 1 && DivList.Count == 1)
                {
                    AssignSiteDivModuleSession(SiteList.FirstOrDefault().SiteId, DivList.FirstOrDefault().DivisionId);

                    return(RedirectToAction("DefaultGodownSelection"));
                }
            }
            else
            {
                var SiteList = _siteSelectionService.GetSiteList(RoleIds).ToList();
                ViewBag.SiteList = SiteList;
                var DivList = _siteSelectionService.GetDivisionList(RoleIds).ToList();
                ViewBag.DivisionList = DivList;
                if (SiteList.Count == 0 || DivList.Count == 0)
                {
                    return(RedirectToAction("AccessDenied", "Account"));
                }
                else if (SiteList.Count == 1 && DivList.Count == 1)
                {
                    AssignSiteDivModuleSession(SiteList.FirstOrDefault().SiteId, DivList.FirstOrDefault().DivisionId);

                    return(RedirectToAction("DefaultGodownSelection"));
                }
            }
            if (System.Web.HttpContext.Current.Session["DivisionId"] != null && System.Web.HttpContext.Current.Session["SiteId"] != null)
            {
                vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                vm.SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            }

            return(View(vm));
        }
Beispiel #3
0
        public ActionResult SiteSelection(SiteSelectionViewModel vm)
        {
            AssignSiteDivModuleSession(vm.SiteId, vm.DivisionId);

            return(RedirectToAction("DefaultGodownSelection"));
        }