diff --git a/JavaProgrem.iml b/JavaProgrem.iml index 9465dd864f0bbf5233af344982a638534a50275d..fc860bbbfbd104280a034243c930484fc5eb059d 100644 --- a/JavaProgrem.iml +++ b/JavaProgrem.iml @@ -5,7 +5,16 @@ - + + + + + + + + + + \ No newline at end of file diff --git a/src/fxml/CreateAccount.fxml b/src/fxml/CreateAccount.fxml new file mode 100644 index 0000000000000000000000000000000000000000..d700dd57a7f81823860e1ff1fcfe1d5bf0377283 --- /dev/null +++ b/src/fxml/CreateAccount.fxml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fxml/CreateSuccessfully.fxml b/src/fxml/CreateSuccessfully.fxml new file mode 100644 index 0000000000000000000000000000000000000000..ee7696f833deab05b15f1d23f00bdc1613d8ce82 --- /dev/null +++ b/src/fxml/CreateSuccessfully.fxml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -101,11 +92,7 @@ - - - - - + diff --git a/src/imgzip/CreateAccount.java b/src/imgzip/CreateAccount.java new file mode 100644 index 0000000000000000000000000000000000000000..fc8a0df818e3bb06d9dbaced8d5d4774a3083d19 --- /dev/null +++ b/src/imgzip/CreateAccount.java @@ -0,0 +1,61 @@ +package imgzip; + +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.stage.Stage; + +import javafx.scene.control.Label; + +/** + @Author: 肖尧 + @Date: 2019.12.4 + */ +public class CreateAccount { + public CreateAccount(){ + try { + Parent root = FXMLLoader.load(getClass().getResource("/fxml/CreateAccount.fxml")); + + Label already = (Label)root.lookup("#Al"); + already.setVisible(false); + + Label already2 = (Label)root.lookup("#Al2"); + already2.setVisible(false); + + Button createAccount = (Button)root.lookup("#createAccount"); + createAccount.setDisable(true); + + Stage primaryStage = new Stage(); + primaryStage.setTitle("Create an Account"); + primaryStage.setScene(new Scene(root, 600.0000999999975, 633)); + primaryStage.show(); + + }catch (Exception e){ + e.printStackTrace(); + } + + } +} + +class CreateSuccessfully{ + + public CreateSuccessfully(){ + + try { + Parent root = FXMLLoader.load(getClass().getResource("/fxml/CreateSuccessfully.fxml")); + + Stage primaryStage = new Stage(); + primaryStage.setTitle("Create an Account Successfully!"); + primaryStage.setScene(new Scene(root, 638, 406)); + primaryStage.show(); + + }catch (Exception e){ + e.printStackTrace(); + } + + + } + +} + diff --git a/src/imgzip/CreateAccountController.java b/src/imgzip/CreateAccountController.java new file mode 100644 index 0000000000000000000000000000000000000000..6a2c88bf6cd332b263ae66ae4f5379420b1f3b75 --- /dev/null +++ b/src/imgzip/CreateAccountController.java @@ -0,0 +1,286 @@ +package imgzip; +import javafx.application.Platform; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.control.Alert; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebView; +import javafx.stage.Stage; + +import java.awt.*; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + @Author: 肖尧 + @Date: 2019.12.4 + */ +public class CreateAccountController { + + @FXML + private TextField userName; + + @FXML + private TextField passWord; + + @FXML + private TextField email; + + @FXML + private TextField telephone; + + @FXML + private CheckBox agree; + + @FXML + private Button createAccount; + + @FXML + private Hyperlink privacy; + + @FXML + private Label already; + + @FXML + private Label already2; + + @FXML + private Hyperlink signIn; + + + /** + * SignIn点击后,返回登录页面并关闭注册页面 + */ + public void backToLogin() { + Stage stage = (Stage) signIn.getScene().getWindow(); + new Loginbeginner(); + stage.close(); + + } + + /** + * 检查账号是否存在,如果存在则无法点击注册按钮,且会提醒用户。 + */ + boolean judgeAccountExists = false; + public void checkAccountExistence() { + DataBaseController createAccountInstruction = new DataBaseController(); + ResultSet rs = null; + ResultSet rs2 = null; + + try { + /** + 第一步,检查数据库中是否有该账号存在 + */ + String currentInstruction = "SELECT pwd FROM login WHERE userName=" + "'" + userName.getText().trim() + "'"; + rs = createAccountInstruction.queryExcecute(currentInstruction); + + /** + * 第二步: + * ①如果账号为空,则无法点击注册按钮。 + * ②如果账号存在,无法点击。 + * ③如果账号不存在,邮箱存在,无法点击。 + * ④如果账号邮箱都不存在,但是未同意服务条款,无法点击。 + * ⑤如果账号邮箱都不存在,且同意了服务条款,才可被点击。 + */ + + if("".equals(userName.getText())){ + createAccount.setDisable(true); + + }else { + if (rs.next()) { + judgeAccountExists = true; + already.setVisible(true); + + if(!createAccount.isDisable()){ + createAccount.setDisable(true); + + } + }else{ + judgeAccountExists = false; + already.setVisible(false); + + if(!judgeEmialexist && agree.isSelected()){ + createAccount.setDisable(false); + + } + + } + + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + createAccountInstruction.close(); + } + + } + + /** + * 检查邮箱是否存在,如果存在则无法点击注册按钮,且会提醒用户。 + */ + + boolean judgeEmialexist = false; + public void checkEmailExistence() { + + DataBaseController createAccountInstruction = new DataBaseController(); + ResultSet rs = null; + ResultSet rs2 = null; + + try { + String currentInstruction2 = "SELECT pwd FROM login WHERE email=" + "'" + email.getText().trim() + "'"; + rs2 = createAccountInstruction.queryExcecute(currentInstruction2); + + /** + * 第二步: + * ①如果账号为空,则无法点击注册按钮。 + * ②如果账号存在,无法点击。 + * ③如果账号不存在,邮箱存在,无法点击。 + * ④如果账号邮箱都不存在,但是未同意服务条款,无法点击。 + * ⑤如果账号邮箱都不存在,且同意了服务条款,才可被点击。 + */ + + if ("".equals(email.getText())){ + createAccount.setDisable(true); + + }else { + if (rs2.next()) { + judgeEmialexist = true; + already2.setVisible(true); + + if(!createAccount.isDisable()){ + createAccount.setDisable(true); + + } + }else{ + judgeEmialexist = false; + already2.setVisible(false); + + if(!judgeAccountExists && agree.isSelected()){ + createAccount.setDisable(false); + + } + + } + + } + } catch (Exception e) { + e.printStackTrace(); + + } finally { + createAccountInstruction.close(); + + } + + } + + /** + * CreateAccount点击后,将账号插入数据库中 + */ + public void createAccount() { + DataBaseController createAccountInstruction = new DataBaseController(); + ResultSet rs = null; + + try { + /** + 向数据库中插入数据 + */ + String currentInstruction = "INSERT INTO login (userName,pwd,email,tel) values(" + "'"+userName.getText().trim()+ "'" + "," + "'"+ passWord.getText().trim()+ "'" + "," + "'"+ email.getText().trim() + "'"+ "," + "'"+telephone.getText().trim()+ "'"+")" ; + createAccountInstruction.queryUpdate(currentInstruction); + + /** + 检查数据库中是否成功插入数据 + */ + String currentInstruction2 = "SELECT pwd FROM login WHERE userName=" + "'" + userName.getText().trim() + "'"; + rs = createAccountInstruction.queryExcecute(currentInstruction2); + + if(rs.next()){ + Stage stage = (Stage) signIn.getScene().getWindow(); + new CreateSuccessfully(); + stage.close(); + + }else{ + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("SORRY!"); + alert.setHeaderText("Something's wrong!"); + alert.setContentText("The Account is not created"); + alert.showAndWait(); + + } + + } catch (Exception e) { + e.printStackTrace(); + System.out.println("456"); + + } finally { + createAccountInstruction.close(); + + } + + } + + /** + * 检查是否点击了同意privacy协议,如果不同意,则无法点击 createaccount 按钮。 + */ + public void checkIfSelectedPrivacy(){ + if(!judgeAccountExists && !judgeEmialexist && createAccount.isDisable()){ + createAccount.setDisable(false); + + } + + boolean userNmae = "".equals(userName.getText()); + boolean emial = "".equals(email.getText()); + + if(!agree.isSelected() || userNmae || emial ){ + createAccount.setDisable(true); + + } + } + + /** + * 点击Privacy 的 hyperlink后,跳出网页进入隐私条例说明。 + */ + public void openPrivacy(){ + + try{ + try { + Desktop.getDesktop().browse(new URI("https://www.epicgames.com/site/en-US/privacypolicy?lang=en-US&sessionInvalidated=true")); + + }catch (IOException e){ + System.out.println("123"); + + } + }catch (URISyntaxException e){ + System.out.println("456"); + + } + } + + + /** + * 点击Service 的 hyperlink后,跳出网页进入服务说明。 + */ + public void openService(){ + + try{ + try { + Desktop.getDesktop().browse(new URI("https://www.epicgames.com/site/en-US/tos?lang=en-US")); + + }catch (IOException e){ + System.out.println("123"); + + } + }catch (URISyntaxException e){ + System.out.println("456"); + + } + } + +} + + diff --git a/src/imgzip/CreateSuccessfullyController.java b/src/imgzip/CreateSuccessfullyController.java new file mode 100644 index 0000000000000000000000000000000000000000..2e59f533366f997177e2d3b6897dd7161f977342 --- /dev/null +++ b/src/imgzip/CreateSuccessfullyController.java @@ -0,0 +1,39 @@ +package imgzip; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.stage.Stage; +/** + @Author: 肖尧 + @Date: 2019.11.24 + */ + +public class CreateSuccessfullyController{ + @FXML + private Button signUp; + + @FXML + private Button signIn; + + + /** + * 点击后sign up 后回到登录页面。 + */ + public void backToLogin() { + Stage stage = (Stage) signUp.getScene().getWindow(); + new Loginbeginner(); + stage.close(); + + } + + + /** + * 点击后sign in again 后继续注册。 + */ + public void backToSignIn() { + Stage stage = (Stage) signIn.getScene().getWindow(); + new CreateAccount(); + stage.close(); + + } +} diff --git a/src/imgzip/DataBaseController.java b/src/imgzip/DataBaseController.java index 7e68673fb4855c15a82f68055bd41454c1d49c30..2779ab39793181fe1a29139ec94b6cdfece609ec 100644 --- a/src/imgzip/DataBaseController.java +++ b/src/imgzip/DataBaseController.java @@ -48,6 +48,7 @@ public class DataBaseController { ex.printStackTrace(); } + } @@ -68,7 +69,28 @@ public class DataBaseController { ex.printStackTrace(); } + return rs; } + + public void queryUpdate(String sql){ + try { + + Class.forName(driver); + + ct = DriverManager.getConnection(url,user,password); + + ps = ct.prepareStatement(sql); + + ps.executeUpdate(); + + }catch (Exception ex){ + ex.printStackTrace(); + + } + + } + + } diff --git a/src/imgzip/Login.java b/src/imgzip/Login.java index 48daf40a60961761f3fc486b07ff2056cef68019..9f92445d368aa2bab562488d3fe10c670ac10d41 100644 --- a/src/imgzip/Login.java +++ b/src/imgzip/Login.java @@ -8,6 +8,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; import javafx.scene.control.TextField; import javafx.scene.control.PasswordField; import javafx.scene.layout.BorderPane; @@ -15,10 +16,14 @@ import javafx.stage.Stage; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; /** @Author: 肖尧 - @Date: 2019.11.22 + @Date: 2019.12.4 */ public class Login extends Application { @@ -29,17 +34,123 @@ public class Login extends Application { Parent root = FXMLLoader.load(getClass().getResource("/fxml/Login.fxml")); + TextField account = (TextField)root.lookup("#Account"); + PasswordField password = (PasswordField)root.lookup("#password"); + CheckBox remember = (CheckBox)root.lookup("#remember"); + Button logIn = (Button)root.lookup("#Login"); + + + /** + 在页面开启之前检查上一次登录时是否记住了密码, + 如果上一次登录点击了记住密码,则在本次打开时会将账号和密码写入 + */ + try { + + FileReader fr = new FileReader("src/txtFile/RememberAccount&Password.txt"); + BufferedReader br = new BufferedReader(fr); + + String line = ""; + line = br.readLine(); + + + String[] judge = line.split("\\|"); + String truejudge = "true"; + int accountIndex = 0; + int passwordIndex = 1; + int judgeIndex = 2; + + if(judge[judgeIndex].equals(truejudge) ){ + account.setText(judge[accountIndex]); + password.appendText(judge[passwordIndex]); + + remember.setSelected(true); + logIn.setDisable(false); + + } + + br.close(); + fr.close(); + + }catch (Exception e){ + e.printStackTrace(); + + } + primaryStage.setTitle("XXX login"); primaryStage.setScene(new Scene(root, 638, 400)); primaryStage.show(); }catch (Exception e){ e.printStackTrace(); + + } + } - } public static void main(String[] args) { launch(args); } } + + +class Loginbeginner{ + public Loginbeginner(){ + try { + Stage primaryStage = new Stage(); + Parent root = FXMLLoader.load(getClass().getResource("/fxml/Login.fxml")); + + TextField account = (TextField)root.lookup("#Account"); + PasswordField password = (PasswordField)root.lookup("#password"); + CheckBox remember = (CheckBox)root.lookup("#remember"); + Button logIn = (Button)root.lookup("#Login"); + + + /** + 在页面开启之前检查上一次登录时是否记住了密码, + 如果上一次登录点击了记住密码,则在本次打开时会将账号和密码写入 + */ + try { + + FileReader fr = new FileReader("src/txtFile/RememberAccount&Password.txt"); + BufferedReader br = new BufferedReader(fr); + + String line = ""; + line = br.readLine(); + + + String[] judge = line.split("\\|"); + String truejudge = "true"; + int accountIndex = 0; + int passwordIndex = 1; + int judgeIndex = 2; + + if(judge[judgeIndex].equals(truejudge) ){ + account.setText(judge[accountIndex]); + password.appendText(judge[passwordIndex]); + + remember.setSelected(true); + logIn.setDisable(false); + + } + + br.close(); + fr.close(); + + }catch (Exception e){ + e.printStackTrace(); + + } + + primaryStage.setTitle("XXX login"); + primaryStage.setScene(new Scene(root, 638, 400)); + primaryStage.show(); + + }catch (Exception e){ + e.printStackTrace(); + + } + + } + +} \ No newline at end of file diff --git a/src/imgzip/LoginController.java b/src/imgzip/LoginController.java index ee5e10d2c8b23fd7413a7d19eaf3ddb141dd26c5..6c47f3d59a2dbf4c3958a010db447ab594fd721d 100644 --- a/src/imgzip/LoginController.java +++ b/src/imgzip/LoginController.java @@ -8,16 +8,23 @@ import javafx.scene.control.TextField; import javafx.scene.control.CheckBox; import javafx.stage.Stage; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; + import java.sql.SQLException; import java.sql.Statement; /** @Author:肖尧 - @Date:2019.11.22 + @Date:2019.11.24 */ public class LoginController { @@ -56,7 +63,7 @@ public class LoginController { String stringPassword = password.getText(); String ifEmpty = ""; - if ( (stringAccount.equals(ifEmpty) || stringPassword.equals(ifEmpty)) && login.isDisable() == false){ + if ( (stringAccount.equals(ifEmpty) || stringPassword.equals(ifEmpty))){ login.setDisable(true); }else if ((!stringAccount.equals(ifEmpty) && !stringPassword.equals(ifEmpty))){ @@ -81,15 +88,15 @@ public class LoginController { /** 用户点击此按钮时, - ①:如果账号不存在或账号存在但是密码错误,则进入密码错误页面。 - ②:如果账号存在且密码正确,则进入主页面(尚未完成) + ①:如果账号不存在或账号存在但是密码错误,则进入密码错误页面。 + ②:如果账号存在且密码正确,则进入主页面(尚未完成)。 + ③:如果勾选了记住账号和密码,则在下一次打开页面时会记住上一次的密码。 */ public void login(){ DataBaseController loginInstruction = new DataBaseController(); ResultSet rs = null; - try{ String currentInstruction = "SELECT pwd FROM login WHERE userName=" + "'" + account.getText().trim()+ "'"; @@ -99,16 +106,21 @@ public class LoginController { if (rs.next()) { String rightPassword = rs.getString(1); if (rightPassword.equals(password.getText())){ + + remember(); //登入主页面,待定 - System.out.println("登录成功"); + System.out.println("登录1"); }else{ new WrongPassword(); - + Stage stage = (Stage)createAccount.getScene().getWindow(); + stage.close(); } }else { new WrongPassword(); + Stage stage = (Stage)createAccount.getScene().getWindow(); + stage.close(); } @@ -118,13 +130,11 @@ public class LoginController { }finally { loginInstruction.close(); } - } /** - 设置back事件, - 当用户点击该按钮的时候,跳转至登录界面 + 设置cancel按钮,可以直接点击这里完成窗口的关闭。 */ public void cancel(){ @@ -132,4 +142,48 @@ public class LoginController { stage.close(); } + + + /** + 设置记住账号密码按钮的方法。 + */ + + public void remember(){ + boolean ifclick = remember.isSelected(); + String judgeIfclick = ""; + + if(ifclick){ + judgeIfclick = "true"; + }else { + judgeIfclick = "false"; + } + + try { + FileWriter fw = new FileWriter("src/txtFile/RememberAccount&Password.txt"); + BufferedWriter fis = new BufferedWriter(fw); + + fis.write(account.getText() +"|"+ password.getText() + "|" + judgeIfclick ); + fis.newLine(); + + fis.close(); + fw.close(); + + }catch (Exception e){ + e.printStackTrace(); + } + } + + + /** + 点击注册页面的方法,用户点击以后直接进入注册页面。 + */ + public void createAccount(){ + new CreateAccount(); + Stage stage = (Stage)createAccount.getScene().getWindow(); + stage.close(); + } + + + } + diff --git a/src/imgzip/WrongPassword.java b/src/imgzip/WrongPassword.java index 7a41275fa957ed5e08935e021d44b9143df2ccb8..39416f353f93a92122374cce70d710ff31e2baed 100644 --- a/src/imgzip/WrongPassword.java +++ b/src/imgzip/WrongPassword.java @@ -8,7 +8,7 @@ import javafx.stage.Stage; /** @Author: 肖尧 - @Date: 2019.11.22 + @Date: 2019.11.24 */ public class WrongPassword { @@ -19,7 +19,7 @@ public class WrongPassword { Parent root = FXMLLoader.load(getClass().getResource("/fxml/WrongPassword.fxml")); Stage primaryStage = new Stage(); primaryStage.setTitle("Password is wrong!"); - primaryStage.setScene(new Scene(root, 638.0, 450.0)); + primaryStage.setScene(new Scene(root, 638.0, 400)); primaryStage.show(); }catch (Exception e){ diff --git a/src/imgzip/WrongPasswordController.java b/src/imgzip/WrongPasswordController.java index 00e085ecaffa61513ba519d417f6deacdada3bdb..b1793a365a942111fd8e2e660f316642f3cffbd2 100644 --- a/src/imgzip/WrongPasswordController.java +++ b/src/imgzip/WrongPasswordController.java @@ -3,14 +3,15 @@ import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.stage.Stage; +import sun.rmi.runtime.Log; import java.sql.ResultSet; import java.sql.SQLException; /** - Author:肖尧 - Date:2019.11.22 + @Author:肖尧 + @Date:2019.11.24 */ public class WrongPasswordController { @@ -30,7 +31,9 @@ public class WrongPasswordController { */ public void createAccount(){ - + new CreateAccount(); + Stage stage = (Stage)back.getScene().getWindow(); + stage.close(); } @@ -51,7 +54,7 @@ public class WrongPasswordController { Stage stage = (Stage)back.getScene().getWindow(); stage.close(); - + new Loginbeginner(); } diff --git a/src/res/icon/Happyface.jpg b/src/res/icon/Happyface.jpg new file mode 100644 index 0000000000000000000000000000000000000000..00d0f14d75093eacdf0f9dd49cf749b3a4c0a0e1 Binary files /dev/null and b/src/res/icon/Happyface.jpg differ diff --git a/src/res/icon/sad face.jpg b/src/res/icon/sad face.jpg index b9d85dbf6b73b912c30baf7da2c8b00dba7adfc8..41a788914fa33a772477f82cd6b29a5cbc1d2850 100644 Binary files a/src/res/icon/sad face.jpg and b/src/res/icon/sad face.jpg differ diff --git a/src/txtFile/RememberAccount&Password.txt b/src/txtFile/RememberAccount&Password.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c847cdce67d1546354ce8a9ec9289bde89f286a --- /dev/null +++ b/src/txtFile/RememberAccount&Password.txt @@ -0,0 +1 @@ +13609013530|xiaoyaozizai|true