package controllers;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Control;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import model.SceneCode;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by samschofield on 15/03/17.
 */
public class MainController extends Controller{

    @FXML
    TextField username;
    @FXML
    PasswordField password;

    public void register() throws Exception{
        changeScene(SceneCode.REGISTER);
    }

    public boolean validateLogin(String user, String pass){
        if (user.equals(pass)){
            return true;
        }
        return false;
    }

    public void login() throws Exception {
        //validate login
        if (validateLogin(username.getText(), password.getText())){
            parent.getSession().setUserCode(username.getText());
            changeScene(SceneCode.HOME);
        }else{
            popUp(Alert.AlertType.WARNING, "Warning!", "Invalid Login!", "Your password and username do not match a record in our database.");
        }
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}
