From 870201a7bd6e0d8e4469d1da7bbee94859762e84 Mon Sep 17 00:00:00 2001 From: simon <sw4wang@uwaterloo.ca> Date: Fri, 31 Mar 2023 15:28:01 -0400 Subject: [PATCH] Adding login manager popup --- .../net/codebot/application/LoginManager.kt | 72 +++++++++++++++++++ .../kotlin/net/codebot/application/Main.kt | 26 +++++-- 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 application/src/main/kotlin/net/codebot/application/LoginManager.kt diff --git a/application/src/main/kotlin/net/codebot/application/LoginManager.kt b/application/src/main/kotlin/net/codebot/application/LoginManager.kt new file mode 100644 index 0000000..28e0a76 --- /dev/null +++ b/application/src/main/kotlin/net/codebot/application/LoginManager.kt @@ -0,0 +1,72 @@ +package net.codebot.application + +import javafx.event.EventHandler +import javafx.geometry.Insets +import javafx.geometry.Pos +import javafx.scene.Scene +import javafx.scene.control.Button +import javafx.scene.control.Label +import javafx.scene.control.PasswordField +import javafx.scene.control.TextField +import javafx.scene.layout.GridPane +import javafx.scene.layout.HBox +import javafx.scene.layout.StackPane +import javafx.scene.paint.Color +import javafx.scene.text.Text +import javafx.stage.Stage + + +class LoginManager { + fun build(self: Stage, markdown: Stage): StackPane { + val grid = GridPane() + grid.alignment = Pos.CENTER + grid.hgap = 10.0 + grid.vgap = 10.0 + grid.padding = Insets(25.0, 25.0, 25.0, 25.0) + + val gridTitle = Text("User Login") + grid.add(gridTitle, 0, 0, 2, 1) + + val userName = Label("User Name:") + grid.add(userName, 0, 1) + val userTextField = TextField() + grid.add(userTextField, 1, 1) + + val pw = Label("Password:") + grid.add(pw, 0, 2) + val pwBox = PasswordField() + grid.add(pwBox, 1, 2) + + // Defining sign in buttons and their placement + val guestBtn = Button("Sign in as Guest") + val userBtn = Button("Sign in") + val hbBtn = HBox(10.0) + hbBtn.alignment = Pos.BOTTOM_RIGHT + hbBtn.children.addAll(guestBtn, userBtn) + grid.add(hbBtn, 1, 4) + + val actiontarget = Text() + grid.add(actiontarget, 1, 6) + + guestBtn.onAction = EventHandler { + markdown.show() + self.hide() + } + + userBtn.onAction = EventHandler { + actiontarget.setFill(Color.FIREBRICK) + val user = userTextField.text + val password = pwBox.text + + if (user == "") { + actiontarget.setText("Enter a user name.") + } else if (password == "") { + actiontarget.setText("Enter a password.") + } else { + actiontarget.setText("Username: " + user + " Password: " + password) + } + } + + return StackPane(grid) + } +} \ No newline at end of file diff --git a/application/src/main/kotlin/net/codebot/application/Main.kt b/application/src/main/kotlin/net/codebot/application/Main.kt index 71ec228..a355a00 100644 --- a/application/src/main/kotlin/net/codebot/application/Main.kt +++ b/application/src/main/kotlin/net/codebot/application/Main.kt @@ -11,13 +11,17 @@ import com.vladsch.flexmark.util.data.MutableDataSet import com.vladsch.flexmark.util.misc.Extension import javafx.application.Application import javafx.event.EventHandler +import javafx.geometry.Insets +import javafx.geometry.Pos import javafx.scene.Scene import javafx.scene.control.* import javafx.scene.input.* import javafx.scene.layout.BorderPane +import javafx.scene.layout.GridPane import javafx.scene.layout.HBox import javafx.scene.layout.VBox import javafx.scene.text.Font +import javafx.scene.text.Text import javafx.scene.web.WebView import javafx.stage.FileChooser import javafx.stage.Stage @@ -34,7 +38,8 @@ class Main : Application() { var userConfig = initConfig() // variables to know on startup? maybe user preferences etc. var cur_theme = "darkMode.css" - + // stage for login window + val loginStage = Stage() var cur_file: FolderView.cur_File = FolderView.cur_File() val bold = Button("B") @@ -195,8 +200,9 @@ class Main : Application() { val new = MenuItem("New") val saveAsFile = MenuItem("Save As") val saveFile = MenuItem("Save") + val signOut = MenuItem("Sign Out") val exitApp = MenuItem("Exit") - file.items.addAll(openFile, new, saveFile, saveAsFile, exitApp) + file.items.addAll(openFile, new, saveFile, saveAsFile, signOut,exitApp) val edit = Menu("Edit") val undo = MenuItem("Undo") @@ -345,7 +351,12 @@ class Main : Application() { } } - + signOut.onAction = EventHandler { + stage.hide() + loginStage.show() + loginStage.scene = Scene(LoginManager().build(loginStage, stage)) + // reset stage as well + } // Undo, Redo undo.isDisable = true @@ -445,7 +456,12 @@ class Main : Application() { stage.height = 450.0 stage.title = "Markdown Editor" stage.scene = scene - stage.show() - } + stage.hide() + // authentication box + val loginScene = Scene(LoginManager().build(loginStage, stage)) + loginStage.scene = loginScene + loginStage.title = "User Login" + loginStage.show() + } } \ No newline at end of file -- GitLab