From 5da3e578a1723846be816a7c2149cee808dd96da Mon Sep 17 00:00:00 2001 From: Edgard Lorraine Messias Date: Mon, 19 Mar 2018 11:42:55 -0300 Subject: [PATCH] Improved Authentication (Close #219) --- src/commands.ts | 27 +++++++++++++++++++++------ src/repository.ts | 15 +++++++++------ src/svn.ts | 4 ++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 01e3624c..ccce505e 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -125,16 +125,31 @@ export class SvnCommands implements IDisposable { } @command("svn.promptAuth", { repository: true }) - async promptAuth(repository: Repository) { - repository.username = await window.showInputBox({ + async promptAuth(repository: Repository): Promise { + const username = await window.showInputBox({ placeHolder: "Svn repository username", - prompt: "Please enter your username" + prompt: "Please enter your username", + value: repository.username }); - repository.password = await window.showInputBox({ + if(username === undefined) { + return false; + } + + const password = await window.showInputBox({ placeHolder: "Svn repository password", - prompt: "Please enter your password" + prompt: "Please enter your password", + password: true }); + + if(username === undefined) { + return false; + } + + repository.username = username; + repository.password = password; + + return true; } @command("svn.commitWithMessage", { repository: true }) @@ -168,7 +183,7 @@ export class SvnCommands implements IDisposable { repository.inputBox.value = ""; } catch (error) { console.error(error); - window.showErrorMessage(error); + window.showErrorMessage("Unable to commit"); } } diff --git a/src/repository.ts b/src/repository.ts index 1d1030da..84ce7d2d 100644 --- a/src/repository.ts +++ b/src/repository.ts @@ -138,7 +138,7 @@ export class Repository { public isIncomplete: boolean = false; public needCleanUp: boolean = false; - private lastPromptAuth?: Thenable; + private lastPromptAuth?: Thenable; private _onDidChangeRepository = new EventEmitter(); readonly onDidChangeRepository: Event = this._onDidChangeRepository @@ -688,16 +688,16 @@ export class Repository { ); } - async promptAuth() { + async promptAuth(): Promise { // Prevent multiple prompts for auth if (this.lastPromptAuth) { - await this.lastPromptAuth; - return; + return await this.lastPromptAuth; } this.lastPromptAuth = commands.executeCommand("svn.promptAuth"); - await this.lastPromptAuth; + const result = await this.lastPromptAuth; this.lastPromptAuth = undefined; + return result; } onDidSaveTextDocument(document: TextDocument) { @@ -774,7 +774,10 @@ export class Repository { err.svnErrorCode === SvnErrorCodes.AuthorizationFailed && attempt <= 3 ) { - await this.promptAuth(); + const result = await this.promptAuth(); + if (!result) { + throw err; + } } else { throw err; } diff --git a/src/svn.ts b/src/svn.ts index 4c59272d..a942f303 100644 --- a/src/svn.ts +++ b/src/svn.ts @@ -50,6 +50,10 @@ function getSvnErrorCode(stderr: string): string | undefined { } } + if (/No more credentials or we tried too many times/.test(stderr)) { + return SvnErrorCodes.AuthorizationFailed; + } + return void 0; }