| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-setup-pin-dialog' is the settings page for choosing a PIN. | 7 * 'settings-setup-pin-dialog' is the settings page for choosing a PIN. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * | 10 * |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 * length. | 134 * length. |
| 135 * @private | 135 * @private |
| 136 * @param {string|undefined} pin | 136 * @param {string|undefined} pin |
| 137 * @return {boolean} | 137 * @return {boolean} |
| 138 */ | 138 */ |
| 139 isPinLongEnough_: function(pin) { | 139 isPinLongEnough_: function(pin) { |
| 140 return !!pin && pin.length >= 4; | 140 return !!pin && pin.length >= 4; |
| 141 }, | 141 }, |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * Returns true if the PIN is ready to be changed to a new value. | 144 * Returns true if the currently entered PIN is the same as the initially |
| 145 * submitted PIN. |
| 145 * @private | 146 * @private |
| 146 * @return {boolean} | 147 * @return {boolean} |
| 147 */ | 148 */ |
| 148 canSubmit_: function() { | 149 isPinConfirmed_: function() { |
| 149 return this.isPinLongEnough_(this.pinKeyboardValue_) && | 150 return this.isPinLongEnough_(this.pinKeyboardValue_) && |
| 150 this.initialPin_ == this.pinKeyboardValue_; | 151 this.initialPin_ == this.pinKeyboardValue_; |
| 151 }, | 152 }, |
| 152 | 153 |
| 153 /** | 154 /** |
| 154 * Notify the user about a problem. | 155 * Notify the user about a problem. |
| 155 * @private | 156 * @private |
| 156 * @param {string} messageId | 157 * @param {string} messageId |
| 157 * @param {string} problemClass | 158 * @param {string} problemClass |
| 158 */ | 159 */ |
| 159 showProblem_: function(messageId, problemClass) { | 160 showProblem_: function(messageId, problemClass) { |
| 161 var previousMessage = this.problemMessage_; |
| 162 |
| 163 // Update problem info. |
| 160 this.problemMessage_ = this.i18n(messageId); | 164 this.problemMessage_ = this.i18n(messageId); |
| 161 this.problemClass_ = problemClass; | 165 this.problemClass_ = problemClass; |
| 162 this.updateStyles(); | 166 this.updateStyles(); |
| 163 }, | 167 |
| 168 // If the problem message has changed, fire an alert. |
| 169 if (previousMessage != this.problemMessage_) |
| 170 this.$.problemDiv.setAttribute('role', 'alert'); |
| 171 }, |
| 164 | 172 |
| 165 /** @private */ | 173 /** @private */ |
| 166 hideProblem_: function() { | 174 hideProblem_: function() { |
| 167 this.problemMessage_ = ''; | 175 this.problemMessage_ = ''; |
| 168 this.problemClass_ = ''; | 176 this.problemClass_ = ''; |
| 169 }, | 177 }, |
| 170 | 178 |
| 171 /** @private */ | 179 /** @private */ |
| 172 onPinChange_: function() { | 180 onPinChange_: function() { |
| 173 if (!this.isConfirmStep_) { | 181 if (!this.isConfirmStep_) { |
| 174 var isPinLongEnough = this.isPinLongEnough_(this.pinKeyboardValue_); | 182 var isPinLongEnough = this.isPinLongEnough_(this.pinKeyboardValue_); |
| 175 var isWeak = isPinLongEnough && this.isPinWeak_(this.pinKeyboardValue_); | 183 var isWeak = isPinLongEnough && this.isPinWeak_(this.pinKeyboardValue_); |
| 176 | 184 |
| 177 if (!isPinLongEnough && this.pinKeyboardValue_) | 185 if (!isPinLongEnough) |
| 178 this.showProblem_('configurePinTooShort', 'error'); | 186 this.showProblem_('configurePinTooShort', 'warning'); |
| 179 else if (isWeak) | 187 else if (isWeak) |
| 180 this.showProblem_('configurePinWeakPin', 'warning'); | 188 this.showProblem_('configurePinWeakPin', 'warning'); |
| 181 else | 189 else |
| 182 this.hideProblem_(); | 190 this.hideProblem_(); |
| 183 | 191 |
| 184 this.enableSubmit_ = isPinLongEnough; | 192 this.enableSubmit_ = isPinLongEnough; |
| 185 | 193 |
| 186 } else { | 194 } else { |
| 187 var canSubmit = this.canSubmit_(); | 195 if (this.isPinConfirmed_()) |
| 196 this.hideProblem_(); |
| 197 else |
| 198 this.showProblem_('configurePinMismatched', 'warning'); |
| 188 | 199 |
| 189 if (!canSubmit && this.pinKeyboardValue_) | 200 this.enableSubmit_ = true; |
| 190 this.showProblem_('configurePinMismatched', 'error'); | |
| 191 else | |
| 192 this.hideProblem_(); | |
| 193 | |
| 194 this.enableSubmit_ = canSubmit; | |
| 195 } | 201 } |
| 196 }, | 202 }, |
| 197 | 203 |
| 198 /** @private */ | 204 /** @private */ |
| 199 onPinSubmit_: function() { | 205 onPinSubmit_: function() { |
| 200 if (!this.isConfirmStep_) { | 206 if (!this.isConfirmStep_) { |
| 201 if (this.isPinLongEnough_(this.pinKeyboardValue_)) { | 207 if (this.isPinLongEnough_(this.pinKeyboardValue_)) { |
| 202 this.initialPin_ = this.pinKeyboardValue_; | 208 this.initialPin_ = this.pinKeyboardValue_; |
| 203 this.pinKeyboardValue_ = ''; | 209 this.pinKeyboardValue_ = ''; |
| 204 this.isConfirmStep_ = true; | 210 this.isConfirmStep_ = true; |
| 205 this.onPinChange_(); | 211 this.onPinChange_(); |
| 206 this.$.pinKeyboard.focus(); | 212 this.$.pinKeyboard.focus(); |
| 207 } | 213 } |
| 208 } else { | 214 } else { |
| 209 // onPinSubmit_ gets called if the user hits enter on the PIN keyboard. | 215 // onPinSubmit_ gets called if the user hits enter on the PIN keyboard. |
| 210 // The PIN is not guaranteed to be valid in that case. | 216 // The PIN is not guaranteed to be valid in that case. |
| 211 if (!this.canSubmit_()) | 217 if (!this.isPinConfirmed_()) { |
| 218 this.showProblem_('configurePinMismatched', 'error'); |
| 212 return; | 219 return; |
| 220 } |
| 213 | 221 |
| 214 function onSetModesCompleted(didSet) { | 222 function onSetModesCompleted(didSet) { |
| 215 if (!didSet) { | 223 if (!didSet) { |
| 216 console.error('Failed to update pin'); | 224 console.error('Failed to update pin'); |
| 217 return; | 225 return; |
| 218 } | 226 } |
| 219 | 227 |
| 220 this.resetState_(); | 228 this.resetState_(); |
| 221 this.fire('done'); | 229 this.fire('done'); |
| 222 } | 230 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 252 * @private | 260 * @private |
| 253 * @param {boolean} isConfirmStep | 261 * @param {boolean} isConfirmStep |
| 254 * @return {string} | 262 * @return {string} |
| 255 */ | 263 */ |
| 256 getContinueMessage_: function(isConfirmStep) { | 264 getContinueMessage_: function(isConfirmStep) { |
| 257 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); | 265 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); |
| 258 }, | 266 }, |
| 259 }); | 267 }); |
| 260 | 268 |
| 261 })(); | 269 })(); |
| OLD | NEW |