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); }
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); }
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); }
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)); } }
public async Task <IActionResult> SetLoginPassword([FromForm] SetPasswordCommand command) { var result = await _mediator.Send(command); return(Ok(result)); }