@@ -26,7 +26,8 @@ import {
2626 getActiveConnection ,
2727 setActiveConnection ,
2828 updateConnection ,
29- CONNECT
29+ CONNECT ,
30+ VERIFY_CREDENTIALS
3031} from 'shared/modules/connections/connectionsDuck'
3132import { getInitCmd } from 'shared/modules/settings/settingsDuck'
3233import { executeSystemCommand } from 'shared/modules/commands/commandsDuck'
@@ -49,6 +50,7 @@ export class ConnectionForm extends Component {
4950 this . state = {
5051 ...connection ,
5152 isConnected : isConnected ,
53+ isLoading : false ,
5254 passwordChangeNeeded : props . passwordChangeNeeded || false ,
5355 forcePasswordChange : props . forcePasswordChange || false ,
5456 successCallback : props . onSuccess || ( ( ) => { } ) ,
@@ -57,24 +59,41 @@ export class ConnectionForm extends Component {
5759 }
5860 tryConnect = ( password , doneFn ) => {
5961 this . props . error ( { } )
60- this . props . bus . self ( CONNECT , { ...this . state , password } , res => {
61- doneFn ( res )
62- } )
62+ this . props . bus . self (
63+ VERIFY_CREDENTIALS ,
64+ { ...this . state , password } ,
65+ res => {
66+ doneFn ( res )
67+ }
68+ )
6369 }
64- connect = ( doneFn = ( ) => { } ) => {
70+ connect = (
71+ doneFn = ( ) => { } ,
72+ onError = null ,
73+ noResetConnectionOnFail = false
74+ ) => {
6575 this . props . error ( { } )
66- this . props . bus . self ( CONNECT , this . state , res => {
67- doneFn ( )
68- if ( res . success ) {
69- this . saveAndStart ( )
70- } else {
71- if ( res . error . code === 'Neo.ClientError.Security.CredentialsExpired' ) {
72- this . setState ( { passwordChangeNeeded : true } )
76+ this . props . bus . self (
77+ CONNECT ,
78+ { ... this . state , noResetConnectionOnFail } ,
79+ res => {
80+ doneFn ( )
81+ if ( res . success ) {
82+ this . saveAndStart ( )
7383 } else {
74- this . props . error ( res . error )
84+ if (
85+ res . error . code === 'Neo.ClientError.Security.CredentialsExpired'
86+ ) {
87+ this . setState ( { passwordChangeNeeded : true } )
88+ } else {
89+ if ( onError ) {
90+ return onError ( res )
91+ }
92+ this . props . error ( res . error )
93+ }
7594 }
7695 }
77- } )
96+ )
7897 }
7998 onUsernameChange ( event ) {
8099 const username = event . target . value
@@ -98,10 +117,13 @@ export class ConnectionForm extends Component {
98117 this . props . error ( { } )
99118 }
100119 onChangePassword ( { newPassword, error } ) {
120+ this . setState ( { isLoading : true } )
101121 if ( error && error . code ) {
122+ this . setState ( { isLoading : false } )
102123 return this . props . error ( error )
103124 }
104125 if ( this . state . password === null ) {
126+ this . setState ( { isLoading : false } )
105127 return this . props . error ( { message : 'Please set existing password' } )
106128 }
107129 this . props . error ( { } )
@@ -117,9 +139,38 @@ export class ConnectionForm extends Component {
117139 response => {
118140 if ( response . success ) {
119141 return this . setState ( { password : newPassword } , ( ) => {
120- this . connect ( )
142+ let retries = 5
143+ const retryFn = res => {
144+ // New password not accepted yet, initiate retry
145+ if ( res . error . code === 'Neo.ClientError.Security.Unauthorized' ) {
146+ retries --
147+ if ( retries > 0 ) {
148+ setTimeout (
149+ ( ) =>
150+ this . connect (
151+ ( ) => {
152+ this . setState ( { isLoading : false } )
153+ } ,
154+ retryFn ,
155+ true
156+ ) ,
157+ 200
158+ )
159+ }
160+ } else {
161+ this . props . error ( res . error )
162+ }
163+ }
164+ this . connect (
165+ ( ) => {
166+ this . setState ( { isLoading : false } )
167+ } ,
168+ retryFn ,
169+ true
170+ )
121171 } )
122172 }
173+ this . setState ( { isLoading : false } )
123174 this . props . error ( response . error )
124175 }
125176 )
@@ -160,7 +211,12 @@ export class ConnectionForm extends Component {
160211 showExistingPasswordInput = { this . props . showExistingPasswordInput }
161212 onChangePasswordClick = { this . onChangePassword . bind ( this ) }
162213 onChange = { this . onChangePasswordChange . bind ( this ) }
163- tryConnect = { this . tryConnect }
214+ tryConnect = { ( password , doneFn ) => {
215+ this . setState ( { isLoading : true } , ( ) =>
216+ this . tryConnect ( password , doneFn )
217+ )
218+ } }
219+ isLoading = { this . state . isLoading }
164220 >
165221 { this . props . children }
166222 </ ChangePasswordForm >
0 commit comments