blob: 02657f84aa15bb38386a1027082f5e73cc915770 [file] [log] [blame]
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04001/**
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 Filippovdaf0ec92020-03-17 11:27:28 +010017import '../../../scripts/bundled-polymer.js';
Wyatt Allen31958fcb2016-06-17 10:21:59 -070018
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010019import '../../../styles/gr-form-styles.js';
20import '../../shared/gr-button/gr-button.js';
21import '../../shared/gr-copy-clipboard/gr-copy-clipboard.js';
22import '../../shared/gr-overlay/gr-overlay.js';
23import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
24import '../../../styles/shared-styles.js';
25import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
26import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
27import {PolymerElement} from '@polymer/polymer/polymer-element.js';
28import {htmlTemplate} from './gr-http-password_html.js';
Wyatt Allen31958fcb2016-06-17 10:21:59 -070029
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010030/** @extends Polymer.Element */
31class GrHttpPassword extends GestureEventListeners(
32 LegacyElementMixin(
33 PolymerElement)) {
34 static get template() { return htmlTemplate; }
Wyatt Allen31958fcb2016-06-17 10:21:59 -070035
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010036 static get is() { return 'gr-http-password'; }
Paladox none4a116292019-06-14 18:50:53 +000037
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010038 static get properties() {
39 return {
40 _username: String,
41 _generatedPassword: String,
42 _passwordUrl: String,
43 };
Dmitrii Filippov3fd2b102019-11-15 16:16:46 +010044 }
45
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010046 /** @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
83customElements.define(GrHttpPassword.is, GrHttpPassword);