@@ -18,24 +18,37 @@ Login as HMD successfully!
18
18
19
19
static flags = {
20
20
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 ( )
22
23
}
23
24
24
25
async run ( ) {
25
26
const { flags} = this . parse ( Login )
26
27
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
+ }
39
52
}
40
53
}
41
54
@@ -46,10 +59,16 @@ Login as HMD successfully!
46
59
} )
47
60
48
61
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 ) {
50
69
return this . log ( 'Login successfully' )
51
70
} else {
52
- this . log ( 'Login failed, please ensure your email/password is set' )
71
+ this . log ( 'Login failed, please ensure your credentials are set' )
53
72
}
54
73
} catch ( err ) {
55
74
this . error ( err )
0 commit comments