diff options
author | Luke Bennett <lbennett@gitlab.com> | 2018-07-06 14:36:02 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-07-06 14:36:02 +0000 |
commit | 02ad729308307a107ca930485e4b5b7dae10e5dc (patch) | |
tree | 7427f9e9dd58c2f7befd821b1b9d871c8733cb12 /app/assets/javascripts/profile | |
parent | 3033e019247a599bcf22167c04e7bc41211cbe90 (diff) | |
download | gitlab-ce-02ad729308307a107ca930485e4b5b7dae10e5dc.tar.gz |
(Part 2) Resolve "Recognise when a user is trying to validate a private SSH key"
Diffstat (limited to 'app/assets/javascripts/profile')
-rw-r--r-- | app/assets/javascripts/profile/add_ssh_key_validation.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/assets/javascripts/profile/add_ssh_key_validation.js b/app/assets/javascripts/profile/add_ssh_key_validation.js new file mode 100644 index 00000000000..ab6a6c1896c --- /dev/null +++ b/app/assets/javascripts/profile/add_ssh_key_validation.js @@ -0,0 +1,43 @@ +export default class AddSshKeyValidation { + constructor(inputElement, warningElement, originalSubmitElement, confirmSubmitElement) { + this.inputElement = inputElement; + this.form = inputElement.form; + + this.warningElement = warningElement; + + this.originalSubmitElement = originalSubmitElement; + this.confirmSubmitElement = confirmSubmitElement; + + this.isValid = false; + } + + register() { + this.form.addEventListener('submit', event => this.submit(event)); + + this.confirmSubmitElement.addEventListener('click', () => { + this.isValid = true; + this.form.submit(); + }); + + this.inputElement.addEventListener('input', () => this.toggleWarning(false)); + } + + submit(event) { + this.isValid = AddSshKeyValidation.isPublicKey(this.inputElement.value); + + if (this.isValid) return true; + + event.preventDefault(); + this.toggleWarning(true); + return false; + } + + toggleWarning(isVisible) { + this.warningElement.classList.toggle('hide', !isVisible); + this.originalSubmitElement.classList.toggle('hide', isVisible); + } + + static isPublicKey(value) { + return /^(ssh|ecdsa-sha2)-/.test(value); + } +} |