-
Notifications
You must be signed in to change notification settings - Fork 19
/
login-fire.html
533 lines (484 loc) · 13.9 KB
/
login-fire.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<!--
@license
Copyright (c) 2016 Convoo All Rights Reserved.
Use of this source code is governed by a MIT license that can be found in the
LICENSE file or at https://github.com/convoo/login-fire/blob/master/LICENSE.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="./localize-behavior.html">
<link rel="import" href="../iron-media-query/iron-media-query.html">
<link rel="import" href="../reverse-element/reverse-element.html">
<link rel="import" href="./login-fire-form.html">
<link rel="import" href="./login-fire-social.html">
<link rel="import" href="./paper-social-button.html">
<!--
An element allowing user authentication with email and password or federated
identity providers (Google, Facebook, Twitter and GitHub) using the
[Firebase Auth API](https://firebase.google.com/docs/auth/).
Displaying a login form and a list of button (Google, Facebook, Twitter, GitHub)
for user authentication. You can can easily choose which buttons to display and how to
organize them with the form. See the demo page for more details.
For email-password authentication only, use `<login-fire-form>`.
For authenticating with multiple federated identity providers only, use `<login-fire-social>` and for a single provider, use `<login-fire-button>`.
Example:
```
<firebase-app
name="demo"
api-key="API_KEY"
auth-domain="AUTH_DOMAIN"
database-url="DATABASE_URL"></firebase-app>
<login-fire app-name="demo" providers="google, facebook, twitter, github, anonymous"></login-fire>
```
### Styling
Style the buttons with CSS as you would a normal DOM element. The following custom
properties and mixins are available for styling:
Custom property | Description | Default
--- | --- | ---
`--login-fire-divider-color` | The color for the divider bar | `gray`
`--login-fire-background-color` | The color for the divider bar | `white`
@customElement
@polymer
@demo demo/login-fire.html
-->
<dom-module id="login-fire">
<template>
<style>
reverse-element {
background: var(--login-fire-background-color, white);
@apply --layout-horizontal;
@apply --layout-wrap;
@apply --layout-center-center;
}
:host([horizontal]) reverse-element {
@apply --layout-vertical;
@apply --layout-center;
}
.div {
@apply --layout-center-center;
background-color: var(--login-fire-divider-color, lightgray);
}
.div__span {
line-height: 15px;
padding: 16px;
background: var(--login-fire-background-color, white);
font-size: 12px;
font-style: italic;
color: var(--login-fire-divider-color, gray);
font-weight: lighter;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}
.div--hidden {
display: none;
}
.div--vertical {
@apply --layout-horizontal;
margin: 0 50px;
min-height: 200px;
max-height: 400px;
width: 1px;
}
.div--horizontal {
@apply --layout-vertical;
height: 1px;
margin: 50px 0;
min-width: 300px;
max-width: 400px;
}
[hidden] {
display: none !important;
}
</style>
<template is="dom-if" if="[[_showSignOutButton]]">
<paper-social-button
signed-in="[[signedIn]]"
mini$="[[mini]]"
flat$="[[flat]]"
no-sign-in
locales-file="[[localesFile]]"
language="[[language]]"
disabled$="[[inProgress]]"
on-click="signOut">
</paper-social-button>
</template>
<template is="dom-if" if="[[!_showSignOutButton]]">
<reverse-element reverse="[[reverse]]">
<login-fire-form
app-name="[[appName]]"
user="{{user}}"
in-progress="{{_inProgressForm}}"
signed-in="{{signedIn}}"
status-known="{{statusKnown}}"
no-sign-out="[[noSignOut]]"
no-sign-in="[[noSignIn]]"
auto-sign-up="[[autoSignUp]]"
show-sign-up="{{showSignUp}}"
flat="{{flat}}"
locales-file="[[localesFile]]"
language="[[language]]"
auto="[[auto]]"
debug="[[debug]]"
no-toggleable-password="[[noToggleablePassword]]"
password-regex="{{passwordRegex}}"
email-regex="{{emailRegex}}"
reenter-password="[[reenterPassword]]">
</login-fire-form>
<div class$="div [[_dividerStyle]]" hidden$="[[noDivider]]">
<span class="div__span">[[localize('lf-or')]]</span>
</div>
<login-fire-social
app-name="[[appName]]"
providers="[[providers]]"
user="{{user}}"
in-progress="{{_inProgressSocial}}"
signed-in="{{signedIn}}"
status-known="{{statusKnown}}"
no-sign-in="[[noSignIn]]"
no-sign-out="[[noSignOut]]"
redirect="[[redirect]]"
mini$="[[mini]]"
horizontal$="[[horizontal]]"
show-sign-up="{{showSignUp}}"
flat="{{flat}}"
locales-file="[[localesFile]]"
language="[[language]]"
google-scopes="[[googleScopes]]"
facebook-scopes="[[facebookScopes]]"
github-scopes="[[githubScopes]]"
auto="[[auto]]"
debug="[[debug]]">
</login-fire-social>
</reverse-element>
</template>
<iron-media-query query="(max-width: 650px)" query-matches="{{_isNarrow}}">
</iron-media-query>
</template>
<script>
Polymer({
is: 'login-fire',
behaviors: [
Convoo.LocalizeBehavior,
],
properties: {
/**
* An application name. This is required if you want use several Firebase
* configurations in the same app. All elements that implement this
* behavior and having the same application name share their properties.
*
* @type {String}
*/
appName: {
type: String,
value: ''
},
/**
* Enables automatic sign-up on form if the user does not exist.
*
* @type {Boolean}
*/
autoSignUp: {
type: Boolean,
value: false
},
/**
* Prefers a horizontally structured social login.
*
* @type{Boolean}
*/
horizontal: {
type: Boolean,
value: false
},
/**
* Providers names. A list of the providers names, seperated by comma, to
* use for authentication. A button is displayed for each provider.
*
* Current accepted providers are:
*
* ```
* 'anonymous' (for signin anonymously)
* 'facebook'
* 'github'
* 'google'
* 'twitter'
* ```
*
* @type {String}
*/
providers: {
type: String,
value: 'anonymous'
},
/**
* Displays mini social sign in buttons removing the "Sign in with" text
*/
mini: {
type: Boolean,
value: false
},
/**
* Hides the divider.
*
* @type {Boolean}
*/
noDivider: {
type: Boolean,
value: false
},
/**
* Displays social buttons first instead of the form. By default, the form
* is displayed first.
*
* @type{Boolean}
*/
reverse: {
type: Boolean,
value: false
},
/**
* Removes the view button on the password input
*/
noToggleablePassword: {
type: Boolean,
value: false
},
/**
* Adds another input to re-enter password in the sign up view
*/
reenterPassword: {
type: Boolean,
value: false
},
/**
* Regular expression used to check password strength. The default Regex
* checks if the password has a length at least of 8 chars and contains:
* - 2 uppercase letters
* - 1 special char letter [!@#$&*]
* - 2 digits
* - 3 lowercase letters
*
* Password strength validation can be disabled by setting this property
* to "none", "null" or a falsy value.
*
* @type {String}
*/
passwordRegex: {
type: String,
},
/**
* Regular expression used to check email address format. It's a simplified
* version that check the email address has the same syntax as described
* on <a href="https://en.wikipedia.org/wiki/Email_address">Wikipedia</a>.
* Pay attention, quoted email addresses are not passing the validation due
* to the complexity of the regular expression it should have been write.
*
* Email address syntax validation can be disabled by setting this property
* to "none", "null" or a falsy value.
*
* @type {String}
*/
emailRegex: {
type: String,
},
/**
* GitHub scopes.
*
* @type {String}
*/
githubScopes: {
type: String
},
/**
* Google scopes.
*
* @type {String}
*/
googleScopes: {
type: String
},
/**
* Facebook scopes.
*
* @type {String}
*/
facebookScopes: {
type: String
},
/**
* Sets the element in debug mode. In the debug mode, the Firebase
* configuration used by the element and relevant steps like a user
* change are print out into the browser's console.
*
* @type {Boolean}
*/
debug: {
type: Boolean,
value: false
},
/**
* Defines if the authentication must use redirection. If `false`, the
* authentication will use pop-up.
*
* @type {Boolean}
*/
redirect: {
type: Boolean,
value: false
},
/**
* When this attribute is `true`, the element tries to log the user in
* right after have been attached to the DOM if and only if the user was
* signed in when they left the application.
*
* @type {Boolean}
* @default false
*/
auto: {
type: Boolean,
value: false
},
/**
* `True` if a user is authenticated, otherwise `false`.
*
* @type {Boolean}
*/
signedIn: {
type: Boolean,
value: false,
notify: true
},
/**
* Whether to show the view at sign up or sign in.
*
* @type {Boolean}
*/
showSignUp: {
type: Boolean,
value: false,
notify: true
},
/**
* When `true`, login status can be determined by checking user property.
*
* @type {Boolean}
*/
statusKnown: {
type: Boolean,
value: false,
notify: true
},
/**
* Signed-in user. This user representation is accessible from all elements
* that use Firebase Auth with the same application name.
*
* @type {Object}
*/
user: {
type: Object,
notify: true
},
/**
* Prevents the element from signing out. It means, if this attribute is
* `true`, the `signOut` method has no effect.
*
* @type {Boolean}
*/
noSignOut: {
type: Boolean,
value: false
},
/**
* Prevents the element from signing in. It means, if this attribute is
* `true`, the `signIn` method has no effect.
*
* @type {Boolean}
*/
noSignIn: {
type: Boolean,
value: false
},
/**
* This property is used in `login-fire` and `login-fire-social` when the
* user is signed in and allowed to sign out. Then it shows only one
* button (instead of multiple) to sign out.
*/
_showSignOutButton: {
type: Boolean,
computed: '_computeShowOneButton(noSignIn, signedIn, noSignOut)'
},
/**
* True if the element is too much narrow to be display horizontally.
*
* @type {Boolean}
*/
_isNarrow: {
type: Boolean
},
/**
* Sets the divider in horizontal or vertical orientation.
*
* @type {String}
*/
_dividerStyle: {
type: String,
computed: '_computeDividerStyle(_isNarrow, horizontal)'
},
inProgress: {
type: Boolean,
notify: true,
computed: '_computeInProgress(_inProgressForm, _inProgressSocial)'
}
},
/**
* Signs the user out regardless the provider used for the sign-in.
*/
signOut: function() {
this.$$('login-fire-social').signOut();
},
/**
* Signs the user in using the target provider. It's not possible to sign in
* using the provider "email" when only one button is displayed. Also, does
* nothing if a user is already signed in.
*
* @param {String} provider name
*/
signInWith: function(provider) {
if (this.signedIn) {
return;
}
if (provider === 'email') {
if (this._showSignOutButton) {
console.error("Can't sign in using provider \"email\" when only one button is displayed.");
} else {
this.$$('login-fire-form').confirm();
}
} else {
this.$$('login-fire-social').signInWith(provider);
}
},
/**
* Computes CSS class for the divider.
*
* @param {Boolean} isNarrow
* @param {Boolean} horizontal
* @return {String} CSS class to set to the divider
*/
_computeDividerStyle: function(isNarrow, horizontal) {
return (horizontal || isNarrow) ? 'div--horizontal' : 'div--vertical';
},
_computeInProgress() {
return this._inProgressForm || this._inProgressSocial;
},
/**
* Returns `true` when the element allows only to signing out or a user is
* already signed in and they can signing out.
*/
_computeShowOneButton: function(noSignIn, signedIn, noSignOut) {
return noSignIn || (signedIn && !noSignOut);
},
});
</script>
</dom-module>