public IHttpActionResult changePassword(LoginRequest login) { try { byte[] data = System.Convert.FromBase64String(login.Password); BOGnUsuar bo = new BOGnUsuar(); var identity = Thread.CurrentPrincipal.Identity; return(Ok(bo.SetNewPassword(identity.Name, System.Text.ASCIIEncoding.ASCII.GetString(data), login.Username))); } catch (Exception ex) { return(Ok(new TOTransaction() { Retorno = 1, TxtError = ex.Message })); } }
public IHttpActionResult ForgetPassword(LoginRequestForgetPassword login) { try { string link = ConfigurationManager.AppSettings["JWT_TRANSACT_SITE"]; if (string.IsNullOrEmpty(link)) { throw new Exception("Llave JWT_TRANSACT_SITE no parametrizada.Contacte con su administrador de la configuración"); } BOGnUsuar bo = new BOGnUsuar(); if (login == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } bool isCredentialValid = bo.GnUsuarAutenticate(login.Username, login.Password).Retorno == 0; if (isCredentialValid) { if (string.IsNullOrEmpty(login.LoginUser)) { throw new Exception("El usuario a restaurar no puede estar vacío"); } var token = TokenGenerator.GenerateTokenJwt(login.LoginUser); bo.SendMailForgetPasswordToUser(login.LoginUser, token, link); return(Ok(new TOTransaction() { Retorno = 0, TxtError = "" })); } else { return(Ok(new TOTransaction() { Retorno = 1, TxtError = string.Format("Credenciales para el usuario {0} no válidas", login.Username) })); } } catch (Exception ex) { return(Ok(new TOTransaction() { TxtError = ex.Message, Retorno = 1 })); } }
public IHttpActionResult Authenticate(LoginRequest login) { if (login == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } bool isCredentialValid = new BOGnUsuar().GnUsuarAutenticate(login.Username, login.Password).Retorno == 0; if (isCredentialValid) { var token = TokenGenerator.GenerateTokenJwt(login.Username); return(Ok(token)); } else { return(Unauthorized()); } }