summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-22 17:15:34 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-22 17:15:34 +0200
commit80218da58eca9c95870770f88e477891e8fdb50a (patch)
tree66f685f2bcbbaaac0031d2e7a83f306358043a88 /state.go
parent0c9a300a58d9dacce7b84ff93222eed35eab5721 (diff)
State + FSM + Exports: Implement changing a secure internet location
Diffstat (limited to 'state.go')
-rw-r--r--state.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/state.go b/state.go
index 2f7e785..d559c88 100644
--- a/state.go
+++ b/state.go
@@ -154,7 +154,7 @@ func (state *VPNState) SetSecureLocation(countryCode string) error {
return nil
}
-func (state *VPNState) AskSecureLocation() error {
+func (state *VPNState) askSecureLocation() error {
errorMessage := "failed asking Secure Internet location"
locations, locationsErr := state.Discovery.GetSecureLocationList()
if locationsErr != nil {
@@ -184,7 +184,7 @@ func (state *VPNState) addSecureInternetHomeServer(orgID string) (server.Server,
var locationErr error
if !state.Servers.HasSecureLocation() {
- locationErr = state.AskSecureLocation()
+ locationErr = state.askSecureLocation()
} else {
// reinitialize
locationErr = state.SetSecureLocation(state.Servers.GetSecureLocation())
@@ -285,6 +285,25 @@ func (state *VPNState) CancelOAuth() error {
return nil
}
+func (state *VPNState) ChangeSecureLocation() error {
+ errorMessage := "failed to change location from the main screen"
+
+ if !state.FSM.InState(fsm.NO_SERVER) {
+ return &types.WrappedErrorMessage{Message: errorMessage, Err: fsm.WrongStateError{Got: state.FSM.Current, Want: fsm.NO_SERVER}.CustomError()}
+ }
+
+ askLocationErr := state.askSecureLocation()
+
+ if askLocationErr != nil {
+ return &types.WrappedErrorMessage{Message: errorMessage, Err: askLocationErr}
+ }
+
+ // Go back to the main screen
+ state.FSM.GoTransitionWithData(fsm.NO_SERVER, state.GetSavedServers(), false)
+
+ return nil
+}
+
func (state *VPNState) GetDiscoOrganizations() (string, error) {
if state.FSM.InState(fsm.DEREGISTERED) {
return "", &types.WrappedErrorMessage{Message: "failed to get the organizations with Discovery", Err: fsm.DeregisteredError{}.CustomError()}