@@ -18,24 +18,37 @@ Login as HMD successfully!
1818
1919 static flags = {
2020 help : flags . help ( { char : 'h' } ) ,
21- email : flags . string ( { char : 'u' , description : 'Login email' } )
21+ id : flags . string ( { char : 'u' , description : 'Login email/username' } ) ,
22+ ldap : flags . boolean ( )
2223 }
2324
2425 async run ( ) {
2526 const { flags} = this . parse ( Login )
2627
27- let email = flags . email
28-
29- if ( ! email ) {
30- const out = await inquirer . prompt ( {
31- type : 'input' ,
32- name : 'email' ,
33- message : 'Enter your email'
34- } )
35- email = out . email
36- if ( ! email ) {
37- // TODO: do more email validation
38- return this . log ( 'No email is given' )
28+ let id = flags . id
29+
30+ if ( ! id ) {
31+ if ( flags . ldap ) {
32+ const out = await inquirer . prompt ( {
33+ type : 'input' ,
34+ name : 'username' ,
35+ message : 'Enter your username'
36+ } )
37+ id = out . username
38+ if ( ! id ) {
39+ return this . log ( 'No username is given' )
40+ }
41+ } else {
42+ const out = await inquirer . prompt ( {
43+ type : 'input' ,
44+ name : 'email' ,
45+ message : 'Enter your email'
46+ } )
47+ id = out . email
48+ if ( ! id ) {
49+ // TODO: do more email validation
50+ return this . log ( 'No email is given' )
51+ }
3952 }
4053 }
4154
@@ -46,10 +59,16 @@ Login as HMD successfully!
4659 } )
4760
4861 try {
49- if ( await APIClient . login ( email , password ) ) {
62+ let success = false
63+ if ( flags . ldap ) {
64+ success = await APIClient . loginLdap ( id , password )
65+ } else {
66+ success = await APIClient . login ( id , password )
67+ }
68+ if ( success ) {
5069 return this . log ( 'Login successfully' )
5170 } else {
52- this . log ( 'Login failed, please ensure your email/password is set' )
71+ this . log ( 'Login failed, please ensure your credentials are set' )
5372 }
5473 } catch ( err ) {
5574 this . error ( err )
0 commit comments