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
53 changes: 28 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
plugins {
id 'java'
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.12'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
id 'java'
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.12'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
}

group 'AP.Restaurant'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
mavenCentral()
}

ext {
junitVersion = '5.10.2'
junitVersion = '5.10.2'
}

sourceCompatibility = '23'
targetCompatibility = '23'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.encoding = 'UTF-8'
}

application {
mainModule = 'ap.restaurant.restaurant'
mainClass = 'ap.restaurant.restaurant.HelloApplication'
mainModule = 'ap.restaurant.restaurant'
mainClass = 'ap.restaurant.restaurant.HelloApplication'
}

javafx {
version = '17.0.6'
modules = ['javafx.controls', 'javafx.fxml']
version = '21.0.7'
modules = ['javafx.controls', 'javafx.fxml']
}

dependencies {

testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}

test {
useJUnitPlatform()}
useJUnitPlatform()
}

jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}

jlinkZip {
group = 'distribution'
}
group = 'distribution'
}
8 changes: 8 additions & 0 deletions src/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions src/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions src/.idea/modules.xml

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

6 changes: 6 additions & 0 deletions src/.idea/vcs.xml

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

42 changes: 42 additions & 0 deletions src/main/java/ap/restaurant/restaurant/Authenticate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ap.restaurant.restaurant;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

import static ap.restaurant.restaurant.User.users;

public class Authenticate {
private String username;
private String password;
Scanner sc = new Scanner(System.in);

public User signin() {
int id = (int)(Math.random() * 900) + 100;
System.out.println("your id: " + id);
System.out.println("Enter username: ");
String username = sc.nextLine();
System.out.println("Enter password: ");
String password = sc.nextLine();
System.out.println("Enter email: ");
String email = sc.nextLine();

User user = new User(id, username, password, email);
users.add(user);
System.out.println("ُSign in successful");
return user;
}


public void login(User user) {
if (users.contains(user)) {
System.out.println("You are logged in!");
}
}
}
12 changes: 5 additions & 7 deletions src/main/java/ap/restaurant/restaurant/HelloApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
public void start(Stage stage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("login.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 400, 300);
stage.setTitle("AMD Restaurant");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch();
}
}
}
79 changes: 79 additions & 0 deletions src/main/java/ap/restaurant/restaurant/LoginController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ap.restaurant.restaurant;

import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.fxml.FXMLLoader;

import java.io.IOException;
import java.sql.*;

public class LoginController {
@FXML private TextField usernameField;
@FXML private PasswordField passwordField;
@FXML private TextField emailField;
@FXML private Label messageLabel;

private final String url = "jdbc:postgresql://localhost:5432/Restaurant";
private final String dbUser = "postgres";
private final String dbPassword = "AmirMahdiImani";

@FXML
protected void onSignUp() {
String username = usernameField.getText();
String password = passwordField.getText();
String email = emailField.getText();

if (username.isEmpty() || password.isEmpty() || email.isEmpty()) {
messageLabel.setText("Please fill all fields.");
return;
}

int id = (int)(Math.random() * 9000 + 1000);

try (Connection conn = DriverManager.getConnection(url, dbUser, dbPassword)) {
String insert = "INSERT INTO users (id, username, password, email) VALUES (?, ?, ?, ?)";
try (PreparedStatement stmt = conn.prepareStatement(insert)) {
stmt.setInt(1, id);
stmt.setString(2, username);
stmt.setString(3, password);
stmt.setString(4, email);
stmt.executeUpdate();
messageLabel.setText("Signup successful!");
}
} catch (SQLException e) {
messageLabel.setText("Error: " + e.getMessage());
}
}

@FXML
protected void onLogin() {
String username = usernameField.getText();
String password = passwordField.getText();

try (Connection conn = DriverManager.getConnection(url, dbUser, dbPassword)) {
String query = "SELECT * FROM users WHERE username = ? AND password = ?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setString(1, username);
stmt.setString(2, password);
ResultSet rs = stmt.executeQuery();

if (rs.next()) {
int userId = rs.getInt("id");
FXMLLoader loader = new FXMLLoader(getClass().getResource("menu.fxml"));
Scene menuScene = new Scene(loader.load());
MenuController controller = loader.getController();
controller.setUserId(userId);

Stage stage = (Stage) usernameField.getScene().getWindow();
stage.setScene(menuScene);
} else {
messageLabel.setText("Invalid login.");
}
}
} catch (SQLException | IOException e) {
messageLabel.setText("Error: " + e.getMessage());
}
}
}
Loading