Exemple #1
0
        public PartialViewResult KnowYourTurfHeader()
        {
            User user = new User();

            if (User.Identity.IsAuthenticated)
            {
                user = _sessionContext.GetCurrentUser();
            }
            var inAdminMode = _sessionContext.RetrieveSessionObject(WebLocalizationKeys.INADMINMODE.ToString());

            if (inAdminMode == null)
            {
                _sessionContext.AddUpdateSessionItem(new SessionItem {
                    SessionKey = WebLocalizationKeys.INADMINMODE.ToString(), SessionObject = false
                });
                inAdminMode = false;
            }
            HeaderViewModel model = new HeaderViewModel
            {
                User        = user,
                LoggedIn    = User.Identity.IsAuthenticated,
                IsAdmin     = (user.UserRoles.IsNotEmpty() && user.UserRoles.Contains(UserRole.Admin.ToString())),
                InAdminMode = (bool)inAdminMode
            };

            return(PartialView(model));
        }
Exemple #2
0
        public ActionResult Login(LoginViewModel input)
        {
            var notification = new Notification
            {
                Message = WebLocalizationKeys.INVALID_USERNAME_OR_PASSWORD.ToString()
            };

            if (input.HasCredentials())
            {
                var redirectUrl = string.Empty;
                var user        = _securityDataService.AuthenticateForUserId(input.UserName, input.Password);
                if (user != null)
                {
                    redirectUrl           = _authContext.ThisUserHasBeenAuthenticated(user, input.RememberMe);
                    notification.Success  = true;
                    notification.Message  = string.Empty;
                    notification.Redirect = true;
                    _sessionContext.AddUpdateSessionItem(
                        new SessionItem
                    {
                        SessionKey    = WebLocalizationKeys.USER_ROLES.ToString(),
                        SessionObject = user.UserRoles
                    }
                        );
                }
                if (redirectUrl != "/Home/Home")
                {
                    notification.RedirectUrl = redirectUrl;
                }
                else if (user.UserType == UserType.Employee.ToString())
                {
                    notification.RedirectUrl = UrlContext.GetUrlForAction <EmployeeDashboardController>(x => x.ViewEmployee(null)) + "/" + user.EntityId;
                }
                else
                {
                    notification.RedirectUrl = redirectUrl;
                }
            }
            return(Json(notification));
        }