Exemple #1
0
        public async Task <bool> CreatePasswordAsync(SetPasswordCommand request)
        {
            var user = await _userManager.FindByNameAsync(request.Username);

            var hasPassword = await _userManager.HasPasswordAsync(user);

            if (hasPassword)
            {
                /*
                 * DO NOT display the reason.
                 * if this happen is because userId are trying to hack.
                 */
                throw new Exception("Unknown error");
            }

            var result = await _userManager.AddPasswordAsync(user, request.Password);

            if (result.Succeeded)
            {
                return(true);
            }

            foreach (var error in result.Errors)
            {
                await _bus.RaiseEvent(new DomainNotification(result.ToString(), error.Description));
            }

            return(false);
        }
Exemple #2
0
        public HttpResponseMessage Post(SetPasswordCommand command)
        {
            string authToken = Request.GetAuthToken();

            command.UserId = m_TokenProvider.ValidateAuthorizationToken(authToken);

            m_SetPasswordHandler.Handle(command);

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Accepted, command.UserId);

            return(response);
        }
Exemple #3
0
        public void Handle(SetPasswordCommand command)
        {
            UserInfo query = new UserInfo();

            query.Id = command.UserId;

            UserInfo userData = m_UserRepository.Get(query);

            userData.PasswordHash    = GetUserPasswordHash(command.Password, userData.Id);
            userData.UpdatedDateTime = DateTime.UtcNow;

            m_UserRepository.Add(userData);
        }
Exemple #4
0
        public async Task Handle(SetPasswordCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return;
            }

            var result = await _userService.CreatePasswordAsync(request);

            if (result)
            {
                await Bus.RaiseEvent(new PasswordCreatedEvent(request.Id.Value));
            }
        }
Exemple #5
0
        public async Task <IActionResult> SetLoginPassword([FromForm] SetPasswordCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(result));
        }