Пример #1
0
        public async Task <IActionResult> Register([FromBody] UserForRegisterDto UserForRegisterDto)
        {
            // Validar el request

            UserForRegisterDto.Email = UserForRegisterDto.Email.ToLower();

            if (await _repo.EmailExists(UserForRegisterDto.Email))
            {
                ModelState.AddModelError("Email", "Email ya registrado");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userToCreate = new UsuariosDASHBOARDMIAUTO
            {
                Nombre_Usuario     = UserForRegisterDto.Nombre,
                Correo_Electronico = UserForRegisterDto.Email
            };

            var createUser = await _repo.Register(userToCreate, UserForRegisterDto.Password);



            return(Ok(new { usuarioCreado = createUser.Nombre_Usuario }));
        }
Пример #2
0
        public async Task <UsuariosDASHBOARDMIAUTO> Register(UsuariosDASHBOARDMIAUTO usuario, string password)
        {
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            usuario.PasswordHash = passwordHash;
            usuario.PasswordSalt = passwordSalt;

            await _context.Users.AddAsync(usuario);

            await _context.SaveChangesAsync();

            return(usuario);
        }