1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview Password changed screen implementation.
9 login
.createScreen('PasswordChangedScreen', 'password-changed', function() {
16 decorate: function() {
17 $('old-password').addEventListener(
18 'keydown', function(e
) {
19 $('password-changed').classList
.remove('password-error');
20 if (e
.keyIdentifier
== 'Enter') {
21 $('password-changed').migrate();
25 $('old-password').addEventListener(
26 'keyup', function(e
) {
27 if ($('password-changed').disabled
)
29 $('password-changed-ok-button').disabled
= this.value
.length
== 0;
31 $('password-changed-cant-remember-link').addEventListener(
32 'click', function(e
) {
33 if (this.classList
.contains('disabled'))
35 var screen
= $('password-changed');
36 if (screen
.classList
.contains('migrate')) {
37 screen
.classList
.remove('migrate');
38 screen
.classList
.add('resync');
39 $('password-changed-proceed-button').focus();
40 $('password-changed').classList
.remove('password-error');
41 $('old-password').value
= '';
42 $('password-changed-ok-button').disabled
= true;
49 * @type {array} Array of Buttons.
54 var backButton
= this.ownerDocument
.createElement('button');
55 backButton
.id
= 'password-changed-back-button';
56 backButton
.textContent
=
57 loadTimeData
.getString('passwordChangedBackButton');
58 backButton
.addEventListener('click', function(e
) {
59 var screen
= $('password-changed');
60 if (screen
.classList
.contains('migrate')) {
63 // Resync all data UI step.
64 screen
.classList
.remove('resync');
65 screen
.classList
.add('migrate');
66 $('old-password').focus();
70 buttons
.push(backButton
);
72 var okButton
= this.ownerDocument
.createElement('button');
73 okButton
.id
= 'password-changed-ok-button';
74 okButton
.textContent
= loadTimeData
.getString('passwordChangedsOkButton');
75 okButton
.addEventListener('click', function(e
) {
76 $('password-changed').migrate();
79 buttons
.push(okButton
);
81 var proceedAnywayButton
= this.ownerDocument
.createElement('button');
82 proceedAnywayButton
.id
= 'password-changed-proceed-button';
83 proceedAnywayButton
.textContent
=
84 loadTimeData
.getString('proceedAnywayButton');
85 proceedAnywayButton
.addEventListener('click', function(e
) {
86 var screen
= $('password-changed');
87 if (screen
.classList
.contains('resync'))
88 $('password-changed').resync();
91 buttons
.push(proceedAnywayButton
);
97 * Returns a control which should receive an initial focus.
99 get defaultControl() {
100 return $('old-password');
104 * True if the the screen is disabled (handles no user interaction).
109 return this.disabled_
;
111 set disabled(value
) {
112 this.disabled_
= value
;
113 var controls
= this.querySelectorAll('button,input');
114 for (var i
= 0, control
; control
= controls
[i
]; ++i
) {
115 control
.disabled
= value
;
117 $('login-header-bar').disabled
= value
;
118 $('password-changed-cant-remember-link').classList
[
119 value
? 'add' : 'remove']('disabled');
123 * Cancels password migration and drops the user back to the login screen.
126 this.disabled
= true;
127 chrome
.send('cancelPasswordChangedFlow');
131 * Starts migration process using old password that user provided.
133 migrate: function() {
134 if (!$('old-password').value
) {
135 $('old-password').focus();
138 this.disabled
= true;
139 chrome
.send('migrateUserData', [$('old-password').value
]);
143 * Event handler that is invoked just before the screen is hidden.
145 onBeforeHide: function() {
146 $('login-header-bar').disabled
= false;
150 * Starts migration process by removing old cryptohome and re-syncing data.
153 this.disabled
= true;
154 chrome
.send('resyncUserData');
158 * Show password changed screen.
159 * @param {boolean} showError Whether to show the incorrect password error.
161 show: function(showError
) {
162 // We'll get here after the successful online authentication.
163 // It assumes session is about to start so hides login screen controls.
164 Oobe
.getInstance().headerHidden
= false;
165 var screen
= $('password-changed');
166 screen
.classList
.toggle('password-error', showError
);
167 screen
.classList
.add('migrate');
168 screen
.classList
.remove('resync');
169 $('old-password').value
= '';
170 $('password-changed').disabled
= false;
172 Oobe
.showScreen({id
: SCREEN_PASSWORD_CHANGED
});
173 $('password-changed-ok-button').disabled
= true;