Пример #1
0
        public virtual async Task <IActionResult> SearchModal(
            Guid?siteId,
            string query   = "",
            int sortMode   = 0, //sortMode: 0 = DisplayName asc, 1 = JoinDate desc, 2 = Last, First
            int pageNumber = 1,
            int pageSize   = -1,
            bool ajaxGrid  = false
            )
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            var itemsPerPage = UIOptions.DefaultPageSize_UserList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            if (query == null)
            {
                query = string.Empty;
            }

            var siteMembers = await UserManager.GetUserAdminSearchPage(
                selectedSite.Id,
                pageNumber,
                itemsPerPage,
                query,
                sortMode);

            var model = new UserListViewModel
            {
                SiteId      = selectedSite.Id,
                UserList    = siteMembers,
                SearchQuery = query,
                SortMode    = sortMode,
                ActionName  = "SearchModal",
                TimeZoneId  = await TimeZoneIdResolver.GetUserTimeZoneId()
            };


            if (ajaxGrid)
            {
                return(PartialView("UserModalGridPartial", model));
            }

            return(PartialView("UserLookupModal", model));
        }
        public virtual async Task <IActionResult> Index(
            Guid?siteId,
            string query   = "",
            int sortMode   = 1,  //sortMode: 0 = DisplayName asc, 1 = JoinDate desc, 2 = Last, First
            int pageNumber = 1,
            int pageSize   = -1
            )
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - User Management"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["User Management"];
            }

            var itemsPerPage = UIOptions.DefaultPageSize_UserList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            var siteMembers = await UserManager.GetPage(
                selectedSite.Id,
                pageNumber,
                itemsPerPage,
                query,
                sortMode);

            var model = new UserListViewModel
            {
                SiteId     = selectedSite.Id,
                UserList   = siteMembers,
                SortMode   = sortMode,
                AlphaQuery = query,
                TimeZoneId = await TimeZoneIdResolver.GetUserTimeZoneId()
            };

            var viewName = await CustomUserInfo.GetUserListViewName(UserManager.Site, HttpContext);

            return(View(viewName, model));
        }
Пример #3
0
        private async Task <IActionResult> RouteToIndexPage(SiteUser user)
        {
            var model = new AccountIndexViewModel
            {
                HasPassword       = (!string.IsNullOrWhiteSpace(user.PasswordHash)),
                PhoneNumber       = !string.IsNullOrWhiteSpace(user.PhoneNumber) ? user.PhoneNumber : null,
                TwoFactor         = user.TwoFactorEnabled,
                Logins            = await UserManager.GetLoginsAsync(user),
                BrowserRemembered = await SignInManager.IsTwoFactorClientRememberedAsync(user),
                TimeZone          = user.TimeZoneId,
                Email             = user.Email
            };

            if (string.IsNullOrEmpty(model.TimeZone))
            {
                model.TimeZone = await TimeZoneIdResolver.GetSiteTimeZoneId();
            }

            return(View("Index", model));
        }
Пример #4
0
        public virtual async Task <IActionResult> IpSearch(
            Guid?siteId,
            string ipQuery = "")
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - User Management"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["User Management"];
            }

            var siteMembers = await UserManager.GetByIPAddress(
                selectedSite.Id,
                ipQuery);

            // not really paged in UI but re-using the ViewModel which needs a PagedResult
            var data = new PagedResult <IUserInfo>
            {
                Data       = siteMembers,
                PageNumber = 1,
                PageSize   = 2000,
                TotalItems = siteMembers.Count()
            };

            var model = new UserListViewModel
            {
                SiteId         = selectedSite.Id,
                UserList       = data,
                IpQuery        = ipQuery, //TODO: sanitize
                ShowAlphaPager = false,
                TimeZoneId     = await TimeZoneIdResolver.GetUserTimeZoneId(),
                ActionName     = "IpSearch"
            };

            return(View("Index", model));
        }
