Exemplo n.º 1
0
        public async Task <ActionResult <UserToken> > CreateUserTaller(UserTallerInfo model)
        {
            var validationInfo = await ValidateInfoUserTaller(model);

            if (validationInfo.Codigo == HttpStatusCode.Found || validationInfo.Codigo == HttpStatusCode.BadRequest)
            {
                return(new UserToken
                {
                    Ok = false,
                    Message = validationInfo.Mensaje,
                    Codigo = validationInfo.Codigo
                });
            }
            else
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var BuscarUsuario = await _userManager.FindByNameAsync(model.UserName);

                    model.UserId = BuscarUsuario.Id;

                    var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap <UserTallerInfo, Taller>();
                    });
                    IMapper iMapper   = config.CreateMapper();
                    var     mappClass = iMapper.Map <UserTallerInfo, Taller>(model);

                    await _repository.CreatedAsync(mappClass);

                    return(BuildToken(new LoginInfo {
                        UserName = model.UserName, Password = model.Password
                    }));
                }
                else
                {
                    return(new UserToken
                    {
                        Ok = false,
                        Message = "Error al crear el usuario.",
                        Codigo = HttpStatusCode.BadRequest
                    });
                }
            }
        }
Exemplo n.º 2
0
        private async Task <Request <bool> > ValidateInfoUserTaller(UserTallerInfo model)
        {
            var passwordValidator = new PasswordValidator <ApplicationUser>();
            var _request          = new Request <bool>();
            //Valida si el email existe
            var validateEmail = await _userManager.FindByEmailAsync(model.Email);

            //valida si el password cumple con lo requerido
            var validatePassword = await passwordValidator.ValidateAsync(_userManager, null, model.Password);

            //Valida si el Usuario existe
            var validateUsername = await _userManager.FindByNameAsync(model.UserName);

            if (validateUsername == null)
            {
                if (validateEmail == null)
                {
                    if (!validatePassword.Succeeded)
                    {
                        _request.Codigo  = HttpStatusCode.BadRequest;
                        _request.Mensaje = "Su contraseña debe tener almenos una letra mayuscula, un numero y un caracter extraño.";
                    }
                    else
                    {
                        _request.Codigo = HttpStatusCode.Continue;
                    }
                }
                else
                {
                    _request.Codigo  = HttpStatusCode.Found;
                    _request.Mensaje = "El correo que intenta registrar ya existe.";
                }
            }
            else
            {
                _request.Codigo  = HttpStatusCode.Found;
                _request.Mensaje = "El usuario que intenta registrar ya existe.";
            }

            return(_request);
        }
 public async Task <ActionResult <UserToken> > CreateUserTaller([FromBody] UserTallerInfo model)
 {
     return(await _logica.CreateUserTaller(model));
 }