Fixed structure of UI, Added some logic to Auth

This commit is contained in:
maciejrusek
2026-04-28 20:33:08 +02:00
parent f306606b34
commit 54c7bb47b5
9 changed files with 150 additions and 53 deletions

View File

@@ -6,6 +6,7 @@ import java.util.Optional;
public interface UserRepository {
Optional<User> getUser(String username, String password);
Boolean userExists(String username);
Optional<User> saveUser(String username, String email, String password);
boolean deleteUser(int userId);
}

View File

@@ -27,6 +27,9 @@ public class UserRepositoryJdbc implements UserRepository {
preparedStatement.setString(1, username);
ResultSet resultSet = preparedStatement.executeQuery();
if (!resultSet.next()) {
return Optional.empty();
}
String passwordFromDB = resultSet.getString("password");
String emailFromDB = resultSet.getString("email");
@@ -43,6 +46,28 @@ public class UserRepositoryJdbc implements UserRepository {
}
}
@Override
public Boolean userExists(String username) {
try {
PreparedStatement preparedStatement = connection.prepareStatement(
"SELECT * FROM users WHERE name=(?);"
);
preparedStatement.setString(1, username);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
return true;
}
return false;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public Optional<User> saveUser(String username, String email, String password) {
try {