Exemplo n.º 1
0
        // -----------------
        // Get User
        // -----------------

        public async Task <IActionResult> GetUser(DisplayUserOptions opts)
        {
            // Ensure we have defaults

            if (opts == null)
            {
                opts = new DisplayUserOptions();
            }

            if (opts.Id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(opts.Id));
            }

            // Get user
            var user = await _platoUserStore.GetByIdAsync(opts.Id);

            // Ensure user exists
            if (user == null)
            {
                return(NotFound());
            }

            // Return view
            return(View(user));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(DisplayUserOptions opts)
        {
            if (opts == null)
            {
                opts = new DisplayUserOptions();
            }

            var user = opts.Id > 0
                ? await _platoUserStore.GetByIdAsync(opts.Id)
                : await _contextFacade.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(NotFound());
            }

            // Build page title
            _pageTitleBuilder.AddSegment(S[user.DisplayName], int.MaxValue);

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Users"], discuss => discuss
                                  .Action("Index", "Home", "Plato.Users")
                                  .LocalNav()
                                  ).Add(S[user.DisplayName], discuss => discuss
                                        .Action("Display", "Home", "Plato.Users", new RouteValueDictionary()
                {
                    ["opts.id"]    = user.Id,
                    ["opts.alias"] = user.Alias
                })
                                        .LocalNav()
                                        ).Add(S["Badges"]);
            });

            // Return view
            return(View((LayoutViewModel)await _userBadgeViewProvider.ProvideIndexAsync(new UserBadge()
            {
                UserId = user.Id
            }, this)));
        }
Exemplo n.º 3
0
        // -----------------
        // Display User
        // -----------------

        public async Task <IActionResult> Display(DisplayUserOptions opts)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User,
                                                            Permissions.ViewProfiles))
            {
                return(Unauthorized());
            }

            // Get user to display
            var user = opts.Id > 0
                ? await _platoUserStore.GetByIdAsync(opts.Id)
                : await _contextFacade.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(NotFound());
            }

            // Ensure we have permission to view unconfirmed accounts
            if (!user.EmailConfirmed)
            {
                if (!await _authorizationService.AuthorizeAsync(User,
                                                                Permissions.ViewUnconfirmedUsers))
                {
                    return(Unauthorized());
                }
            }

            // Ensure we have permission to view users flagged as SPAM
            if (user.IsSpam)
            {
                if (!await _authorizationService.AuthorizeAsync(User,
                                                                Permissions.ViewSpamUsers))
                {
                    return(Unauthorized());
                }
            }

            // Ensure we have permission to view banned users
            if (user.IsBanned)
            {
                if (!await _authorizationService.AuthorizeAsync(User,
                                                                Permissions.ViewBannedUsers))
                {
                    return(Unauthorized());
                }
            }

            // Return Url for authentication & canonical url purposes
            ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"]       = "Plato.Users",
                ["controller"] = "Home",
                ["action"]     = "Display",
                ["opts.id"]    = user != null ? user.Id.ToString() : "",
                ["opts.alias"] = user != null ? user.Alias : ""
            });;

            // Build page title
            _pageTitleBuilder.AddSegment(S[user.DisplayName], int.MaxValue);

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Users"], discuss => discuss
                                  .Action("Index", "Home", "Plato.Users")
                                  .LocalNav()
                                  ).Add(S[user.DisplayName]);
            });

            // Add user to context
            HttpContext.Items[typeof(User)] = user;

            // Build view model
            var viewModel = new ProfilePage()
            {
                Id = user.Id
            };

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideDisplayAsync(viewModel, this)));
        }