Exemplo n.º 1
0
        public async Task <IActionResult> Registration(
            CancellationToken cancellationToken,
            [FromBody] RegistrationBinding binding,
            [FromServices] IUserRepository userRepository,
            [FromServices] UserRegistrationService registrationService)
        {
            var user = await userRepository.FindByLogin(binding.Login, cancellationToken);

            if (user != null)
            {
                return(Conflict());
            }
            user = await registrationService.CreateUser(binding.Email,
                                                        binding.Login, binding.Password, 1, binding.NumberPhone,
                                                        DateTime.Now, DateTime.Now, binding.FirstName, binding.LastName,
                                                        binding.MiddleName, binding.Hobby, binding.DateOfBirth, (AuthType)binding.AuthTypeBinding, cancellationToken);

            try
            {
                await userRepository.Save(user);

                return(NoContent());
            }
            catch (DbUpdateException exception)
                when(((Npgsql.PostgresException)exception.InnerException)?.SqlState == "23505")
                {
                    return(Conflict());
                }
        }
        public async Task <IActionResult> Registration(
            CancellationToken cancellationToken,
            [FromForm] RegistrationBinding binding,
            [FromServices] IUserRepository userRepository,
            [FromServices] UserRegistrationService registrationService)
        {
            var user = await userRepository.FindByEmail(binding.Email, cancellationToken);

            if (user != null)
            {
                if (user.EmailState == EmailState.Unconfirmed)
                {
                    return(NoContent());
                }
                return(Conflict());
            }

            user = await registrationService.CreateUser(binding.Email, binding.Password, cancellationToken);

            try
            {
                await userRepository.Save(user);

                return(NoContent());
            }
            catch (DbUpdateException exception)
                when(((Npgsql.PostgresException)exception.InnerException)?.SqlState == "23505")  // 23505 unique_violation
                {
                    return(Conflict());
                }
        }
 public override void Handle(AuthUserCreated evt)
 {
     _userRegistrationService.CreateUser(evt.UserId, evt.Username);
 }