Fixed structure of UI, Added some logic to Auth
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user