public async Task <IActionResult> Post([FromBody] AppUserRegisterCommandInputDTO input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = new AppUser
            {
                Email      = input.Email,
                UserName   = input.UserName,
                FirstName  = input.FirstName,
                LastName   = input.LastName,
                PictureUrl = input.PictureUrl
            };

            var result = await this.UserManager.CreateAsync(userIdentity, input.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }


            return(new OkObjectResult("Account created"));
        }
Ejemplo n.º 2
0
        public OperationResponse <AppUserRegisterCommandOutputDTO> Execute(AppUserRegisterCommandInputDTO input)
        {
            using (var dbContextScope = this.DbContextScopeFactory.Create())
            {
                this.FormatData(input);

                var result = new OperationResponse <AppUserRegisterCommandOutputDTO>().AddValidationResult(this.Validator.Validate(input));
                if (!result.IsSucceed)
                {
                    return(result);
                }

                var    internalInput = input.Clone() as AppUserRegisterCommandInputDTO;
                byte[] passwordHash, passwordSalt;
                HashHelper.CreatePasswordHash(internalInput.Password, out passwordHash, out passwordSalt);

                internalInput.PasswordHash = passwordHash;
                internalInput.PasswordSalt = passwordSalt;

                return(this.Repository.Insert(internalInput));
            }
        }
Ejemplo n.º 3
0
 private void FormatData(AppUserRegisterCommandInputDTO input)
 {
     input.NormalizedEmail = InternetFieldNormalization.NormalizeEmail(input.Email);
 }