private Users MapearUser(UsersInputModel usersInput) { var user = new Users { UserName = usersInput.UserName, Password = usersInput.Password, TipoUsuario = usersInput.TipoUsuario, }; return(user); }
public ActionResult <UsersViewModel> Login([FromBody] UsersInputModel model) { var user = _usersService.Validate(model.UserName, model.Password); if (user != null) { var response = _jwtService.GenerateToken(user); response.Estado = user.Estado; response.TipoUsuario = user.TipoUsuario; return(Ok(response)); } return(BadRequest("Usuario o clave es incorrecta")); }
public ActionResult <UsersViewModel> Post(UsersInputModel userInput) { Users user = MapearUser(userInput); user.FirstName = "xxxx"; user.LastName = "xxxx"; user.Estado = "AC"; var response = _UserService.Guardar(user); if (response.Error) { ModelState.AddModelError("Guardar user", response.Mensaje); var problemDetails = new ValidationProblemDetails(ModelState) { Status = StatusCodes.Status400BadRequest, }; return(BadRequest(problemDetails)); } return(Ok(response.Users)); }
public HttpResponse Register(UsersInputModel input) { if (string.IsNullOrEmpty(input.Username) || input.Username.Length < 5 || input.Username.Length > 20) { return(this.Error("Username should be between 5 and 20 characters.")); } if (!this.usersService.IsUsernameAvailable(input.Username)) { return(this.Error("Username is already taken.")); } if (string.IsNullOrEmpty(input.Email) || !new EmailAddressAttribute().IsValid(input.Email)) { return(this.Error("Invalid email address.")); } if (!this.usersService.IsEmailAvailable(input.Email)) { return(this.Error("Email is already taken.")); } if (string.IsNullOrEmpty(input.Password) || input.Password.Length < 6 || input.Password.Length > 20) { return(this.Error("Password should be between 6 and 20 characters.")); } if (input.Password != input.ConfirmPassword) { return(this.Error("Passwords do not match.")); } this.usersService.CreateUser(input.Username, input.Email, input.Password); return(this.Redirect("/Users/Login")); }
public UsersModel CreateUsers(UsersInputModel usersInputModel) { return(Post <UsersModel, UsersInputModel>("core_user_create_users", usersInputModel)); }