@@ -11,31 +11,27 @@ const configuration = require('../lib/settings')();
1111
1212program
1313 . arguments ( '<url>' )
14- . option ( '-r, --reset' , 'Request password reset' )
15- . option ( '-t, --token' , 'Display current JSON Web Token' )
16- . action ( url => account ( Object . assign ( { url : url } , program ) ) )
14+ . action ( url => login ( Object . assign ( { url : url , program} ) ) )
1715 . parse ( process . argv ) ;
1816
19- if ( ! program . args . length ) account ( program . opts ( ) ) ;
17+ if ( ! program . args . length ) login ( program . opts ( ) ) ;
2018
21- function account ( { url, token , reset } ) {
19+ function login ( { url} ) {
2220 if ( url && ! urlRegex ( { exact : true } ) . test ( url ) ) {
23- console . log ( chalk . red ( 'Invalid DROPSTACK URL. Must be the format http(s)://host.domain.com.' ) ) ;
21+ console . log ( chalk . red ( 'Invalid Dropstack-Server- URL. Must be the format http(s)://host.domain.com.' ) ) ;
2422 return process . exit ( 1 ) ;
2523 }
2624
27- configuration
28- . load ( { url, reset} )
29- . then ( settings => configuration . save ( settings ) )
25+ configuration . removeGlobalFile ( )
26+ . then ( ( ) => configuration . load ( { url} ) )
3027 . then ( settings => {
3128 console . log ( chalk . green ( `Account information for ${ chalk . green . underline ( settings . username || '-' ) } on ${ chalk . green . underline ( settings . url || '-' ) } ` ) ) ;
32- if ( ! ( settings . token && settings . username ) ) console . log ( chalk . yellow ( `Enter your email and password to log in or sign up for free!\n` ) ) ;
29+ console . log ( chalk . yellow ( `Enter your email and password to log in or sign up for free!\n` ) ) ;
3330 return settings ;
3431 } )
35- . then ( settings => reset ? credentials . reset ( settings ) . then ( data => Promise . reject ( data ) ) : Promise . resolve ( settings ) )
36- . then ( settings => ! settings . token ? credentials . inputEmail ( settings . username ) . then ( data => Object . assign ( settings , data ) ) : Promise . resolve ( settings ) )
37- . then ( settings => ! settings . token ? credentials . inputPassword ( settings . password ) . then ( data => Object . assign ( settings , data ) ) : Promise . resolve ( settings ) )
38- . then ( settings => ! settings . token ? credentials . login ( settings ) . catch ( ( ) => credentials . signup ( settings ) ) . then ( data => Object . assign ( settings , data ) ) : Promise . resolve ( settings ) )
32+ . then ( settings => credentials . inputEmail ( settings . username ) . then ( data => Object . assign ( settings , data ) ) )
33+ . then ( settings => credentials . inputPassword ( settings . password ) . then ( data => Object . assign ( settings , data ) ) )
34+ . then ( settings => credentials . login ( settings ) . catch ( ( ) => credentials . signup ( settings ) ) . then ( data => Object . assign ( settings , data ) ) )
3935 . then ( settings => {
4036 if ( ! settings . token ) return Promise . reject ( new Error ( 'Sign in failed. Use `dropstack login` to log in with your credentials.' ) ) ;
4137 if ( settings . message ) return Promise . reject ( new Error ( settings . message ) ) ;
@@ -51,17 +47,11 @@ function account({url, token, reset}) {
5147 . then ( data => Boolean ( data . message ) ? Promise . reject ( new Error ( data . message ) ) : data )
5248 . then ( data => {
5349 let message = `${ chalk . green ( `User ${ chalk . bold ( data . id ) } logged in successful!\n\n` ) } ` ;
54- message += `• ${ chalk . gray ( `Server-Version: ${ data . version } ` ) } ` ;
55- if ( token ) message = `${ chalk . gray ( `JWT: ${ data . token } ` ) } ` ;
50+ message += `• ${ chalk . gray ( `Server Version: ${ chalk . white ( data . version ) } ` ) } ` ;
5651 console . log ( boxen ( message , { padding : 1 , borderColor : 'gray' , margin : 1 } ) ) ;
57-
5852 process . exit ( 0 ) ;
5953 } )
6054 . catch ( err => {
61- if ( err . message === '"We\'ve just sent you an email to reset your password"' ) {
62- console . log ( chalk . red ( err . message ) ) ;
63- return process . exit ( 0 ) ;
64- }
6555 if ( err . message === 'canceled' ) {
6656 console . log ( chalk . yellow ( 'aborted' ) ) ;
6757 return process . exit ( 0 ) ;
0 commit comments