public IActionResult Login([FromBody] UserInfo userInfo) { if (ModelState.IsValid) { User userAuth = new User(); string ePass = ManageKeys.GetSHA256(userInfo.Password); string passadmin = this._configuration.GetValue(typeof(string), "passadmin").ToString(); if ((userInfo.Email == "admin") && (passadmin == ePass)) { userAuth.Rol = "A"; userAuth.Email = "admin"; return(BuildToken(userAuth)); } userAuth = this._userRepository.GetUsers().Where(p => p.Email == userInfo.Email && p.Password == ePass).FirstOrDefault(); if (userAuth != null) { return(BuildToken(userAuth)); } return(Unauthorized()); } else { return(BadRequest(ModelState)); } }
public IActionResult Create([FromBody] User user) { //Validate email unique int cant = this._userRepository.GetUsers().Where(p => p.Email == user.Email).Count(); if (cant > 0) { return(BadRequest(new { ok = false, message = "El email debe ser único" })); } user.Password = ManageKeys.GetSHA256(user.Password); bool res = this._userRepository.CreateUser(user); return(Ok(new { ok = true, message = "Usuario creado" })); }