-
Notifications
You must be signed in to change notification settings - Fork 7
/
vaadin-login.html
203 lines (175 loc) · 5.77 KB
/
vaadin-login.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!--
@license
Copyright (c) 2018 Vaadin Ltd.
This program is available under Commercial Vaadin Add-On License 3.0 (CVALv3).
See <a href="https://vaadin.com/license/cval-3">the website</a> for the complete license.
-->
<link rel="import" href="../../polymer/polymer-element.html">
<link rel="import" href="../../vaadin-themable-mixin/vaadin-themable-mixin.html">
<link rel="import" href="../../vaadin-element-mixin/vaadin-element-mixin.html">
<link rel="import" href="../../vaadin-license-checker/vaadin-license-checker.html">
<link rel="import" href="vaadin-login-mixin.html">
<link rel="import" href="../../iron-form/iron-form.html">
<link rel="import" href="../../vaadin-text-field/src/vaadin-text-field.html">
<link rel="import" href="../../vaadin-text-field/src/vaadin-password-field.html">
<link rel="import" href="../../vaadin-button/src/vaadin-button.html">
<dom-module id="vaadin-login">
<template>
<style>
:host {
overflow: hidden;
display: inline-block;
}
:host([hidden]) {
display: none !important;
}
[part="card"] {
max-width: 100%;
box-sizing: border-box;
overflow: hidden;
display: flex;
flex-direction: column;
}
[part="brand"] {
box-sizing: border-box;
overflow: hidden;
flex-grow: 1;
flex-shrink: 0;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
[part="brand"] h1 {
color: inherit;
margin: 0;
}
[part="form"] {
flex: none;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
[part="form"] h2 {
margin: 0;
}
vaadin-text-field,
vaadin-password-field,
#submit {
width: 100%;
}
[part="error-message"] {
position: relative;
}
</style>
<section part="card">
<div part="brand">
<h1>[[i18n.header.title]]</h1>
<p>[[i18n.header.description]]</p>
</div>
<div part="form">
<h2>[[i18n.form.title]]</h2>
<div part="error-message" hidden$="[[!error]]">
<h5>[[i18n.errorMessage.title]]</h5>
<p>[[i18n.errorMessage.message]]</p>
</div>
<iron-form id="loginForm" allow-redirect>
<form method="POST" action$="[[action]]">
<vaadin-text-field label="[[i18n.form.username]]" name="username" id="username" autofocus required on-keydown="_handleInputKeydown"></vaadin-text-field>
<vaadin-password-field label="[[i18n.form.password]]" name="password" id="password" required on-keydown="_handleInputKeydown"></vaadin-password-field>
<vaadin-button id="submit" theme="primary contained" on-click="submit" disabled$="[[disabled]]">[[i18n.form.submit]]</vaadin-button>
</form>
</iron-form>
<vaadin-button id="forgotPasswordButton" theme="tertiary small" on-click="_forgotPassword" hidden$="[[hideForgotPasswordButton]]">[[i18n.form.forgotPassword]]</vaadin-button>
<div part="footer">
<p>[[i18n.additionalInformation]]</p>
</div>
</div>
</section>
</template>
<script>
(function() {
/**
* `<vaadin-login>` is a Web Component.
*
* ```
* <vaadin-login></vaadin-login>
* ```
*
* @memberof Vaadin
* @mixes Vaadin.ElementMixin
* @mixes Vaadin.ThemableMixin
* @mixes Vaadin.LoginMixin
* @demo demo/index.html
*/
class VaadinLogin extends Vaadin.LoginMixin(Vaadin.ElementMixin(Vaadin.ThemableMixin(Polymer.Element))) {
static get is() {
return 'vaadin-login';
}
static get version() {
return '1.0.0-alpha3';
}
submit() {
if (this.disabled || !(this.$.username.validate() && this.$.password.validate())) {
return;
}
this.error = false;
this.disabled = true;
if (this.action == null) {
const eventDetails = {
bubbles: true,
cancelable: true,
detail: {
username: this.$.username.value,
password: this.$.password.value
}
};
this.dispatchEvent(new CustomEvent('login', eventDetails));
} else {
this.$.loginForm.submit();
}
}
_forgotPassword() {
this.dispatchEvent(new CustomEvent('forgot-password'));
}
_handleInputKeydown(e) {
if (this._isEnterKey(e)) {
const {target: inputActive} = e;
const nextInput = inputActive.name === 'username' ? this.$.password : this.$.username;
if (inputActive.validate()) {
if (nextInput.checkValidity()) {
this.submit();
} else {
nextInput.focus();
}
}
}
}
_isEnterKey(e) {
return e.key === 'Enter' || e.keyCode === 13;
}
/**
* Fired when user clicks on the "Forgot password" button
*
* @event forgot-password
*/
/**
* Fired when an user submits the login.
* This event is fired **only** if `action` is `null`
*
* @event login
*
*/
}
customElements.define(VaadinLogin.is, VaadinLogin);
/**
* @namespace Vaadin
*/
window.Vaadin.VaadinLogin = VaadinLogin;
const licenseChecker = window.Vaadin.developmentModeCallback
&& window.Vaadin.developmentModeCallback['vaadin-license-checker'];
if (typeof licenseChecker === 'function') {
licenseChecker(VaadinLogin);
}
})();
</script>
</dom-module>