-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: System can now make a user (+ Fxml for login and register and c…
…ontroller for register). Login needs handling
- Loading branch information
AdrianBalunan
committed
Apr 16, 2026
1 parent
adbed95
commit 33505ee
Showing
6 changed files
with
171 additions
and
332 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...ication/src/main/java/ntnu/systemutvikling/team6/controller/CreateUserPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package ntnu.systemutvikling.team6.controller; | ||
|
|
||
| import javafx.event.ActionEvent; | ||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.Alert; | ||
| import javafx.scene.control.PasswordField; | ||
| import javafx.scene.control.TextField; | ||
| import ntnu.systemutvikling.team6.controller.components.BaseController; | ||
| import ntnu.systemutvikling.team6.controller.components.FooterController; | ||
| import ntnu.systemutvikling.team6.controller.components.LoaderScene; | ||
| import ntnu.systemutvikling.team6.controller.components.NavbarController; | ||
|
|
||
|
|
||
|
|
||
| public class CreateUserPageController extends BaseController { | ||
| @FXML | ||
| private NavbarController navbarController; | ||
| @FXML | ||
| private FooterController footerController; | ||
|
|
||
| @FXML private TextField firstNameField; | ||
| @FXML private TextField lastNameField; | ||
| @FXML private TextField emailField; | ||
| @FXML private PasswordField passwordField; | ||
| @FXML private PasswordField confirmPasswordField; | ||
|
|
||
|
|
||
| @Override | ||
| protected void authTokenisSet() { | ||
| if (isLoggedin()){ | ||
| LoaderScene.LoadScene("frontPage", new ActionEvent(), null, null, authToken); | ||
| } | ||
| navbarController.setAuthToken(authToken); | ||
| footerController.setAuthToken(authToken); | ||
| } | ||
|
|
||
| @FXML | ||
| private void handleCreateAccount(ActionEvent event){ | ||
| String firstNameText = firstNameField.getText(); | ||
| String lastNameText = lastNameField.getText(); | ||
| String emailText = emailField.getText(); | ||
| String password = passwordField.getText(); | ||
| String confirmPassword = confirmPasswordField.getText(); | ||
|
|
||
| if (firstNameText.isBlank() || lastNameText.isBlank() || emailText.isBlank() || password.isBlank() || confirmPassword.isBlank()) { | ||
| showAlert(Alert.AlertType.ERROR, "Empty input", "Please fill out all fields"); | ||
| return; | ||
| } | ||
|
|
||
| if (emailText == null || emailText.isBlank() || !emailText.contains("@") || !emailText.contains(".")) { | ||
| showAlert(Alert.AlertType.ERROR, "Invalid Email", "Please enter a valid email"); | ||
| return; | ||
| } | ||
|
|
||
| if (!password.equals(confirmPassword)) { | ||
| showAlert(Alert.AlertType.ERROR, "Mismatch of password", "Password do not match"); | ||
| return; | ||
| } | ||
|
|
||
| // Now login | ||
| boolean loginSuccess; | ||
| try { | ||
| String username = firstNameText + " " + lastNameText; | ||
| loginSuccess = authToken.register(username,emailText, confirmPassword); | ||
| } catch (IllegalArgumentException e) { | ||
| showAlert(Alert.AlertType.ERROR, "Email already taken", "Email already taken by another user."); | ||
| return; | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred"); | ||
| return; | ||
|
|
||
| } | ||
| if (loginSuccess) { | ||
| showAlert( | ||
| Alert.AlertType.INFORMATION, | ||
| "Sign up sucsess", | ||
| "You have registered a new account! Please login with same credentials"); | ||
| LoaderScene.LoadScene("loginSite", event, null, null, authToken); | ||
| } | ||
| } | ||
| /** | ||
| * Show an JavaFx alert dialog with the specified type, title, and message. | ||
| * | ||
| * @param type | ||
| * @param title | ||
| * @param message | ||
| */ | ||
| private void showAlert(Alert.AlertType type, String title, String message) { | ||
| Alert alert = new Alert(type); | ||
| alert.setTitle(title); | ||
| alert.setHeaderText(null); | ||
| alert.setContentText(message); | ||
| alert.showAndWait(); | ||
| } | ||
| @FXML | ||
| private void switchToLoginPage(ActionEvent event){ | ||
| System.out.println("Click!"); | ||
| LoaderScene.LoadScene("loginSite", event, null, null, authToken); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...papplication/src/main/java/ntnu/systemutvikling/team6/controller/LoginPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package ntnu.systemutvikling.team6.controller; | ||
|
|
||
| import javafx.event.ActionEvent; | ||
| import javafx.fxml.FXML; | ||
| import ntnu.systemutvikling.team6.controller.components.BaseController; | ||
| import ntnu.systemutvikling.team6.controller.components.FooterController; | ||
| import ntnu.systemutvikling.team6.controller.components.LoaderScene; | ||
| import ntnu.systemutvikling.team6.controller.components.NavbarController; | ||
|
|
||
|
|
||
| public class LoginPageController extends BaseController { | ||
| @FXML private NavbarController navbarController; | ||
| @FXML private FooterController footerController; | ||
|
|
||
| @Override | ||
| protected void authTokenisSet() { | ||
| if (isLoggedin()){ | ||
| LoaderScene.LoadScene("frontPage", new ActionEvent(), null, null, authToken); | ||
| } | ||
| navbarController.setAuthToken(authToken); | ||
| footerController.setAuthToken(authToken); | ||
| } | ||
|
|
||
| @FXML | ||
| private void handleLogin(ActionEvent event){ | ||
|
|
||
| } | ||
|
|
||
| @FXML | ||
| private void switchToSignupPage(ActionEvent event){ | ||
| System.out.println("Click!"); | ||
| LoaderScene.LoadScene("creater_user_site", event, null, null, authToken); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.