public String createDeveloper(Developer developer) { StringBuffer sql = new StringBuffer(); String key = UUID.randomUUID().toString(); // encriptar password PasswordEncoder encoder = new Md5PasswordEncoder(); String hashedPass = encoder.encodePassword(developer.getPassword(), null); sql.append("INSERT INTO developers "); sql.append("(username, password, email, key) "); sql.append("VALUES "); sql.append("(?, ?, ?, ?)"); Object[] parametros; int[] types; parametros = new Object[] {developer.getUsername(), hashedPass, developer.getEmail(), key}; types = new int[] {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}; if (jdbcTemplate.update(sql.toString(), parametros, types) == 1) { return key; } else { return "-1"; } }
public Integer updateDeveloperCert(Developer developer) { StringBuffer sql = new StringBuffer(); Object[] parametros = new Object[0]; int[] types = new int[0]; sql.append("UPDATE developers "); sql.append("SET "); if (developer.getCertURL() != null) { sql.append("certurl = ?"); parametros = addToObjectArray(parametros, developer.getCertURL()); types = addToIntArray(types, Types.VARCHAR); } String username = SecurityContextHolder.getContext().getAuthentication().getName(); sql.append("WHERE username = ?"); parametros = addToObjectArray(parametros, username); types = addToIntArray(types, Types.VARCHAR); System.out.println("jdbcTemplate " + jdbcTemplate.update(sql.toString(), parametros, types)); if (jdbcTemplate.update(sql.toString(), parametros, types) == 1) { Developer dev = getDeveloperByUsername(username); createCert(developer.getCertURL(), dev.getKey()); return 1; } else { return -1; } }
public Integer updateDeveloper(Developer developer) { StringBuffer sql = new StringBuffer(); Object[] parametros = new Object[0]; int[] types = new int[0]; sql.append("UPDATE developers "); sql.append("SET "); if (developer.getEndpoint() != null) { sql.append("endpoint = ?"); parametros = addToObjectArray(parametros, developer.getEndpoint()); types = addToIntArray(types, Types.VARCHAR); } String username = SecurityContextHolder.getContext().getAuthentication().getName(); sql.append("WHERE username = ?"); parametros = addToObjectArray(parametros, username); types = addToIntArray(types, Types.VARCHAR); // parametros = new Object[] { developer.getCallback_url(), username }; // types = new int[] { Types.VARCHAR, Types.VARCHAR }; if (jdbcTemplate.update(sql.toString(), parametros, types) == 1) { return 1; } else { return -1; } }