Ejemplo n.º 1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var userId = _currentUserService.GetUserName();
            var user   = await _userService.GetUserDetails(userId);

            return(View(user));
        }
Ejemplo n.º 2
0
        // GET: User/Edit/5
        public async Task <IActionResult> Edit(string userId)
        {
            if (userId == null || userId == "")
            {
                return(NotFound());
            }
            var currentUserId = _currentUser.GetUserName();
            var model         = await _userService.GetUserDetailsVM(userId, currentUserId);

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

            return(View(model));
        }
            /// <summary>
            /// Called asynchronously before the action, after model binding is complete.
            /// </summary>
            /// <param name="context">A context for action filters</param>
            /// <returns>A task that on completion indicates the necessary filter actions have been executed</returns>
            private async Task ValidatePasswordAsync(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                if (context.HttpContext.Request == null)
                {
                    return;
                }


                //get action and controller names
                var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
                var actionName       = actionDescriptor?.ActionName;
                var controllerName   = actionDescriptor?.ControllerName;

                if (string.IsNullOrEmpty(actionName) || string.IsNullOrEmpty(controllerName))
                {
                    return;
                }

                //don't validate on the 'Change Password' endpoint
                if (controllerName.Equals("Identity", StringComparison.InvariantCultureIgnoreCase) &&
                    actionName.Equals("ChangePassword", StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                //don't validate on the 'Login' endpoint
                if (controllerName.Equals("Identity", StringComparison.InvariantCultureIgnoreCase) &&
                    actionName.Equals("Login", StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                //check password expiration
                var user = _currentUserService.CurrentUser;

                if (user == null)
                {
                    return;
                }

                if (!await _userManager.HasPasswordExpiredAsync(user))
                {
                    return;
                }

                //return an error
                var response = new ErrorResponse()
                {
                    Code    = "PasswordExpired",
                    Message = $"{_currentUserService.GetUserName()} Requires Password Change"
                };

                context.Result = new ForbiddenObjectResult(response);
            }
Ejemplo n.º 4
0
        public async Task <SendMessageResponse> SaveMessage(SendMessageRequest messageDto)
        {
            try
            {
                var message = new Message {
                    Text = messageDto.Text, Date = DateTime.Now, UserId = new Guid(_currentUserService.GetUserId()), UserName = _currentUserService.GetUserName(), To = messageDto.To
                };

                await _context.Messages.AddAsync(message);

                await _context.SaveChangesAsync();

                return(new SendMessageResponse {
                    Success = true
                });
            }
            catch (Exception)
            {
                return(new SendMessageResponse {
                    Success = false, Error = "An error ocurred"
                });
            }
        }