Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Button;
- import javafx.scene.control.ButtonType;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.Hyperlink;
- import javafx.scene.control.Label;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextField;
- import javafx.scene.control.ToolBar;
- import javafx.scene.control.Alert.AlertType;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.input.KeyCode;
- import javafx.scene.input.KeyEvent;
- import javafx.scene.layout.AnchorPane;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.scene.shape.Line;
- import javafx.stage.Stage;
- import javafx.stage.WindowEvent;
- import java.sql.SQLException;
- import java.util.Optional;
- import dbsettings.db;
- import model.functions;
- public class Main extends Application{
- static Stage actualstage = null;
- functions functions = new functions();
- db dbcon = new db();
- private String userlevel = "";
- private String loggeduser = "";
- public static void main(String[] args) {
- launch(args);
- }
- public void start(Stage loginpage) throws Exception {
- functions.conection(dbcon); //Use database connection in functions class
- actualstage = loginpage;
- //Testing
- try {
- dbcon.getallusers();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- try {
- dbcon.getalluserlevels();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- //Login setup
- VBox vbox = new VBox();
- Image img = new Image("logo.png");
- ImageView imageView = new ImageView(img);
- imageView.setFitHeight(100);
- imageView.setFitWidth(100);
- imageView.setTranslateX(95);
- imageView.setTranslateY(3);
- Label label = new Label("Ludzu, ielogojies, vai izveido jaunu profilu");
- label.setMaxWidth(Double.MAX_VALUE);
- AnchorPane.setLeftAnchor(label, 0.0);
- AnchorPane.setRightAnchor(label, 0.0);
- label.setAlignment(Pos.CENTER);
- label.setStyle("-fx-font-size: 14; -fx-font-weight: bold;");
- Label label2 = new Label("username:");
- label2.setStyle("-fx-font-weight: bold;");
- TextField username = new TextField();
- Label label3 = new Label("password:");
- label3.setStyle("-fx-font-weight: bold;");
- PasswordField password = new PasswordField();
- Button loginbutton = new Button("Go");
- loginbutton.setTranslateX(129);
- Button registerbutton = new Button("Registreties");
- registerbutton.setTranslateX(107);
- loginbutton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent arg0) {
- boolean status = false;
- String getTextfromusername = username.getText();
- String getTextfrompass = password.getText();
- String passwordcode = "";
- try {
- passwordcode = functions.encrypt(getTextfrompass);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- try {
- status = dbcon.login(getTextfromusername, passwordcode);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(status) {
- System.out.println("Autentifikacija izdevusies. Parbauda userlevel...");
- try {
- userlevel = dbcon.getuserlevel(getTextfromusername);
- loggeduser = getTextfromusername;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- System.out.println("Ieguts userlevel:" + userlevel);
- if(userlevel.equals("banned")) {
- System.out.println("Autentifikacija neizdevas(lietotajs ir nobanots)");
- Alert alert = new Alert(Alert.AlertType.ERROR);
- alert.setTitle("Banned");
- alert.setHeaderText("Tavs profils ir banots par noteikumu neieverosanu.");
- alert.show();
- password.setText("");
- }
- else{
- System.out.println("Ielade foruma lapu");
- loginpage.close();
- mainview();
- }
- }
- else {
- System.out.println("Autentifikacija neizdevas");
- Alert alert = new Alert(Alert.AlertType.ERROR);
- alert.setTitle("Kluda");
- alert.setHeaderText("Nepareizs lietotajvards/parole");
- alert.show();
- password.setText("");
- }
- }
- });
- registerbutton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- registrationview();
- }
- });
- password.setOnKeyPressed(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent event) {
- if(event.getCode().equals(KeyCode.ENTER)) {
- loginbutton.fire();
- }
- }
- });
- vbox.getChildren().addAll(imageView, label, label2, username, label3, password, loginbutton, registerbutton);
- Scene scene = new Scene(vbox, 300, 255);
- scene.getStylesheets().add("loginstylesheet.css");
- loginpage.resizableProperty().setValue(Boolean.FALSE);
- loginpage.setScene(scene);
- loginpage.setTitle("Forums");
- loginpage.getIcons().add(new Image("logo.png"));
- loginpage.show();
- }
- private void registrationview() {
- Stage stage = new Stage();
- VBox box = new VBox();
- Image img = new Image("logo.png");
- ImageView imageView = new ImageView(img);
- imageView.setFitHeight(100);
- imageView.setFitWidth(100);
- imageView.setTranslateX(130);
- imageView.setTranslateY(3);
- Label reginf = new Label("Registracija");
- reginf.setStyle("-fx-font-size: 20; -fx-font-weight: bold;");
- reginf.setMaxWidth(Double.MAX_VALUE);
- AnchorPane.setLeftAnchor(reginf, 0.0);
- AnchorPane.setRightAnchor(reginf, 0.0);
- reginf.setAlignment(Pos.CENTER);
- Label usernametxt = new Label("Izvelies lietotajvardu");
- usernametxt.setStyle("-fx-font-weight: bold;");
- TextField username = new TextField();
- Label passtxt = new Label("Ievadi paroli");
- passtxt.setStyle("-fx-font-weight: bold;");
- PasswordField password = new PasswordField();
- Label passtxt2 = new Label("Ievadi velreiz paroli");
- passtxt2.setStyle("-fx-font-weight: bold;");
- PasswordField password2 = new PasswordField();
- Button register = new Button("Registreties");
- register.setTranslateX(128);
- Label userexists = new Label("");
- userexists.setStyle("-fx-text-fill: red;");
- Label passnotmatch = new Label("");
- passnotmatch.setStyle("-fx-text-fill: red;");
- Label usernametooshort = new Label("Lietotajvarda jabut vismaz 4 simboliem");
- usernametooshort.setStyle("-fx-text-fill: red;");
- Label passtooshort = new Label("Parole jabut vismaz 4 simboliem");
- passtooshort.setStyle("-fx-text-fill: red;");
- Label namecontainsspaces = new Label("");
- namecontainsspaces.setStyle("-fx-text-fill: red;");
- CheckBox rulescheckBox = new CheckBox("");
- rulescheckBox.setTranslateY(20);
- Hyperlink ruleslink = new Hyperlink("Piekrîtu foruma noteikumiem");
- ruleslink.setTranslateX(15);
- username.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent arg0) {
- boolean status = true;
- String getTextfromusername = username.getText();
- try {
- status = dbcon.checkIfUserExists(getTextfromusername);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(status && getTextfromusername.length() > 1)
- userexists.setText("Lietotajvards ir aiznemts");
- else
- userexists.setText("");
- if(getTextfromusername.length() < 4)
- usernametooshort.setText("Lietotajvarda jabut vismaz 4 simboliem");
- else
- usernametooshort.setText("");
- int spacescount = 0;
- spacescount = functions.countspacesinusername(getTextfromusername);
- if (spacescount > 0)
- namecontainsspaces.setText("Lietotajvards nedrikst saturet atstarpes");
- else
- namecontainsspaces.setText("");
- }
- });
- password.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent arg0) {
- String getTextfrompassword = password.getText();
- String getTextfrompassword2 = password2.getText();
- if(!getTextfrompassword.equals(getTextfrompassword2) && getTextfrompassword.length() > 0)
- passnotmatch.setText("Paroles nesakrit!");
- else
- passnotmatch.setText("");
- if(getTextfrompassword.length() < 4)
- passtooshort.setText("Parole jabut vismaz 4 simboliem");
- else
- passtooshort.setText("");
- }
- });
- password2.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent arg0) {
- String getTextfrompassword = password.getText();
- String getTextfrompassword2 = password2.getText();
- if(!getTextfrompassword.equals(getTextfrompassword2) && getTextfrompassword.length() > 0)
- passnotmatch.setText("Paroles nesakrit!");
- else
- passnotmatch.setText("");
- }
- });
- register.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- boolean status = false;
- String getTextfromusername = username.getText();
- String getTextfrompass = password.getText();
- String getTextfrompass2 = password2.getText();
- String passwordcode = "";
- int spacescount = 0;
- spacescount = functions.countspacesinusername(getTextfromusername);
- if(rulescheckBox.isSelected()) {
- if(getTextfrompass.equals(getTextfrompass2)) {
- if(getTextfromusername.length() > 3 && getTextfrompass.length() > 3 && spacescount == 0) {
- try {
- passwordcode = functions.encrypt(getTextfrompass);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- try {
- status = dbcon.adduser(getTextfromusername, passwordcode);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(status) {
- Alert regsuc = new Alert(Alert.AlertType.INFORMATION);
- System.out.println("Registracija veiksmiga(" + getTextfromusername + ")");
- regsuc.setTitle("Registracija veiksmiga");
- regsuc.setHeaderText("Lietotajs izveidots. Tagad variet ielogoties ar savu jauno profilu");
- regsuc.show();
- stage.close();
- }
- else {
- Alert regfail = new Alert(Alert.AlertType.ERROR);
- System.out.println("Registracija neveiksmiga(server error vai username aiznemts)");
- regfail.setTitle("Registracija neizdevusies");
- regfail.setHeaderText("Registracija neveiksmiga, lietotajvards nav pieejams");
- regfail.show();
- password.setText("");
- password2.setText("");
- }
- }
- else {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Registracija neveiksmiga(parak isa username/parole vai atstarpes parole)");
- alert.setTitle("Kluda");
- alert.setHeaderText("Lietotajvardaa un parolee jabut vismaz 4 simboliem, ka ari lietotajvards nedrikst saturet atstarpes");
- alert.show();
- password.setText("");
- password2.setText("");
- }
- }
- else {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Registracija neveiksmiga(paroles nesakrit)");
- alert.setTitle("Kluda");
- alert.setHeaderText("Paroles nesakrit");
- alert.show();
- password.setText("");
- password2.setText("");
- }
- }
- else {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Registracija neveiksmiga(nepiekrit noteikumiem)");
- alert.setTitle("Kluda");
- alert.setHeaderText("Jums japiekrit noteikumiem, lai registretos");
- alert.show();
- password.setText("");
- password2.setText("");
- }
- }
- });
- ruleslink.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- getHostServices().showDocument("http://178.62.8.75/noteikumi.html");
- }
- });
- box.getChildren().addAll(imageView, reginf, usernametxt, username, usernametooshort, userexists, namecontainsspaces, passtxt, password, passtooshort, passtxt2, password2, passnotmatch, rulescheckBox, ruleslink, register);
- Scene sc = new Scene(box, 350, 407);
- sc.getStylesheets().add("registerstylesheet.css");
- stage.setScene(sc);
- stage.getIcons().add(new Image("logo.png"));
- stage.setTitle("Registracija");
- stage.resizableProperty().setValue(Boolean.FALSE);
- stage.show();
- }
- public void mainview() {
- functions.funcgetloggeduser(loggeduser);
- functions.funcgetuserlevel(userlevel);
- Stage stage = new Stage();
- stage.setMaximized(true);
- BorderPane border = new BorderPane();
- Scene sc = new Scene(border, 600, 600);
- //Window top toolbar setup
- Image logoimg = new Image("logo.png");
- ImageView logoimgview = new ImageView(logoimg);
- logoimgview.setFitHeight(30);
- logoimgview.setFitWidth(30);
- Button toolbarjauns = new Button("Jauns");
- toolbarjauns.setGraphic(new ImageView("plus.png"));
- Button toolbarprofils = new Button("Profils");
- toolbarprofils.setGraphic(new ImageView("profileicon.png"));
- Button toolbarmod = new Button("Mod");
- toolbarmod.setGraphic(new ImageView("modicon.png"));
- Button toolbarlogout = new Button("Iziet");
- toolbarlogout.setGraphic(new ImageView("logouticon.png"));
- Button toolbaradmin = new Button("Admin");
- toolbaradmin.setGraphic(new ImageView("adminicon.png"));
- ToolBar toolBar = null;
- //Toolbar config
- if(userlevel.equals("mod")){
- toolBar = new ToolBar(
- logoimgview,
- toolbarjauns,
- toolbarprofils,
- toolbarmod,
- toolbarlogout
- );
- }
- else if(userlevel.equals("admin")){
- toolBar = new ToolBar(
- logoimgview,
- toolbarjauns,
- toolbarprofils,
- toolbarmod,
- toolbaradmin,
- toolbarlogout
- );
- }
- else{
- toolBar = new ToolBar(
- logoimgview,
- toolbarjauns,
- toolbarprofils,
- toolbarlogout
- );
- }
- border.setTop(toolBar);
- //Window midbox setup
- VBox centerbox = new VBox();
- functions.mainwindow(centerbox);
- Image img = new Image("forummainpage.png");
- ImageView imageView = new ImageView(img);
- centerbox.getChildren().addAll(imageView);
- border.setCenter(centerbox);
- //Left panel setup
- VBox leftbox = new VBox();
- HBox searchbox = functions.searchbox();
- Label categoryinfo = new Label(" Kategorijas ");
- leftbox.setStyle("-fx-background-color: #cc0000;");
- categoryinfo.setStyle("-fx-text-fill: rgb(255, 255, 255); -fx-font-weight: bold; -fx-font-size: 30;");
- Line seperator = new Line();
- seperator.setEndX(200);
- seperator.setStyle("-fx-stroke: white;");
- VBox allcategory = functions.loadallcategory();
- functions.categorywindow(allcategory);
- leftbox.getChildren().addAll(searchbox, categoryinfo, seperator, allcategory);
- border.setLeft(leftbox);
- //Bottom panel setup
- HBox hbox = new HBox();
- Label infotext = new Label("©Forums 2018-2019");
- hbox.getChildren().addAll(infotext);
- border.setBottom(hbox);
- Stage panelstage = new Stage();
- stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
- @Override
- public void handle(WindowEvent event) {
- panelstage.close();
- }
- });
- //Toolbar functions
- toolbarlogout.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- try {
- stage.close();
- panelstage.close();
- System.out.println("Lietotajs beidzis sesiju");
- start(actualstage);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- toolbaradmin.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- adminpanel(panelstage);
- }
- });
- toolbarmod.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- modpanel(panelstage);
- }
- });
- toolbarjauns.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- addpanel(userlevel, panelstage);
- }
- });
- toolbarprofils.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- try {
- profilepanel(centerbox, panelstage);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- });
- //Window final setup
- sc.getStylesheets().add("mainpagestylesheet.css");
- stage.setScene(sc);
- stage.getIcons().add(new Image("logo.png"));
- stage.setTitle("Forums");
- stage.show();
- }
- public void adminpanel(Stage stage){
- VBox vbox = new VBox();
- Label usermanage = new Label("Lietotaju parvaldisana");
- usermanage.setStyle("-fx-font-size: 18; -fx-font-weight: bold;");
- usermanage.setTranslateX(60);
- VBox levelview = functions.userlevelchangeview();
- VBox deluser = functions.deleteuserview();
- Label catmanage = new Label("Kategoriju parvaldisana");
- catmanage.setStyle("-fx-font-size: 18; -fx-font-weight: bold;");
- catmanage.setTranslateX(60);
- VBox deletecategory = functions.deletecategoryview();
- VBox updatecategory = functions.updatecategoryview();
- vbox.getChildren().addAll(usermanage, levelview, deluser, catmanage, deletecategory, updatecategory);
- Scene sc = new Scene(vbox, 330, 570);
- sc.getStylesheets().add("adminpanelstylesheet.css");
- stage.setScene(sc);
- stage.getIcons().add(new Image("logo.png"));
- stage.setTitle("Admin panel");
- stage.resizableProperty().setValue(Boolean.FALSE);
- stage.show();
- }
- public void modpanel(Stage stage) {
- VBox vbox = new VBox();
- Label usermanage = new Label("Lietotaju parvaldisana");
- usermanage.setStyle("-fx-font-size: 18; -fx-font-weight: bold;");
- usermanage.setTranslateX(60);
- VBox banview = functions.userbanview();
- VBox changename = functions.changenameview();
- vbox.getChildren().addAll(usermanage, banview, changename);
- Scene sc = new Scene(vbox, 330, 400);
- sc.getStylesheets().add("modpanelstylesheet.css");
- stage.setScene(sc);
- stage.getIcons().add(new Image("logo.png"));
- stage.setTitle("Moderation panel");
- stage.resizableProperty().setValue(Boolean.FALSE);
- stage.show();
- }
- public void addpanel(String userlevel, Stage stage) {
- VBox vbox = new VBox();
- VBox addtopic = functions.addtopicview(stage);
- vbox.getChildren().add(addtopic);
- if(userlevel.equals("admin")) {
- VBox addcategory = functions.addcategory();
- vbox.getChildren().add(addcategory);
- }
- Scene sc = new Scene(vbox, 700, 500);
- sc.getStylesheets().add("addpanelstylesheet.css");
- stage.setScene(sc);
- stage.getIcons().add(new Image("logo.png"));
- stage.setTitle("Pievienot");
- stage.resizableProperty().setValue(Boolean.FALSE);
- stage.show();
- }
- public void profilepanel(VBox midbox, Stage stage) throws SQLException {
- int loggeduserid = 0;
- loggeduserid = dbcon.getuserid(loggeduser);
- VBox profile = new VBox();
- VBox userinfobox = new VBox();
- userinfobox.setStyle("-fx-background-color: #ffc4c4;");
- Image img = new Image("avatar.png");
- ImageView imageView = new ImageView(img);
- Label loggedusertext = new Label(loggeduser);
- Label loggeduserlevel = new Label(userlevel);
- loggedusertext.setStyle("-fx-font-size: 30; -fx-font-weight: bold;");
- userinfobox.getChildren().addAll(imageView, loggedusertext, loggeduserlevel);
- userinfobox.setAlignment(Pos.CENTER);
- Label mytopicsinfo = new Label("Manas izveidotas diskusijas:");
- mytopicsinfo.setStyle("-fx-font-size: 22; -fx-font-weight: bold;");
- VBox mytopiclist = functions.loadtopiclist(0, "profiletopics", loggeduserid, null);
- Label myreplyinfo = new Label("Manas komentetas diskusijas:");
- VBox myreplylist = functions.loadtopiclist(0, "profilereply", loggeduserid, null);
- myreplyinfo.setStyle("-fx-font-size: 22; -fx-font-weight: bold;");
- HBox buttons = new HBox();
- buttons.setStyle("-fx-background-color: #ffc4c4;");
- Button changename = new Button("Mainit lietotajvardu");
- Button changepassword = new Button("Mainit paroli");
- changename.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- profilepanelchangename(stage, midbox);
- }
- });
- changepassword.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- profilepanelchangepassword(stage, midbox);
- }
- });
- buttons.getChildren().addAll(changename, changepassword);
- profile.getChildren().addAll(userinfobox, mytopicsinfo, mytopiclist, myreplyinfo, myreplylist, buttons);
- midbox.getChildren().clear();
- midbox.getChildren().add(profile);
- }
- public void profilepanelchangename(Stage stage, VBox midbox) {
- VBox vbox = new VBox();
- Label changenameinfo = new Label("Lietotajvarda maina");
- changenameinfo.setStyle("-fx-font-size: 30; -fx-font-weight: bold;");
- changenameinfo.setMaxWidth(Double.MAX_VALUE);
- AnchorPane.setLeftAnchor(changenameinfo, 0.0);
- AnchorPane.setRightAnchor(changenameinfo, 0.0);
- changenameinfo.setAlignment(Pos.CENTER);
- Label usernametxt = new Label("Izvelies lietotajvardu");
- usernametxt.setStyle("-fx-font-weight: bold;");
- TextField username = new TextField();
- Label userexists = new Label("Lietotajvards jau ir aiznemts");
- userexists.setStyle("-fx-text-fill: red;");
- userexists.setManaged(false);
- userexists.setVisible(false);
- Label usernametooshort = new Label("Lietotajvarda jabut vismaz 4 simboliem");
- usernametooshort.setStyle("-fx-text-fill: red;");
- Label namecontainsspaces = new Label("Lietotajvards nedrikst saturet atstarpes");
- namecontainsspaces.setStyle("-fx-text-fill: red;");
- namecontainsspaces.setManaged(false);
- namecontainsspaces.setVisible(false);
- Label passtxt = new Label("Ievadi paroli");
- passtxt.setStyle("-fx-font-weight: bold;");
- PasswordField password = new PasswordField();
- Button confirm = new Button("Mainit");
- username.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent arg0) {
- boolean status = true;
- String getTextfromusername = username.getText();
- try {
- status = dbcon.checkIfUserExists(getTextfromusername);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(status && getTextfromusername.length() > 1) {
- userexists.setManaged(true);
- userexists.setVisible(true);
- }
- else {
- userexists.setManaged(false);
- userexists.setVisible(false);
- }
- if(getTextfromusername.length() < 4) {
- usernametooshort.setManaged(true);
- usernametooshort.setVisible(true);
- }
- else {
- usernametooshort.setManaged(false);
- usernametooshort.setVisible(false);
- }
- int spacescount = 0;
- spacescount = functions.countspacesinusername(getTextfromusername);
- if (spacescount > 0) {
- namecontainsspaces.setManaged(true);
- namecontainsspaces.setVisible(true);
- }
- else {
- namecontainsspaces.setManaged(false);
- namecontainsspaces.setVisible(false);
- }
- }
- });
- confirm.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- boolean status = false;
- String getTextfromusername = username.getText();
- String getTextfrompass = password.getText();
- String passwordcode = "";
- int spacescount = 0;
- Alert alert2 = new Alert(AlertType.CONFIRMATION);
- alert2.setTitle("Mainit lietotajvardu?");
- alert2.setHeaderText("Vai tiesam mainit lietotajvardu?");
- Optional<ButtonType> result = alert2.showAndWait();
- if (result.get() == ButtonType.OK){
- try {
- passwordcode = functions.encrypt(getTextfrompass);
- status = dbcon.login(loggeduser, passwordcode);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- if(status) {
- spacescount = functions.countspacesinusername(getTextfromusername);
- if(getTextfromusername.length() > 3 && spacescount == 0) {
- try {
- status = dbcon.changename(loggeduser, getTextfromusername);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(status) {
- setloggeduser(getTextfromusername);
- functions.funcgetloggeduser(loggeduser);
- Alert regsuc = new Alert(Alert.AlertType.INFORMATION);
- System.out.println("Nickname mainits(" + getTextfromusername + ")");
- regsuc.setTitle("Operacija veiksmiga");
- regsuc.setHeaderText("Lietotajvards mainits");
- regsuc.show();
- midbox.getChildren().clear();
- try {
- profilepanel(midbox, stage);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- stage.close();
- }
- else {
- Alert regfail = new Alert(Alert.AlertType.ERROR);
- System.out.println("Operacija neveiksmiga(server error vai username aiznemts)");
- regfail.setTitle("Operacija neizdevusies");
- regfail.setHeaderText("Operacija neveiksmiga, lietotajvards nav pieejams");
- regfail.show();
- password.setText("");
- }
- }
- else {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Operacija neveiksmiga(parak iss username)");
- alert.setTitle("Operacija neveiksmiga");
- alert.setHeaderText("Lietotajvardaa jabut vismaz 4 simboliem, ka ari lietotajvards nedrikst saturet atstarpes");
- alert.show();
- password.setText("");
- }
- }
- else {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Operacija neveiksmiga(nepareiza parole)");
- alert.setTitle("Operacija neveiksmiga");
- alert.setHeaderText("Nepareiza parole");
- alert.show();
- password.setText("");
- }
- }
- }
- });
- vbox.getChildren().addAll(changenameinfo, usernametxt, username, userexists, usernametooshort, namecontainsspaces, passtxt, password, confirm);
- Scene sc = new Scene(vbox, 300, 180);
- sc.getStylesheets().add("changenamepanel.css");
- stage.setScene(sc);
- stage.getIcons().add(new Image("logo.png"));
- stage.setTitle("Mainit lietotajvardu");
- stage.resizableProperty().setValue(Boolean.FALSE);
- stage.show();
- }
- public void profilepanelchangepassword(Stage stage, VBox midbox) {
- VBox vbox = new VBox();
- Label changenameinfo = new Label("Paroles maina");
- changenameinfo.setStyle("-fx-font-size: 30; -fx-font-weight: bold;");
- changenameinfo.setMaxWidth(Double.MAX_VALUE);
- AnchorPane.setLeftAnchor(changenameinfo, 0.0);
- AnchorPane.setRightAnchor(changenameinfo, 0.0);
- changenameinfo.setAlignment(Pos.CENTER);
- Label passtxt = new Label("Ievadi veco paroli");
- passtxt.setStyle("-fx-font-weight: bold;");
- PasswordField password = new PasswordField();
- Label passtxt2 = new Label("Ievadi jauno paroli");
- passtxt2.setStyle("-fx-font-weight: bold;");
- PasswordField password2 = new PasswordField();
- Label passtxt3 = new Label("Ievadi velreiz jauno paroli");
- passtxt3.setStyle("-fx-font-weight: bold;");
- PasswordField password3 = new PasswordField();
- Button change = new Button("Mainit");
- Label passtooshort = new Label("Parole jabut vismaz 4 simboliem");
- passtooshort.setStyle("-fx-text-fill: red;");
- Label passnotmatch = new Label("Paroles nesakrit!");
- passnotmatch.setStyle("-fx-text-fill: red;");
- password2.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent arg0) {
- String getTextfrompassword = password2.getText();
- String getTextfrompassword2 = password3.getText();
- if(!getTextfrompassword.equals(getTextfrompassword2) && getTextfrompassword.length() > 0) {
- passnotmatch.setVisible(true);
- passnotmatch.setManaged(true);
- }
- else {
- passnotmatch.setManaged(false);
- passnotmatch.setVisible(false);
- }
- if(getTextfrompassword.length() < 4) {
- passtooshort.setVisible(true);
- passtooshort.setManaged(true);
- }
- else {
- passtooshort.setManaged(false);
- passtooshort.setVisible(false);
- }
- }
- });
- password3.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent arg0) {
- String getTextfrompassword = password2.getText();
- String getTextfrompassword2 = password3.getText();
- if(!getTextfrompassword.equals(getTextfrompassword2) && getTextfrompassword.length() > 0) {
- passnotmatch.setVisible(true);
- passnotmatch.setManaged(true);
- }
- else {
- passnotmatch.setManaged(false);
- passnotmatch.setVisible(false);
- }
- if(getTextfrompassword.length() < 4) {
- passtooshort.setVisible(true);
- passtooshort.setManaged(true);
- }
- else {
- passtooshort.setManaged(false);
- passtooshort.setVisible(false);
- }
- }
- });
- change.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- String passwordcode = "";
- boolean status = false;
- boolean changestatus = false;
- String newcode = "";
- int ID_user = 0;
- Alert alert2 = new Alert(AlertType.CONFIRMATION);
- alert2.setTitle("Mainit paroli?");
- alert2.setHeaderText("Vai tiesam mainit paroli?");
- Optional<ButtonType> result = alert2.showAndWait();
- if (result.get() == ButtonType.OK){
- if(password2.getText().equals(password3.getText()) && password2.getText().length() > 3) {
- try {
- passwordcode = functions.encrypt(password.getText());
- status = dbcon.login(loggeduser, passwordcode);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- if(status) {
- try {
- ID_user = dbcon.getuserid(loggeduser);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- try {
- newcode = functions.encrypt(password2.getText());
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- try {
- changestatus = dbcon.changepassword(ID_user, newcode);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(changestatus) {
- stage.close();
- Alert alert = new Alert(Alert.AlertType.INFORMATION);
- System.out.println("Parole nomainita");
- alert.setTitle("Operacija veiksmiga");
- alert.setHeaderText("Parole mainita");
- alert.show();
- }
- else {
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Operacija neveiksmiga");
- alert.setTitle("Operacija neveiksmiga");
- alert.setHeaderText("Parole netika mainita");
- alert.show();
- }
- }
- else {
- password.setText("");
- password2.setText("");
- password3.setText("");
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Operacija neveiksmiga(nepareiza parole)");
- alert.setTitle("Operacija neveiksmiga");
- alert.setHeaderText("Nepareiza parole");
- alert.show();
- }
- }
- else {
- password.setText("");
- password2.setText("");
- password3.setText("");
- Alert alert = new Alert(Alert.AlertType.ERROR);
- System.out.println("Operacija neveiksmiga(neizpilditas prasibas)");
- alert.setTitle("Operacija neveiksmiga");
- alert.setHeaderText("Nav izpilditas paroles mainas prasibas");
- alert.show();
- }
- }
- }
- });
- vbox.getChildren().addAll(changenameinfo, passtxt, password, passtxt2, password2, passtxt3, password3, passtooshort, passnotmatch, change);
- Scene sc = new Scene(vbox, 300, 230);
- sc.getStylesheets().add("changepasswordpanel.css");
- stage.setScene(sc);
- stage.getIcons().add(new Image("logo.png"));
- stage.setTitle("Mainit paroli");
- stage.resizableProperty().setValue(Boolean.FALSE);
- stage.show();
- }
- //Misc functions
- public void setloggeduser(String loggeduser) {
- this.loggeduser = loggeduser;
- }
- public String getloggeduser() {
- return loggeduser;
- }
- public void setuserlevel(String userlevel) {
- this.loggeduser = userlevel;
- }
- public String getuserlevel() {
- return userlevel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement