From 8379e158cfd7ee78540b79a684b990fa18bef959 Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Sun, 4 Jun 2017 13:39:05 +0200 Subject: [PATCH] password prompt for mail targets --- CHANGELOG.md | 2 +- src/plugins/mail.ts | 59 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86da5cc..381ca5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 9.16.0 (June 4th, 2017; password prompts) -* password box is shown now if no password is defined in [FTP target](https://github.com/mkloubert/vs-deploy/wiki/target_ftp) +* password box is shown now if no password is defined in [FTP](https://github.com/mkloubert/vs-deploy/wiki/target_ftp) and [mail](https://github.com/mkloubert/vs-deploy/wiki/target_mail) targets ## 9.15.1 (June 4th, 2017; bugfixes and password prompt for SFTP) diff --git a/src/plugins/mail.ts b/src/plugins/mail.ts index b0c8c84..647ee64 100644 --- a/src/plugins/mail.ts +++ b/src/plugins/mail.ts @@ -75,9 +75,11 @@ class MailPlugin extends deploy_objects.ZipFileDeployPluginBase { let auth: any; let user = deploy_helpers.toStringSafe(target.user); - if (user) { - //TODO: password prompt + if ('' !== user) { let password = deploy_helpers.toStringSafe(target.password); + if ('' === password) { + password = undefined; + } auth = { user: user, @@ -156,22 +158,55 @@ https://github.com/mkloubert/vs-deploy`, } }; - vscode.window.showInputBox({ - prompt: i18.t('plugins.mail.addressSelector.prompt'), - ignoreFocusOut: true, - placeHolder: i18.t('plugins.mail.addressSelector.placeholder'), - value: to, - }).then((value) => { - to = deploy_helpers.toStringSafe(value).trim(); - if (to) { - deploy(); + let inputRecipients = () => { + vscode.window.showInputBox({ + prompt: i18.t('plugins.mail.addressSelector.prompt'), + ignoreFocusOut: true, + placeHolder: i18.t('plugins.mail.addressSelector.placeholder'), + value: to, + }).then((value) => { + to = deploy_helpers.toStringSafe(value).trim(); + if (to) { + deploy(); + } + else { + completed(); + } + }, (err) => { + completed(err); + }); + }; + + let askForPasswordIfNeeded = () => { + let showPasswordPrompt = false; + if (!deploy_helpers.isEmptyString(auth.user) && deploy_helpers.isNullOrUndefined(auth.password)) { + // user defined, but no password + showPasswordPrompt = deploy_helpers.toBooleanSafe(target.promptForPassword, true); + } + + if (showPasswordPrompt) { + vscode.window.showInputBox({ + placeHolder: i18.t('prompts.inputPassword'), + password: true, + }).then((passwordFromUser) => { + if ('undefined' === typeof passwordFromUser) { + completed(null); // cancelled } else { - completed(); + auth.password = passwordFromUser; + + inputRecipients(); } }, (err) => { completed(err); }); + } + else { + inputRecipients(); + } + }; + + askForPasswordIfNeeded(); } catch (e) { completed(e);