|
| 1 | +package sample; |
| 2 | + |
| 3 | +import javafx.fxml.FXML; |
| 4 | +import javafx.fxml.Initializable; |
| 5 | +import javafx.scene.control.Button; |
| 6 | +import javafx.scene.control.Label; |
| 7 | +import javafx.scene.control.TextField; |
| 8 | +import javafx.scene.image.Image; |
| 9 | +import javafx.scene.image.ImageView; |
| 10 | +import javafx.stage.Stage; |
| 11 | + |
| 12 | +import java.io.File; |
| 13 | +import java.net.URL; |
| 14 | +import java.sql.Connection; |
| 15 | +import java.sql.DriverManager; |
| 16 | +import java.sql.ResultSet; |
| 17 | +import java.sql.Statement; |
| 18 | +import java.util.ResourceBundle; |
| 19 | + |
| 20 | +import util.MyChecker; |
| 21 | + |
| 22 | +public class LoginController implements Initializable { |
| 23 | + @FXML |
| 24 | + private TextField loginField; |
| 25 | + |
| 26 | + @FXML |
| 27 | + private Label invalidLoginLabel; |
| 28 | + |
| 29 | + @FXML |
| 30 | + private Button continueButton; |
| 31 | + |
| 32 | + @FXML |
| 33 | + private Button cancelButton; |
| 34 | + |
| 35 | + @FXML |
| 36 | + private ImageView leftImage; |
| 37 | + |
| 38 | + public void onContinue(){ |
| 39 | + if(loginField.getText().isBlank()){ |
| 40 | + invalidLoginLabel.setText("Введите почту"); |
| 41 | + } |
| 42 | + else if( !MyChecker.isEmail( loginField.getText() ) ){ |
| 43 | + invalidLoginLabel.setText("Не является почтой или содержит недопустимые символы. \nВводите в формате email@box.any с -._"); |
| 44 | + } |
| 45 | + else if (!validateEmail()){ |
| 46 | + invalidLoginLabel.setText("Почта не найдена. \nПроверьте правильность или зарегистрируйтесь"); |
| 47 | + } |
| 48 | + else{ |
| 49 | + invalidLoginLabel.setText("Продолжение следует..."); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public void onCancel(){ |
| 54 | + Stage stage = (Stage) cancelButton.getScene().getWindow(); // could be better code here |
| 55 | + stage.close(); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public void initialize(URL url, ResourceBundle resourceBundle) { |
| 60 | + File file1 = new File("images/0.png"); //no picture now |
| 61 | + Image image1 = new Image(file1.toURI().toString()); |
| 62 | + leftImage.setImage(image1); |
| 63 | + } |
| 64 | + |
| 65 | + private boolean validateEmail(){ |
| 66 | + DatabaseConnection toolDB = new DatabaseConnection(); |
| 67 | + Connection toDB = toolDB.getConnection(); |
| 68 | + |
| 69 | + String verifyLogin = "SELECT count(1) FROM users WHERE email = '" + loginField.getText() + "';"; |
| 70 | + |
| 71 | + try{ |
| 72 | + Statement statement = toDB.createStatement(); |
| 73 | + ResultSet queryResult = statement.executeQuery(verifyLogin); |
| 74 | + |
| 75 | + while(queryResult.next()){ |
| 76 | + if(queryResult.getInt(1) == 1){ |
| 77 | + return true; |
| 78 | + } else { |
| 79 | + return false; |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + }catch(Exception e){ |
| 84 | + e.printStackTrace(); |
| 85 | + e.getCause(); |
| 86 | + } |
| 87 | + |
| 88 | + return false; |
| 89 | + } |
| 90 | +} |
0 commit comments