Пример #5
0
        public async Task <IActionResult> Index()
        {
            var user = await UserManager.FindByIdAsync(HttpContext.User.GetUserId());

            var model = new AccountIndexViewModel
            {
                HasPassword       = (!string.IsNullOrWhiteSpace(user.PasswordHash)),
                PhoneNumber       = !string.IsNullOrWhiteSpace(user.PhoneNumber) ? user.PhoneNumber : null,
                TwoFactor         = user.TwoFactorEnabled,
                Logins            = await UserManager.GetLoginsAsync(user),
                BrowserRemembered = await SignInManager.IsTwoFactorClientRememberedAsync(user),
                TimeZone          = user.TimeZoneId
            };

            if (string.IsNullOrEmpty(model.TimeZone))
            {
                model.TimeZone = await TimeZoneIdResolver.GetSiteTimeZoneId();
            }

            return(View(model));
        }
Пример #6
0
        public virtual async Task <IActionResult> UnApprovedUsers(
            Guid?siteId,
            int pageNumber = 1,
            int pageSize   = -1)
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - User Accounts Pending Approval"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["User Accounts Pending Approval"];
            }

            var itemsPerPage = UIOptions.DefaultPageSize_UserList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            var siteMembers = await UserManager.GetNotApprovedUsers(
                selectedSite.Id,
                pageNumber,
                itemsPerPage);

            var model = new UserListViewModel
            {
                SiteId         = selectedSite.Id,
                UserList       = siteMembers,
                ShowAlphaPager = false,
                TimeZoneId     = await TimeZoneIdResolver.GetUserTimeZoneId(),
                ActionName     = "UnApprovedUsers"
            };

            return(View(model));
        }
Пример #7
0
        public virtual async Task <IActionResult> TimeZone()
        {
            var user = await UserManager.FindByIdAsync(HttpContext.User.GetUserId());

            var model = new TimeZoneViewModel
            {
                TimeZoneId = user.TimeZoneId
            };

            if (string.IsNullOrEmpty(model.TimeZoneId))
            {
                model.TimeZoneId = await TimeZoneIdResolver.GetSiteTimeZoneId();
            }
            model.AllTimeZones = TimeZoneHelper.GetTimeZoneList().Select(x =>
                                                                         new SelectListItem
            {
                Text     = x,
                Value    = x,
                Selected = model.TimeZoneId == x
            });

            return(View(model));
        }
Пример #8
0
        public virtual async Task <ActionResult> UserEdit(
            Guid userId,
            Guid?siteId
            )
        {
            if (userId == Guid.Empty)
            {
                return(RedirectToAction("Index"));
            }

            ViewData["ReturnUrl"] = Request.Path + Request.QueryString;
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - Manage User"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["Manage User"];
            }



            var model = new EditUserViewModel
            {
                SiteId = selectedSite.Id
            };

            var user = await UserManager.Fetch(selectedSite.Id, userId);

            if (user != null)
            {
                model.UserId          = user.Id;
                model.Email           = user.Email;
                model.FirstName       = user.FirstName;
                model.LastName        = user.LastName;
                model.Username        = user.UserName;
                model.DisplayName     = user.DisplayName;
                model.AccountApproved = user.AccountApproved;
                model.Comment         = user.Comment;
                model.EmailConfirmed  = user.EmailConfirmed;
                model.IsLockedOut     = user.IsLockedOut;
                model.LastLoginDate   = user.LastLoginUtc;
                model.TimeZoneId      = user.TimeZoneId;
                model.WebSiteUrl      = user.WebSiteUrl;
                model.AvatarUrl       = user.AvatarUrl;

                if (string.IsNullOrEmpty(model.TimeZoneId))
                {
                    model.TimeZoneId = await TimeZoneIdResolver.GetSiteTimeZoneId();
                }
                model.AllTimeZones = TimeZoneHelper.GetTimeZoneList().Select(x =>
                                                                             new SelectListItem
                {
                    Text     = x,
                    Value    = x,
                    Selected = model.TimeZoneId == x
                });

                if (user.DateOfBirth > DateTime.MinValue)
                {
                    model.DateOfBirth = user.DateOfBirth;
                }

                model.UserClaims = await UserManager.GetClaimsAsync((SiteUser)user);

                model.UserRoles = await UserManager.GetRolesAsync((SiteUser)user);


                var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext)
                {
                    KeyToAdjust    = "UserEdit",
                    AdjustedText   = user.DisplayName,
                    ViewFilterName = NamedNavigationFilters.Breadcrumbs // this is default but showing here for readers of code
                };
                currentCrumbAdjuster.AddToContext();
            }

            var viewName = await CustomUserInfo.GetUserEditViewName(UserManager.Site, HttpContext);

            await CustomUserInfo.HandleUserEditGet(
                UserManager.Site,
                model,
                HttpContext,
                ViewData);

            return(View(viewName, model));
        }
