aboutsummaryrefslogtreecommitdiff
path: root/go-src
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-07-22 16:52:18 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-07-22 16:52:18 +0300
commit7ac2d94ec237ca76ee7bdbdc8d86d155536bf47d (patch)
tree81e331a3ead6499e44741792637353176cde469e /go-src
parent137d7cc9a77139fe7a267800419f0c85884f3e0f (diff)
downloadctfc-7ac2d94ec237ca76ee7bdbdc8d86d155536bf47d.tar
ctfc-7ac2d94ec237ca76ee7bdbdc8d86d155536bf47d.tar.gz
ctfc-7ac2d94ec237ca76ee7bdbdc8d86d155536bf47d.zip
Very roughly implemented password updating
Diffstat (limited to 'go-src')
-rw-r--r--go-src/user.go8
-rw-r--r--go-src/windowMessages.go4
-rw-r--r--go-src/windows.go55
-rw-r--r--go-src/windowsHelpers.go2
4 files changed, 59 insertions, 10 deletions
diff --git a/go-src/user.go b/go-src/user.go
index 0cbe5b0..9ea269a 100644
--- a/go-src/user.go
+++ b/go-src/user.go
@@ -46,3 +46,11 @@ func validatePassword(username string, password string) bool {
passHash := bytes.Split(f, []byte("\n"))[1]
return string(passHash) == password
}
+
+func updatePassword(oldPassword string, newPassword string) bool {
+ if !validatePassword(loggedInUser.Username, oldPassword) {
+ return false
+ }
+ os.WriteFile(folderPaths.FileAtUsersFolder(loggedInUser.Username), []byte(loggedInUser.Username+"\n"+newPassword+"\n"+loggedInUser.Name), 755)
+ return true
+}
diff --git a/go-src/windowMessages.go b/go-src/windowMessages.go
index 4f3e151..21dd094 100644
--- a/go-src/windowMessages.go
+++ b/go-src/windowMessages.go
@@ -24,6 +24,7 @@ const (
// Input specifications
startupWindowSpec = "[L/R]"
chatWindowSpec = "Message or [C/D/A/L/</>/H]"
+ accountWindowSpec = "[C/D/L/number/H]"
logoutWindowSpec = "[Y/N]"
inputBackSpec = " or [B for Back to start page]"
usernameSpec = " [A-z, 0-9, *, ., _, -; at least 1 letter] or [B for Back to start page]"
@@ -32,4 +33,7 @@ const (
chatsSpec = "[D/A/L/</>/C/E/name/number/H]"
chatNameSpec = " [2-20 characters; A-z, 0-9, spaces, _, -] or [B for Back to chats page]"
chatDescSpec = " [0-30 characters]"
+
+ // Other
+ hiddenValue = "[HIDDEN]"
)
diff --git a/go-src/windows.go b/go-src/windows.go
index 20dedca..93e27f9 100644
--- a/go-src/windows.go
+++ b/go-src/windows.go
@@ -19,15 +19,15 @@ func StartupWindow(...string) {
ui.NormalBox(true, loginNavTitle, registerNavTitle)
input := ui.InputField(startupWindowSpec)
- handled := handleInputActions(input, false,
+ nextWindow := handleInputActions(input, false,
inputAction{"L", loginWindow, nil},
inputAction{"R", registerWindow, nil},
)
- if handled == nil {
+ if nextWindow == nil {
defer showError(invalidCommand, StartupWindow)
} else {
- defer handled()
+ defer nextWindow()
}
}
@@ -105,12 +105,12 @@ func chatsWindow(values ...string) {
input := ui.InputField(chatsSpec)
- handled := handleInputActions(input, true,
+ nextWindow := handleInputActions(input, true,
inputAction{"C", createChatWindow, nil},
inputAction{"H", chatsWindow, []string{values[0], showHelp}},
)
- if handled == nil {
+ if nextWindow == nil {
// If user input is number, navigate to chat of given number, else show error
if chatI, err := strconv.Atoi(input); chatI >= 0 && chatI <= len(allChats) && err == nil {
defer chatWindow(strings.Split(allChats[utils.MaxInt(len(allChats)-pageSize*len(values[0]), 0)+chatI-1], " : ")[0])
@@ -132,7 +132,7 @@ func chatsWindow(values ...string) {
defer showError(invalidCommand, chatsWindow)
}
} else {
- defer handled()
+ defer nextWindow()
}
lastLine = -2
}
@@ -192,11 +192,11 @@ func chatWindow(values ...string) {
input := ui.InputField(chatWindowSpec)
- handled := handleInputActions(input, true,
+ nextWindow := handleInputActions(input, true,
inputAction{"H", chatWindow, []string{values[0], values[1], showHelp}},
)
- if handled == nil {
+ if nextWindow == nil {
switch input {
case ">":
// If possible, increment to the next page (adds a dot to the end of the string)
@@ -216,11 +216,48 @@ func chatWindow(values ...string) {
defer chatWindow(values...)
} else {
- defer handled()
+ defer nextWindow()
}
lastLine = -2 // Practically stops execution of the paginated subwindow routine
}
+func accountWindow(...string) {
+ csi.ClearScreen()
+
+ ui.NormalBox(true, chatNavTitle, directMessagesNavTitle, logoutNavTitle)
+ ui.TextField(usernameInName + " : " + loggedInUser.Username)
+ ui.NumberedFields(
+ passwordInName+" : "+hiddenValue,
+ nameInName+" : "+loggedInUser.Name,
+ )
+
+ ui.EmptyLine()
+ input := ui.InputField(accountWindowSpec)
+
+ nextWindow := handleInputActions(input, true)
+
+ if nextWindow == nil {
+ if editI, err := strconv.Atoi(input); editI > 0 && editI < 2 && err == nil {
+ switch editI {
+ case 1:
+ pass := formWindow("Editing", accountWindow,
+ []formInput{
+ {"Current password", inputBackSpec, nil},
+ {"New password", "", stringValidPassword},
+ },
+ )
+ if !updatePassword(pass[0], pass[1]) {
+ defer showError(invalidArgument, accountWindow)
+ }
+ }
+ } else {
+ defer showError(invalidCommand, accountWindow)
+ }
+ } else {
+ defer nextWindow()
+ }
+}
+
func logoutWindow(...string) {
csi.ClearScreen()
diff --git a/go-src/windowsHelpers.go b/go-src/windowsHelpers.go
index beef465..f3b7ff0 100644
--- a/go-src/windowsHelpers.go
+++ b/go-src/windowsHelpers.go
@@ -77,7 +77,7 @@ func handleInputActions(input string, handleNav bool, ia ...inputAction) func()
ia = append(ia,
inputAction{"C", chatsWindow, nil},
inputAction{"D", chatsWindow, nil},
- inputAction{"A", chatsWindow, nil},
+ inputAction{"A", accountWindow, nil},
inputAction{"L", logoutWindow, nil},
)
}