public async Task <IActionResult> RegByEmail( [FromBody] RegEmailBinding binding, [FromServices] UserRegistrarService registrar, [FromServices] IUserRegistrationRepository repository, CancellationToken cancellationToken) { try{ var user = await registrar.CreateByEmail( id : binding.Id, guildId : binding.GuildId, password : binding.Password.Trim(), email : binding.Email, name : binding.Name, cancellationToken : cancellationToken ); registrar.ResendConfirmationCode(user); await repository.Save(user, cancellationToken); return(NoContent()); } catch (UserAlreadyExistsException) { throw new ApiException(HttpStatusCode.Conflict, ErrorCodes.GamerAlreadyExists, "Gamer already exists"); } }
public async Task <IActionResult> ConfirmEmail( [FromQuery] ConfirmationCodeBinding binding, [FromServices] UserRegistrarService registrar, [FromServices] IUserRegistrationRepository repository, CancellationToken cancellationToken) { try{ var user = await registrar.Confirm(binding.ConfirmationCode, cancellationToken); await repository.Save(user, cancellationToken); } catch (InvalidOperationException) { throw new ApiException(HttpStatusCode.Forbidden, ErrorCodes.Forbidden, ""); } return(NoContent()); }
public async Task <IActionResult> AddNewGamer( [FromBody] GamerCreateBinding binding, [FromServices] Domain.UserRegistration.IUserRegistrationRepository userRepository, [FromServices] UserRegistrarService gamerFactory, CancellationToken cancellationToken) { try{ var user = await gamerFactory.Create(binding.Id, HttpContext.GetGuildId(), binding.Login, binding.Name, binding.DateOfBirth, binding.Rank, binding.Status, cancellationToken); await userRepository.Save(user, cancellationToken); return(Ok(new { })); } catch (UserAlreadyExistsException) { throw new ApiException(HttpStatusCode.Conflict, ErrorCodes.GamerAlreadyExists, "Gamer already exists"); } }