Skip to content

Commit

Permalink
Feat: Login works now.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 16, 2026
1 parent 950ecdb commit 0f95e96
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

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;

import java.awt.*;


public class LoginPageController extends BaseController {
@FXML private NavbarController navbarController;
@FXML private FooterController footerController;

@FXML private TextField emailField;
@FXML private PasswordField passwordField;

@Override
protected void authTokenisSet() {
if (isLoggedin()){
Expand All @@ -23,7 +31,41 @@ protected void authTokenisSet() {

@FXML
private void handleLogin(ActionEvent event){
String emailText = emailField.getText();
String password = passwordField.getText();

if (emailText.isBlank() || password.isBlank()){
showAlert(Alert.AlertType.ERROR, "Empty input", "Please fill out all fields");
return;
}

if (!emailText.contains("@") || !emailText.contains(".")) {
showAlert(Alert.AlertType.ERROR, "Invalid Email", "Please enter a valid email");
return;
}

boolean loginSuccess;
try {
loginSuccess = authToken.login(emailText, password);
} catch (Exception e) {
e.printStackTrace();
showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred");
return;
}
if (loginSuccess) {
showAlert(
Alert.AlertType.INFORMATION,
"Login Success",
"Login Successful!");
LoaderScene.LoadScene("profile_org_Settings", event, null, null, authToken);
} else {
showAlert(
Alert.AlertType.ERROR,
"Account not found",
"User logg inn failed. Either email is wrong or password");
emailField.setText("");
passwordField.setText("");
}
}

@FXML
Expand Down

0 comments on commit 0f95e96

Please sign in to comment.