Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added images/1047883_1711005940.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1047883_1711005940.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/104992_1711005934.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/104992_1711005934.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1219149_1711005919.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1219149_1711005919.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1311078_1711005805.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1311078_1711005805.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1338480_1711005954.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1338480_1711005954.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1396687_1711005696.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1396687_1711005696.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1405959_1711005703.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1405959_1711005703.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1435343_1711005913.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1435343_1711005913.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005829_bez-nazvanija.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005829_bez-nazvanija.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005866_180266.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005866_180266.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1993_1711005947.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1993_1711005947.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/2213_1711005981.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/2213_1711005981.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/403_1711005928.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/403_1711005928.webp
Binary file added images/4482093_1711005725.png
Binary file added images/4482093_1711005725.webp
Binary file added images/4511631_1711005878.png
Binary file added images/4511631_1711005878.webp
Binary file added images/4540126_1711005740.png
Binary file added images/4540126_1711005740.webp
Binary file added images/4878248_1711005974.png
Binary file added images/4878248_1711005974.webp
Binary file added images/5024491_1711005884.png
Binary file added images/5024491_1711005884.webp
Binary file added images/5120138_1711005811.png
Binary file added images/5120138_1711005811.webp
Binary file added images/5144406_1711005839.png
Binary file added images/5144406_1711005839.webp
Binary file added images/5364708_1711005849.png
Binary file added images/5364708_1711005849.webp
Binary file added images/5437562_1711005900.png
Binary file added images/5437562_1711005900.webp
Binary file added images/804476_1711005789.png
Binary file added images/804476_1711005789.webp
Binary file added images/817324_1711005962.png
Binary file added images/817324_1711005962.webp
Binary file added images/891578_1711005797.png
Binary file added images/891578_1711005797.webp
Binary file added images/913425_1711005908.png
Binary file added images/913425_1711005908.webp
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@
</properties>

<dependencies>
<dependency>
<!-- jsoup HTML parser library @ https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.17.2</version>
</dependency>

<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.36.0.3</version> <!-- Укажите актуальную версию -->
</dependency>

<!-- https://mvnrepository.com/artifact/org.sejda.imageio/webp-imageio -->
<dependency>
<groupId>org.sejda.imageio</groupId>
<artifactId>webp-imageio</artifactId>
<version>0.1.6</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/mdkefir/filmlibrary/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.mdkefir.filmlibrary;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Database {
public static Connection connect() {
String url = "jdbc:sqlite:src/main/java/com/mdkefir/filmlibrary/filmlibrary.db"; // Укажите путь к вашей базе данных
Connection conn = null;
try {
conn = DriverManager.getConnection(url);
} catch (Exception e) {
System.out.println(e.getMessage());
}
return conn;
}

public static void createNewDatabase() {
try (Connection conn = connect()) {
if (conn != null) {
Statement stmt = conn.createStatement();
// Создание таблицы пользователей
/*stmt.execute("DROP TABLE users");*/
stmt.execute("CREATE TABLE IF NOT EXISTS users (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"username TEXT NOT NULL UNIQUE," +
"password TEXT NOT NULL," +
"secret_code TEXT);");

/*stmt.execute("DROP TABLE favorites");*/
// Создание таблицы избранных фильмов
stmt.execute("CREATE TABLE IF NOT EXISTS favorites (" +
"user_id INTEGER," +
"title TEXT," +
"year TEXT," +
"rating TEXT," +
"image_path TEXT," +
"FOREIGN KEY(user_id) REFERENCES users(id));");

// Создание таблицы друзей
stmt.execute("CREATE TABLE IF NOT EXISTS friends (" +
"user_id INTEGER," +
"friend_id INTEGER," +
"FOREIGN KEY(user_id) REFERENCES users(id)," +
"FOREIGN KEY(friend_id) REFERENCES users(id));");

System.out.println("Таблицы созданы");
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

public static void main(String[] args) {
createNewDatabase(); // Создание базы данных и таблиц при запуске
}
}

3 changes: 1 addition & 2 deletions src/main/java/com/mdkefir/filmlibrary/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javafx.scene.paint.Color;
import javafx.stage.Stage;


public class Main extends Application {
public static void main(String[] args) {
launch(args);
Expand All @@ -17,7 +16,7 @@ public static void main(String[] args) {
@Override
public void start(Stage primaryStage) {
try {
primaryStage.setMinWidth(920);
primaryStage.setMinWidth(925);
primaryStage.setMinHeight(620);
Button closeButton = new Button("Закрыть");
closeButton.setOnAction(e -> primaryStage.close());
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/com/mdkefir/filmlibrary/controllers/AuthController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.mdkefir.filmlibrary.controllers;

import com.mdkefir.filmlibrary.Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class AuthController {
private Database db;

public AuthController() {
db = new Database(); // Предполагается, что у вас есть класс Database для работы с базой данных
}

public boolean registerUser(String username, String password) {
String sql = "INSERT INTO users (username, password) VALUES (?, ?)";
try (Connection conn = db.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, username);
pstmt.setString(2, password); // В реальном приложении пароль следует хранить в зашифрованном виде
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
}

public boolean loginUser(String username, String password) {
String sql = "SELECT * FROM users WHERE username = ? AND password = ?";
try (Connection conn = db.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, username);
pstmt.setString(2, password);
ResultSet rs = pstmt.executeQuery();
return rs.next(); // Возвращает true, если пользователь найден
} catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
}

public int getUserId(String username) {
String sql = "SELECT id FROM users WHERE username = ?";
try (Connection conn = db.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, username);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
return rs.getInt("id");
}
} catch (SQLException e) {
System.out.println("Ошибка получения ID пользователя: " + e.getMessage());
}
return -1; // Возвращаем -1, если пользователь не найден
}

public boolean addFriend(int userId, String friendName, String secretCode) {
String sql = "INSERT INTO friends (user_id, friend_id) VALUES (?, ?)";
try (Connection conn = db.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, userId);
pstmt.setString(2, friendName);
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
System.out.println("Ошибка добавления друга: " + e.getMessage());
return false;
}
}

public boolean deleteFriend(int userId, String friendName) {
String sql = "DELETE FROM friends WHERE user_id = ? AND friend_name = ?";
try (Connection conn = db.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, userId);
pstmt.setString(2, friendName);
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
System.out.println("Ошибка удаления друга: " + e.getMessage());
return false;
}
}

public List<String> getFriends(int userId) {
List<String> friends = new ArrayList<>();
String sql = "SELECT friend_id FROM friends WHERE user_id = ?";
try (Connection conn = db.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, userId);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
friends.add(rs.getString("friend_name"));
}
} catch (SQLException e) {
System.out.println("Ошибка получения списка друзей: " + e.getMessage());
}
return friends;
}

}
Loading