@ -100,8 +100,41 @@ class LoginForm extends React.PureComponent {
this . input = c ;
} ;
isValueValid = ( value ) => {
let likelyAcct = false ;
let url = null ;
if ( value . startsWith ( '/' ) ) {
return false ;
}
if ( value . startsWith ( '@' ) ) {
value = value . slice ( 1 ) ;
likelyAcct = true ;
}
/ / T h e u s e r i s i n t h e m i d d l e o f t y p i n g s o m e t h i n g , d o n o t e r r o r o u t
if ( value === '' ) {
return true ;
}
if ( /^https?:\/\// . test ( value ) && ! likelyAcct ) {
url = value ;
} else {
url = ` https:// ${ value } ` ;
}
try {
new URL ( url ) ;
return true ;
} catch ( _ ) {
return false ;
}
} ;
handleChange = ( { target } ) => {
this . setState ( state => ( { value : target . value , isLoading : true , error : false , options : addInputToOptions ( target . value , state . networkOptions ) } ) , ( ) => this . _loadOptions ( ) ) ;
const error = ! this . isValueValid ( target . value ) ;
this . setState ( state => ( { error , value : target . value , isLoading : true , options : addInputToOptions ( target . value , state . networkOptions ) } ) , ( ) => this . _loadOptions ( ) ) ;
} ;
handleMessage = ( event ) => {
@ -115,11 +148,18 @@ class LoginForm extends React.PureComponent {
this . setState ( { isSubmitting : false , error : true } ) ;
} else if ( event . data ? . type === 'fetchInteractionURL-success' ) {
if ( /^https?:\/\// . test ( event . data . template ) ) {
try {
const url = new URL ( event . data . template . replace ( '{uri}' , encodeURIComponent ( resourceUrl ) ) ) ;
if ( localStorage ) {
localStorage . setItem ( PERSISTENCE _KEY , event . data . uri _or _domain ) ;
}
window . location . href = event . data . template . replace ( '{uri}' , encodeURIComponent ( resourceUrl ) ) ;
window . location . href = url ;
} catch ( e ) {
console . error ( e ) ;
this . setState ( { isSubmitting : false , error : true } ) ;
}
} else {
this . setState ( { isSubmitting : false , error : true } ) ;
}
@ -259,7 +299,7 @@ class LoginForm extends React.PureComponent {
spellcheck = 'false'
/ >
< Button onClick = { this . handleSubmit } disabled = { isSubmitting } > < FormattedMessage id = 'interaction_modal.login.action' defaultMessage = 'Take me home' / > < / Button >
< Button onClick = { this . handleSubmit } disabled = { isSubmitting || error } > < FormattedMessage id = 'interaction_modal.login.action' defaultMessage = 'Take me home' / > < / Button >
< / div >
{ hasPopOut && (