Пример #9
0
        public virtual async Task <ActionResult> UserActivity(
            Guid userId,
            Guid?siteId,
            int pageNumber = 1,
            int pageSize   = 10
            )
        {
            if (userId == Guid.Empty)
            {
                return(RedirectToAction("Index"));
            }

            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            var user = await UserManager.Fetch(selectedSite.Id, userId);

            if (user == null)
            {
                return(RedirectToAction("Index"));
            }

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - User Activity - {1}"], selectedSite.SiteName, user.Email);
            }
            else
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["User Activity - {0}"], user.Email);
            }

            var model = new UserActivityViewModel
            {
                SiteId                  = selectedSite.Id,
                UserId                  = user.Id,
                CreatedUtc              = user.CreatedUtc,
                DisplayName             = user.DisplayName,
                Email                   = user.Email,
                AvatarUrl               = user.AvatarUrl,
                FirstName               = user.FirstName,
                LastLoginUtc            = user.LastLoginUtc,
                LastName                = user.LastName,
                LastPassswordChangenUtc = user.LastPasswordChangeUtc,
                TimeZoneId              = await TimeZoneIdResolver.GetUserTimeZoneId(),
                Locations               = await UserManager.GetUserLocations(
                    selectedSite.Id,
                    userId,
                    pageNumber,
                    pageSize
                    ),

                TwoFactor = user.TwoFactorEnabled,
                Logins    = await UserManager.GetLoginsAsync(user as SiteUser)
            };

            if (!string.IsNullOrWhiteSpace(user.TimeZoneId))
            {
                model.UserTimeZone = user.TimeZoneId;
            }
            else
            {
                model.UserTimeZone = UserManager.Site.TimeZoneId;
            }


            var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext)
            {
                KeyToAdjust    = "UserActivity",
                AdjustedText   = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["Activity - {0}"], user.Email),
                ViewFilterName = NamedNavigationFilters.Breadcrumbs // this is default but showing here for readers of code
            };

            currentCrumbAdjuster.AddToContext();

            return(View(model));
        }
Пример #10
0
        public virtual async Task <IActionResult> Search(
            Guid?siteId,
            string query   = "",
            int sortMode   = 2,
            int pageNumber = 1,
            int pageSize   = -1,
            bool ajaxGrid  = false
            )
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - User Management"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["User Management"];
            }

            var itemsPerPage = UIOptions.DefaultPageSize_UserList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            if (query == null)
            {
                query = string.Empty;
            }

            var siteMembers = await UserManager.GetUserAdminSearchPage(
                selectedSite.Id,
                pageNumber,
                itemsPerPage,
                query,
                sortMode);

            var model = new UserListViewModel
            {
                SiteId      = selectedSite.Id,
                UserList    = siteMembers,
                SearchQuery = query,
                SortMode    = sortMode,
                ActionName  = "Search",
                TimeZoneId  = await TimeZoneIdResolver.GetUserTimeZoneId()
            };

            if (Request.IsAjaxRequest())
            {
                if (ajaxGrid)
                {
                    return(PartialView("UserModalGridPartial", model));
                }
                else
                {
                    return(PartialView("UserLookupModal", model));
                }
            }

            return(View("Index", model));
        }