Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Thermocontroller/src/InputOutput/UserLogin.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
124 lines (99 sloc)
3.22 KB
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
package InputOutput; | |
import java.net.URL; | |
import java.util.Hashtable; | |
import java.util.ResourceBundle; | |
import server.server; | |
import testing.UITest; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.fxml.FXML; | |
import javafx.fxml.FXMLLoader; | |
import javafx.fxml.Initializable; | |
import javafx.scene.Node; | |
import javafx.scene.Parent; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.PasswordField; | |
import javafx.scene.control.TextField; | |
import javafx.stage.Stage; | |
public class UserLogin implements Initializable { | |
public String enteredEmail; | |
public String enteredPassword; | |
private String _email; | |
private String _password; | |
private boolean _loggedin = false; | |
server _server; | |
CurrentUser _user = CurrentUser.getInstance(); | |
@FXML | |
private Button loginButton; | |
@FXML | |
private TextField email; | |
@FXML | |
private PasswordField password; | |
//@FXML | |
//private Button newUserButton; | |
@Override | |
public void initialize(URL arg0, ResourceBundle arg1) { | |
_server = server.getInstance(); | |
System.out.println(_server); | |
this.loginButton.setOnAction(new EventHandler<ActionEvent>() { | |
@Override | |
//checks user name and pass word when login button pressed. If not true nothing happens. | |
public void handle(ActionEvent e) { | |
enteredEmail = email.getText(); | |
enteredPassword = password.getText(); | |
/*_login = _owner.getUserFromEmail(enteredEmail); | |
_password = _login.get(enteredEmail); | |
enteredPassword = password.getText(); | |
boolean goodKey = _login.containsKey(enteredEmail);*/ | |
String queriedEmail = null; | |
String queriedPassword = null; | |
try { | |
queriedEmail = _server.getUserFromEmail(enteredEmail).get("email"); | |
queriedPassword = _server.getUserFromEmail(enteredEmail).get("password"); | |
} catch(Exception e1){ | |
e1.printStackTrace(); | |
System.out.println("ERROR: user and password does not exist"); | |
} | |
if(queriedEmail == null || queriedPassword == null){ | |
System.out.println("user and password does not exist"); | |
} else { | |
if (enteredEmail.equals(queriedEmail) && enteredPassword.equals(queriedPassword)){ | |
_loggedin = true; | |
_user.setEmail(queriedEmail); | |
try{//opens new window when login true | |
Parent root = FXMLLoader.load(getClass().getResource("/interface_xml_files/Thermocontroller.fxml")); | |
Stage stage = new Stage(); | |
stage.setScene(new Scene(root)); | |
stage.show(); | |
} | |
catch (Exception exception){ | |
exception.printStackTrace(); | |
} | |
} | |
//closes window | |
Node source = (Node) e.getSource(); | |
Stage stage = (Stage) source.getScene().getWindow(); | |
stage.close(); | |
} | |
} | |
}); | |
} | |
public void login(ActionEvent event){} | |
//public void newUser(ActionEvent event){} | |
public String getEnteredEmail(){ | |
return enteredEmail; | |
} | |
public String getEnteredPassword(){ | |
return enteredPassword; | |
} | |
public String getEmail(){ | |
return _email; | |
} | |
public String getPassword(){ | |
return _password; | |
} | |
public boolean getStatus(){ | |
return _loggedin; | |
} | |
} |