From 8d2a402e188a911b4e01d0388f776f592c7b162c Mon Sep 17 00:00:00 2001 From: Timothy Vane-Tempest Date: Fri, 30 Nov 2018 18:24:05 +0200 Subject: [PATCH] Added option to give password to login as a command line argument --- lib/commands/login.js | 2 +- src/commands/login.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/commands/login.js b/lib/commands/login.js index 8410961..894beee 100644 --- a/lib/commands/login.js +++ b/lib/commands/login.js @@ -1 +1 @@ -const prompt=require('../util/prompt'),signInUser=()=>{let a,b;return Promise.resolve(pgb.opts.commands[1]||pgb.opts.variables.auth_token||prompt('Adobe ID or Authentication Token: ')).then(c=>(a=c,c.match('^[^@]+@[^@]+.[^@]+$')?prompt('Password: ',{mask:!0}).then(c=>(b=c,pgb.api.addAuth(a,b),pgb.api.getToken(a,b))):(pgb.api.addAuth(c),{token:c}))).then(a=>(pgb.debug(`saving auth_token to ${pgb.session.path}`),pgb.session.save({authtoken:a.token}),pgb.api.me())).catch(a=>{if(a&&401===a.statusCode){let a=b?'Adobe ID or password incorrect':'invalid authentication token';return Promise.reject(new Error(a))}return Promise.reject(a)})};module.exports=()=>pgb.api.me().catch(signInUser).then(a=>pgb.print({pretty:'signed in as '+pgb.colours.bold(a.email),json:a,bare:a.id})); \ No newline at end of file +const prompt=require('../util/prompt'),signInUser=()=>{let a,b;return Promise.resolve(pgb.opts.commands[1]||pgb.opts.variables.auth_token||prompt('Adobe ID or Authentication Token: ')).then(c=>(a=c,c.match('^[^@]+@[^@]+.[^@]+$')?Promise.resolve(pgb.opts.commands[2]||prompt('Password: ',{mask:!0})).then(c=>(b=c,pgb.api.addAuth(a,b),pgb.api.getToken(a,b))):(pgb.api.addAuth(c),{token:c}))).then(a=>(pgb.debug(`saving auth_token to ${pgb.session.path}`),pgb.session.save({authtoken:a.token}),pgb.api.me())).catch(a=>{if(a&&401===a.statusCode){let a=b?'Adobe ID or password incorrect':'invalid authentication token';return Promise.reject(new Error(a))}return Promise.reject(a)})};module.exports=()=>pgb.api.me().catch(signInUser).then(a=>pgb.print({pretty:'signed in as '+pgb.colours.bold(a.email),json:a,bare:a.id})); \ No newline at end of file diff --git a/src/commands/login.js b/src/commands/login.js index ecd3b89..bafed9c 100644 --- a/src/commands/login.js +++ b/src/commands/login.js @@ -10,7 +10,7 @@ const signInUser = () => { pgb.api.addAuth(token) return { token } } - return prompt('Password: ', { mask: true }) + return Promise.resolve(pgb.opts.commands[2] || prompt('Password: ', { mask: true })) .then(response => { password = response pgb.api.addAuth(username, password)