| 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 Polymer element for displaying AD domain joining and AD | 6 * @fileoverview Polymer element for displaying AD domain joining and AD |
| 7 * Authenticate user screens. | 7 * Authenticate user screens. |
| 8 */ | 8 */ |
| 9 // Possible error states of the screen. Must be in the same order as |
| 10 // ActiveDirectoryErrorState enum values. |
| 11 /** @enum {number} */ var ACTIVE_DIRECTORY_ERROR_STATE = { |
| 12 NONE: 0, |
| 13 MACHINE_NAME_INVALID: 1, |
| 14 MACHINE_NAME_TOO_LONG: 2, |
| 15 BAD_USERNAME: 3, |
| 16 BAD_PASSWORD: 4, |
| 17 }; |
| 9 | 18 |
| 10 Polymer({ | 19 Polymer({ |
| 11 is: 'offline-ad-login', | 20 is: 'offline-ad-login', |
| 12 | 21 |
| 13 properties: { | 22 properties: { |
| 14 /** | 23 /** |
| 15 * Whether the UI disabled. | 24 * Whether the UI disabled. |
| 16 */ | 25 */ |
| 17 disabled: { | 26 disabled: { |
| 18 type: Boolean, | 27 type: Boolean, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 33 type: String, | 42 type: String, |
| 34 observer: 'realmChanged_' | 43 observer: 'realmChanged_' |
| 35 }, | 44 }, |
| 36 /** | 45 /** |
| 37 * The user kerberos default realm. Used for autocompletion. | 46 * The user kerberos default realm. Used for autocompletion. |
| 38 */ | 47 */ |
| 39 userRealm: String, | 48 userRealm: String, |
| 40 /** | 49 /** |
| 41 * Welcome message on top of the UI. | 50 * Welcome message on top of the UI. |
| 42 */ | 51 */ |
| 43 adWelcomeMessage: String | 52 adWelcomeMessage: String, |
| 53 /** |
| 54 * Error message for the machine name input. |
| 55 */ |
| 56 machineNameError: String, |
| 44 }, | 57 }, |
| 45 | 58 |
| 46 /** @private */ | 59 /** @private */ |
| 47 realmChanged_: function() { | 60 realmChanged_: function() { |
| 48 this.adWelcomeMessage = | 61 this.adWelcomeMessage = |
| 49 loadTimeData.getStringF('adAuthWelcomeMessage', this.realm); | 62 loadTimeData.getStringF('adAuthWelcomeMessage', this.realm); |
| 50 }, | 63 }, |
| 51 | 64 |
| 52 /** @private */ | 65 /** @private */ |
| 53 disabledChanged_: function() { | 66 disabledChanged_: function() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 66 }, | 79 }, |
| 67 | 80 |
| 68 /** | 81 /** |
| 69 * @param {string|undefined} user | 82 * @param {string|undefined} user |
| 70 * @param {string|undefined} machineName | 83 * @param {string|undefined} machineName |
| 71 */ | 84 */ |
| 72 setUser: function(user, machineName) { | 85 setUser: function(user, machineName) { |
| 73 this.$.userInput.value = user || ''; | 86 this.$.userInput.value = user || ''; |
| 74 this.$.machineNameInput.value = machineName || ''; | 87 this.$.machineNameInput.value = machineName || ''; |
| 75 this.$.passwordInput.value = ''; | 88 this.$.passwordInput.value = ''; |
| 76 this.$.passwordInput.isInvalid = !!user; | |
| 77 this.focus(); | 89 this.focus(); |
| 78 }, | 90 }, |
| 79 | 91 |
| 92 /** |
| 93 * @param {ACTIVE_DIRECTORY_ERROR_STATE} error_state |
| 94 */ |
| 95 setInvalid: function(error_state) { |
| 96 this.$.machineNameInput.isInvalid = false; |
| 97 this.$.userInput.isInvalid = false; |
| 98 this.$.passwordInput.isInvalid = false; |
| 99 switch (error_state) { |
| 100 case ACTIVE_DIRECTORY_ERROR_STATE.NONE: |
| 101 break; |
| 102 case ACTIVE_DIRECTORY_ERROR_STATE.MACHINE_NAME_INVALID: |
| 103 this.machineNameError = |
| 104 loadTimeData.getString('adJoinErrorMachineNameInvalid'); |
| 105 this.$.machineNameInput.isInvalid = true; |
| 106 break; |
| 107 case ACTIVE_DIRECTORY_ERROR_STATE.MACHINE_NAME_TOO_LONG: |
| 108 this.machineNameError = |
| 109 loadTimeData.getString('adJoinErrorMachineNameTooLong'); |
| 110 this.$.machineNameInput.isInvalid = true; |
| 111 break; |
| 112 case ACTIVE_DIRECTORY_ERROR_STATE.BAD_USERNAME: |
| 113 this.$.userInput.isInvalid = true; |
| 114 break; |
| 115 case ACTIVE_DIRECTORY_ERROR_STATE.BAD_PASSWORD: |
| 116 this.$.passwordInput.isInvalid = true; |
| 117 break; |
| 118 } |
| 119 }, |
| 120 |
| 80 /** @private */ | 121 /** @private */ |
| 81 onSubmit_: function() { | 122 onSubmit_: function() { |
| 82 if (this.showMachineInput && !this.$.machineNameInput.checkValidity()) | 123 if (this.showMachineInput && !this.$.machineNameInput.checkValidity()) |
| 83 return; | 124 return; |
| 84 if (!this.$.passwordInput.checkValidity()) | 125 if (!this.$.passwordInput.checkValidity()) |
| 85 return; | 126 return; |
| 86 var user = /** @type {string} */ (this.$.userInput.value); | 127 var user = /** @type {string} */ (this.$.userInput.value); |
| 87 if (!user.includes('@') && this.userRealm) | 128 if (!user.includes('@') && this.userRealm) |
| 88 user += this.userRealm; | 129 user += this.userRealm; |
| 89 var msg = { | 130 var msg = { |
| 90 'machinename': this.$.machineNameInput.value, | 131 'machinename': this.$.machineNameInput.value, |
| 91 'username': user, | 132 'username': user, |
| 92 'password': this.$.passwordInput.value | 133 'password': this.$.passwordInput.value |
| 93 }; | 134 }; |
| 94 this.$.passwordInput.value = ''; | 135 this.$.passwordInput.value = ''; |
| 95 this.fire('authCompleted', msg); | 136 this.fire('authCompleted', msg); |
| 96 }, | 137 }, |
| 97 }); | 138 }); |
| OLD | NEW |