From 7ac2d94ec237ca76ee7bdbdc8d86d155536bf47d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 22 Jul 2021 16:52:18 +0300 Subject: Very roughly implemented password updating --- go-src/windows.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'go-src/windows.go') 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() -- cgit v1.2.3