From 9ba9248ebea1209db2c0f005135fa7bfaf8dedf6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 11 Sep 2021 15:58:02 +0300 Subject: Abstracted logic for updating multiple properties with password validation (for each) --- go-src/windows.go | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'go-src/windows.go') diff --git a/go-src/windows.go b/go-src/windows.go index 31c2fb0..5463cd2 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -1,7 +1,6 @@ package ctfc import ( - "strconv" "strings" "gitlab.com/Syndamia/ctfc/go-src/csi" @@ -254,7 +253,6 @@ func directMessagesWindow(values ...string) { defer nextWindow() } lastLine = -2 - } func directMessageWindow(values ...string) { @@ -341,31 +339,18 @@ func accountWindow(values ...string) { ) if nextWindow == nil { - userProp, _ := strconv.Atoi(input) - inputs, updateSuccessful := []formInput{{currentPasswordInName, inputBackSpec, nil}}, false - - switch UserProp(userProp) { - case passwordProp: - values := formWindow(editPasswordNavTitle, accountWindow, - append(inputs, formInput{newPasswordInName, passwordSpec, stringValidPassword}), - ) - updateSuccessful = loggedInUser.UpdatePassword(values[0], values[1]) - case nameProp: - values := formWindow(editNameNavTitle, accountWindow, - append(inputs, formInput{newNameInName, nameSpec, stringValidName}), - ) - updateSuccessful = loggedInUser.UpdateName(values[0], values[1]) - loggedInUser.Name = utils.If(updateSuccessful).String(values[1], loggedInUser.Name) - default: - defer showError(invalidCommand, accountWindow) - return - } - - if !updateSuccessful { - defer showError(invalidArgument, accountWindow) - } else { - defer accountWindow() - } + defer validatedMultiForm(input, accountWindow, + multiFormProp{int(passwordProp), editPasswordNavTitle, + formInput{newPasswordInName, passwordSpec, stringValidPassword}, + func(values []string) bool { return loggedInUser.UpdatePassword(values[0], values[1]) }, + nil, + }, + multiFormProp{int(nameProp), editNameNavTitle, + formInput{newNameInName, nameSpec, stringValidName}, + func(values []string) bool { return loggedInUser.UpdateName(values[0], values[1]) }, + func(values []string) { loggedInUser.Name = values[1] }, + }, + ) } else { defer nextWindow() } -- cgit v1.2.3