up
This commit is contained in:
@@ -5,6 +5,7 @@ import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.sqlclient.Pool;
|
||||
import io.vertx.sqlclient.Row;
|
||||
import io.vertx.sqlclient.Tuple;
|
||||
import io.vertx.sqlclient.templates.SqlTemplate;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
|
||||
@@ -66,6 +67,21 @@ public class UserService {
|
||||
.execute(Map.of("id", id, "active", active)).mapEmpty();
|
||||
}
|
||||
|
||||
public Future<JsonObject> findByLoginOrEmail(String loginOrEmail) {
|
||||
String sql = "SELECT id, login, email, password, active, ip, created, updated FROM users WHERE login = ? OR email = ?";
|
||||
return pool.preparedQuery(sql)
|
||||
.execute(Tuple.of(loginOrEmail, loginOrEmail))
|
||||
.map(rows -> {
|
||||
if (rows.size() == 0) {
|
||||
System.out.println("User not found: " + loginOrEmail);
|
||||
return null;
|
||||
}
|
||||
Row row = rows.iterator().next();
|
||||
System.out.println("User found, active=" + row.getBoolean("active"));
|
||||
return toJson(row);
|
||||
});
|
||||
}
|
||||
|
||||
public Future<JsonObject> findByEmail(String email) {
|
||||
return SqlTemplate.forQuery(pool, "SELECT id, login, email, password, active, ip, created, updated FROM users WHERE email = #{email}")
|
||||
.mapTo(this::toJson)
|
||||
@@ -94,7 +110,16 @@ public class UserService {
|
||||
.execute()
|
||||
.map(rows -> {
|
||||
JsonArray array = new JsonArray();
|
||||
rows.forEach(row -> array.add(toJson(row)));
|
||||
for (Row row : rows) {
|
||||
array.add(new JsonObject()
|
||||
.put("id", row.getInteger("id"))
|
||||
.put("login", row.getString("login"))
|
||||
.put("email", row.getString("email"))
|
||||
.put("active", row.getBoolean("active"))
|
||||
.put("ip", row.getString("ip"))
|
||||
.put("created", row.getLocalDateTime("created") != null ? row.getLocalDateTime("created").toString() : null)
|
||||
.put("updated", row.getLocalDateTime("updated") != null ? row.getLocalDateTime("updated").toString() : null));
|
||||
}
|
||||
return array;
|
||||
});
|
||||
}
|
||||
@@ -135,6 +160,7 @@ public class UserService {
|
||||
.put("id", row.getInteger("id"))
|
||||
.put("login", row.getString("login"))
|
||||
.put("email", row.getString("email"))
|
||||
.put("password", row.getString("password")) // ← ДОБАВИТЬ ЭТУ СТРОКУ
|
||||
.put("active", row.getBoolean("active"))
|
||||
.put("ip", row.getString("ip"))
|
||||
.put("created", row.getLocalDateTime("created") != null ? row.getLocalDateTime("created").toString() : null)
|
||||
|
||||
Reference in New Issue
Block a user