Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 1 | /** |
| 2 | * @license |
| 3 | * Copyright (C) 2016 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 17 | import '../../../scripts/bundled-polymer.js'; |
Wyatt Allen | 31958fcb | 2016-06-17 10:21:59 -0700 | [diff] [blame] | 18 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 19 | import '../../../styles/gr-form-styles.js'; |
| 20 | import '../../shared/gr-button/gr-button.js'; |
| 21 | import '../../shared/gr-copy-clipboard/gr-copy-clipboard.js'; |
| 22 | import '../../shared/gr-overlay/gr-overlay.js'; |
| 23 | import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js'; |
| 24 | import '../../../styles/shared-styles.js'; |
| 25 | import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js'; |
| 26 | import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js'; |
| 27 | import {PolymerElement} from '@polymer/polymer/polymer-element.js'; |
| 28 | import {htmlTemplate} from './gr-http-password_html.js'; |
Wyatt Allen | 31958fcb | 2016-06-17 10:21:59 -0700 | [diff] [blame] | 29 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 30 | /** @extends Polymer.Element */ |
| 31 | class GrHttpPassword extends GestureEventListeners( |
| 32 | LegacyElementMixin( |
| 33 | PolymerElement)) { |
| 34 | static get template() { return htmlTemplate; } |
Wyatt Allen | 31958fcb | 2016-06-17 10:21:59 -0700 | [diff] [blame] | 35 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 36 | static get is() { return 'gr-http-password'; } |
Paladox none | 4a11629 | 2019-06-14 18:50:53 +0000 | [diff] [blame] | 37 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 38 | static get properties() { |
| 39 | return { |
| 40 | _username: String, |
| 41 | _generatedPassword: String, |
| 42 | _passwordUrl: String, |
| 43 | }; |
Dmitrii Filippov | 3fd2b10 | 2019-11-15 16:16:46 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 46 | /** @override */ |
| 47 | attached() { |
| 48 | super.attached(); |
| 49 | this.loadData(); |
| 50 | } |
| 51 | |
| 52 | loadData() { |
| 53 | const promises = []; |
| 54 | |
| 55 | promises.push(this.$.restAPI.getAccount().then(account => { |
| 56 | this._username = account.username; |
| 57 | })); |
| 58 | |
| 59 | promises.push(this.$.restAPI.getConfig().then(info => { |
| 60 | this._passwordUrl = info.auth.http_password_url || null; |
| 61 | })); |
| 62 | |
| 63 | return Promise.all(promises); |
| 64 | } |
| 65 | |
| 66 | _handleGenerateTap() { |
| 67 | this._generatedPassword = 'Generating...'; |
| 68 | this.$.generatedPasswordOverlay.open(); |
| 69 | this.$.restAPI.generateAccountHttpPassword().then(newPassword => { |
| 70 | this._generatedPassword = newPassword; |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | _closeOverlay() { |
| 75 | this.$.generatedPasswordOverlay.close(); |
| 76 | } |
| 77 | |
| 78 | _generatedPasswordOverlayClosed() { |
| 79 | this._generatedPassword = ''; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | customElements.define(GrHttpPassword.is, GrHttpPassword); |