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;
46 var gaiaPasswordChanged = $('gaia-password-changed');
47 gaiaPasswordChanged.addEventListener('cancel', function(e) {
48 chrome.send('cancelPasswordChangedFlow',
49 [$('gaia-password-changed').email]);
50 gaiaPasswordChanged.reset();
53 gaiaPasswordChanged.addEventListener('passwordEnter', function(e) {
54 chrome.send('migrateUserData', [e.detail.password]);
57 gaiaPasswordChanged.addEventListener('proceedAnyway', function() {
58 chrome.send('resyncUserData');
64 * @type {array} Array of Buttons.
69 var backButton = this.ownerDocument.createElement('button');
70 backButton.id = 'password-changed-back-button';
71 backButton.textContent =
72 loadTimeData.getString('passwordChangedBackButton');
73 backButton.addEventListener('click', function(e) {
74 var screen = $('password-changed');
75 if (screen.classList.contains('migrate')) {
78 // Resync all data UI step.
79 screen.classList.remove('resync');
80 screen.classList.add('migrate');
81 $('old-password').focus();
85 buttons.push(backButton);
87 var okButton = this.ownerDocument.createElement('button');
88 okButton.id = 'password-changed-ok-button';
89 okButton.textContent = loadTimeData.getString('passwordChangedsOkButton');
90 okButton.addEventListener('click', function(e) {
91 $('password-changed').migrate();
94 buttons.push(okButton);
96 var proceedAnywayButton = this.ownerDocument.createElement('button');
97 proceedAnywayButton.id = 'password-changed-proceed-button';
98 proceedAnywayButton.textContent =
99 loadTimeData.getString('proceedAnywayButton');
100 proceedAnywayButton.addEventListener('click', function(e) {
101 var screen = $('password-changed');
102 if (screen.classList.contains('resync'))
103 $('password-changed').resync();
106 buttons.push(proceedAnywayButton);
112 * Returns a control which should receive an initial focus.
114 get defaultControl() {
115 return $('old-password');
119 * True if the the screen is disabled (handles no user interaction).
124 return this.disabled_;
126 set disabled(value) {
127 this.disabled_ = value;
128 var controls = this.querySelectorAll('button,input');
129 for (var i = 0, control; control = controls[i]; ++i) {
130 control.disabled = value;
132 $('login-header-bar').disabled = value;
133 $('password-changed-cant-remember-link').classList[
134 value ? 'add' : 'remove']('disabled');
138 * Cancels password migration and drops the user back to the login screen.
141 this.disabled = true;
142 chrome.send('cancelPasswordChangedFlow', ['']);
146 * Starts migration process using old password that user provided.
148 migrate: function() {
149 if (!$('old-password').value) {
150 $('old-password').focus();
153 this.disabled = true;
154 chrome.send('migrateUserData', [$('old-password').value]);
157 onAfterShow: function(data) {
158 if (Oobe.isNewGaiaFlow())
159 $('gaia-password-changed').focus();
163 * Event handler that is invoked just before the screen is hidden.
165 onBeforeHide: function() {
166 $('login-header-bar').disabled = false;
170 * Starts migration process by removing old cryptohome and re-syncing data.
173 this.disabled = true;
174 chrome.send('resyncUserData');
178 * Show password changed screen.
179 * @param {boolean} showError Whether to show the incorrect password error.
181 show: function(showError, email) {
182 if (Oobe.isNewGaiaFlow()) {
183 $('password-changed-contents').hidden = true;
184 $('password-changed-controls').hidden = true;
185 var gaiaPasswordChanged = $('gaia-password-changed');
186 gaiaPasswordChanged.reset();
187 gaiaPasswordChanged.hidden = false;
189 gaiaPasswordChanged.invalidate();
191 gaiaPasswordChanged.email = email;
193 var screen = $('password-changed');
194 screen.classList.toggle('password-error', showError);
195 screen.classList.add('migrate');
196 screen.classList.remove('resync');
197 $('old-password').value = '';
198 $('password-changed').disabled = false;
200 // We'll get here after the successful online authentication.
201 // It assumes session is about to start so hides login screen controls.
202 Oobe.getInstance().headerHidden = false;
203 Oobe.showScreen({id: SCREEN_PASSWORD_CHANGED});
204 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.PASSWORD_CHANGED;
205 if (!Oobe.isNewGaiaFlow())
206 $('password-changed-ok-button').disabled = true;