| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 <link rel="import" href="../../polymer/polymer.html"> |
| 11 <link rel="import" href="../firebase-auth.html"> |
| 12 <dom-module id="x-login"> |
| 13 <template> |
| 14 <firebase-auth id="firebaseLogin" user="{{user}}" status-known="{{statusKnow
n}}" location="https://polymer-tests.firebaseio.com" provider="{{provider}}" on-
error="errorHandler" on-user-created="userSuccessHandler" on-password-changed="u
serSuccessHandler" on-password-reset="userSuccessHandler" on-user-removed="userS
uccessHandler"></firebase-auth> |
| 15 |
| 16 Firebase location: |
| 17 <input value="https://polymer-tests.firebaseio.com" size="40" disabled> |
| 18 <br> |
| 19 |
| 20 Provider type: |
| 21 <select value="{{provider::change}}"> |
| 22 <option>anonymous</option> |
| 23 <option>facebook</option> |
| 24 <option>github</option> |
| 25 <option>google</option> |
| 26 <option>twitter</option> |
| 27 <option>password</option> |
| 28 </select> |
| 29 <em>Only 'anonymous', 'google', and 'password' are activated for demo Fireba
se account</em> |
| 30 <br> |
| 31 |
| 32 Login params (JSON): |
| 33 <input value="{{params::input}}" id="params"> |
| 34 <em>Required by some provider types</em> |
| 35 <br> |
| 36 |
| 37 <div hidden$="{{computePasswordHidden(provider)}}"> |
| 38 <br><em>Password-specific options:</em><br> |
| 39 <input placeholder="email" value="{{email::input}}"> |
| 40 <input placeholder="password" value="{{password::input}}"> |
| 41 <button on-tap="createUserHandler" disabled$="{{computeCreateUserDisabled(
email, password)}}">Create user</button> |
| 42 <br> |
| 43 <input placeholder="new password" value="{{newPassword::input}}"> |
| 44 <button on-tap="changePasswordHandler" disabled$="{{computeChangePasswordD
isabled(email, password, newPassword)}}">Change password</button> |
| 45 <br> |
| 46 <button on-tap="resetPasswordHandler" disabled$="{{computeResetPasswordDis
abled(email, password)}}">Reset password</button> |
| 47 <button on-tap="removeUserHandler" disabled$="{{computeRemoveUserDisabled(
email, password)}}">Remove user</button> |
| 48 </div> |
| 49 <br> |
| 50 <div id="message">[[message]]</div> |
| 51 <br> |
| 52 |
| 53 <button on-tap="login" hidden$="{{computeLoginHidden(statusKnown, user)}}">L
ogin</button> |
| 54 <button on-tap="logout" hidden$="{{computeLogoutHidden(statusKnown, user)}}"
>Logout</button> |
| 55 |
| 56 <h3>Login status:</h3> |
| 57 <p>{{computeLoginStatus(statusKnown, user)}}</p> |
| 58 |
| 59 <h3>User ID:</h3> |
| 60 <pre>{{user.uid}}</pre> |
| 61 </template> |
| 62 </dom-module> |
| 63 <script> |
| 64 Polymer({ |
| 65 is: 'x-login', |
| 66 |
| 67 properties: { |
| 68 provider: { |
| 69 type: String, |
| 70 value: 'anonymous' |
| 71 }, |
| 72 |
| 73 message: { |
| 74 type: String, |
| 75 value: '' |
| 76 }, |
| 77 |
| 78 email: { |
| 79 type: String, |
| 80 value: '' |
| 81 }, |
| 82 |
| 83 password: { |
| 84 type: String, |
| 85 value: '' |
| 86 }, |
| 87 |
| 88 user: { |
| 89 type: Object, |
| 90 value: null |
| 91 }, |
| 92 |
| 93 statusKnown: { |
| 94 type: Boolean |
| 95 } |
| 96 }, |
| 97 |
| 98 login: function() { |
| 99 var params; |
| 100 |
| 101 try { |
| 102 params = JSON.parse(this.params); |
| 103 } catch (e) { |
| 104 params = null; |
| 105 } |
| 106 |
| 107 if (this.provider == 'password') { |
| 108 params = params || {}; |
| 109 params.email = this.email; |
| 110 params.password = this.password; |
| 111 } |
| 112 |
| 113 this.$.firebaseLogin.login(params); |
| 114 }, |
| 115 |
| 116 logout: function() { |
| 117 this.$.firebaseLogin.logout(); |
| 118 }, |
| 119 |
| 120 errorHandler: function(e) { |
| 121 this.message = 'Error: ' + e.detail.message; |
| 122 }, |
| 123 |
| 124 userSuccessHandler: function(e) { |
| 125 this.message = e.type + ' success!'; |
| 126 }, |
| 127 |
| 128 createUserHandler: function(e) { |
| 129 this.$.firebaseLogin.createUser(this.email, this.password); |
| 130 }, |
| 131 |
| 132 changePasswordHandler: function(e) { |
| 133 this.$.firebaseLogin.changePassword(this.email, this.password, this.newPas
sword); |
| 134 }, |
| 135 |
| 136 resetPasswordHandler: function(e) { |
| 137 this.$.firebaseLogin.sendPasswordResetEmail(this.email); |
| 138 }, |
| 139 |
| 140 computePasswordHidden: function(provider) { |
| 141 return provider !== 'password'; |
| 142 }, |
| 143 |
| 144 computeCreateUserDisabled: function(email, password) { |
| 145 return !email || !password; |
| 146 }, |
| 147 |
| 148 computeChangePasswordDisabled: function(email, password, newPassword) { |
| 149 return !email || !password || !newPassword; |
| 150 }, |
| 151 |
| 152 computeResetPasswordDisabled: function(email, password) { |
| 153 return !email || !password; |
| 154 }, |
| 155 |
| 156 computeRemoveUserDisabled: function(email, password) { |
| 157 return !email || !password; |
| 158 }, |
| 159 |
| 160 computeLoginHidden: function(statusKnown, user) { |
| 161 return !statusKnown || !!user; |
| 162 }, |
| 163 |
| 164 computeLogoutHidden: function(statusKnown, user) { |
| 165 return !statusKnown || !user; |
| 166 }, |
| 167 |
| 168 computeLoginStatus: function(statusKnown, user) { |
| 169 if (statusKnown && user) { |
| 170 return 'Logged in'; |
| 171 } |
| 172 |
| 173 if (statusKnown) { |
| 174 return 'Logged out'; |
| 175 } |
| 176 |
| 177 return 'Unknown (checking status...)'; |
| 178 } |
| 179 }); |
| 180 </script> |
| OLD | NEW |