Nicer password widget on account edit dialog

- Added plain-text attribute to avoid encrypting password
- Suggest password now fills both fields the same
This commit is contained in:
nathangray 2020-06-15 16:08:24 -06:00
parent 8020464dde
commit d7d5837ecf
6 changed files with 52 additions and 8 deletions

View File

@ -905,10 +905,20 @@ var AddressbookApp = /** @class */ (function (_super) {
*/ */
AddressbookApp.prototype.account_change = function (_ev, _widget) { AddressbookApp.prototype.account_change = function (_ev, _widget) {
switch (_widget.id) { switch (_widget.id) {
case 'account_passwd':
debugger;
// If they clicked suggest, copy it to password 2
if (_widget && _widget.options.viewable) {
var p2 = _widget.getParent().getWidgetById('account_passwd_2');
p2.set_viewable(true); // Allow viewing password
p2.toggle_visibility(true); // Actually show it
p2.set_value(_widget.getValue());
_widget.options.viewable = false;
}
// Fall through
case 'account_lid': case 'account_lid':
case 'n_family': case 'n_family':
case 'n_given': case 'n_given':
case 'account_passwd':
case 'account_passwd_2': case 'account_passwd_2':
var values = this.et2._inst.getValues(this.et2); var values = this.et2._inst.getValues(this.et2);
var data = { var data = {

View File

@ -1101,10 +1101,21 @@ class AddressbookApp extends EgwApp
{ {
switch(_widget.id) switch(_widget.id)
{ {
case 'account_passwd':
debugger;
// If they clicked suggest, copy it to password 2
if(_widget && _widget.options.viewable)
{
let p2 = _widget.getParent().getWidgetById('account_passwd_2');
p2.set_viewable(true); // Allow viewing password
p2.toggle_visibility(true); // Actually show it
p2.set_value(_widget.getValue());
_widget.options.viewable = false;
}
// Fall through
case 'account_lid': case 'account_lid':
case 'n_family': case 'n_family':
case 'n_given': case 'n_given':
case 'account_passwd':
case 'account_passwd_2': case 'account_passwd_2':
var values = this.et2._inst.getValues(this.et2); var values = this.et2._inst.getValues(this.et2);
var data = { var data = {

View File

@ -26,10 +26,10 @@
</row> </row>
<row> <row>
<description value="Password" for="account_passwd"/> <description value="Password" for="account_passwd"/>
<passwd id="account_passwd" class="et2_fullWidth" onchange="app.addressbook.account_change" autocomplete="new-password"/> <passwd id="account_passwd" class="et2_fullWidth" onchange="app.addressbook.account_change" autocomplete="new-password" plaintext="true"/>
<description/> <description/>
<description value="Re-enter password" for="account_passwd_2"/> <description value="Re-enter password" for="account_passwd_2"/>
<passwd id="account_passwd_2" class="et2_fullWidth" onchange="app.addressbook.account_change"/> <passwd id="account_passwd_2" class="et2_fullWidth" onchange="app.addressbook.account_change" plaintext="true" suggest="0"/>
<description/> <description/>
</row> </row>
<row valign="top"> <row valign="top">

View File

@ -49,6 +49,9 @@ var et2_password = /** @class */ (function (_super) {
// The password is stored encrypted server side, and passed encrypted. // The password is stored encrypted server side, and passed encrypted.
// This flag is for if we've decrypted the password to show it already // This flag is for if we've decrypted the password to show it already
_this.encrypted = true; _this.encrypted = true;
if (_this.options.plaintext) {
_this.encrypted = false;
}
return _this; return _this;
} }
et2_password.prototype.createInputWidget = function () { et2_password.prototype.createInputWidget = function () {
@ -217,6 +220,7 @@ var et2_password = /** @class */ (function (_super) {
var request = egw.json("EGroupware\\Api\\Etemplate\\Widget\\Password::ajax_suggest", [this.options.suggest], function (suggestion) { var request = egw.json("EGroupware\\Api\\Etemplate\\Widget\\Password::ajax_suggest", [this.options.suggest], function (suggestion) {
this.encrypted = false; this.encrypted = false;
this.input.val(suggestion); this.input.val(suggestion);
this.input.trigger('change');
}, this, true, this).sendRequest(); }, this, true, this).sendRequest();
}; };
et2_password.prototype.destroy = function () { et2_password.prototype.destroy = function () {
@ -238,6 +242,12 @@ var et2_password = /** @class */ (function (_super) {
"default": false, "default": false,
"description": "Allow password to be shown" "description": "Allow password to be shown"
}, },
"plaintext": {
name: "Plaintext",
type: "boolean",
default: false,
description: "Password is plaintext"
},
"suggest": { "suggest": {
name: "Suggest password", name: "Suggest password",
type: "integer", type: "integer",

View File

@ -43,6 +43,12 @@ export class et2_password extends et2_textbox
"default": false, "default": false,
"description": "Allow password to be shown" "description": "Allow password to be shown"
}, },
"plaintext": {
name: "Plaintext",
type: "boolean",
default: false,
description: "Password is plaintext"
},
"suggest": { "suggest": {
name: "Suggest password", name: "Suggest password",
type: "integer", type: "integer",
@ -68,6 +74,10 @@ export class et2_password extends et2_textbox
// Call the inherited constructor // Call the inherited constructor
super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_password._attributes, _child || {})); super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_password._attributes, _child || {}));
if(this.options.plaintext)
{
this.encrypted = false;
}
} }
createInputWidget() createInputWidget()
@ -289,6 +299,7 @@ export class et2_password extends et2_textbox
function(suggestion) { function(suggestion) {
this.encrypted = false; this.encrypted = false;
this.input.val(suggestion); this.input.val(suggestion);
this.input.trigger('change');
}, },
this,true,this this,true,this
).sendRequest(); ).sendRequest();

View File

@ -48,12 +48,14 @@ class Password extends Etemplate\Widget\Textbox
{ {
$form_name = self::form_name($cname, $this->id, $expand); $form_name = self::form_name($cname, $this->id, $expand);
$value =& self::get_array(self::$request->content, $form_name); $value =& self::get_array(self::$request->content, $form_name);
$plaintext = 'true' == self::expand_name($this->attrs['plaintext'],$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
if (!empty($value)) if (!empty($value))
{ {
$preserv =& self::get_array(self::$request->preserv, $form_name, true); $preserv =& self::get_array(self::$request->preserv, $form_name, true);
$preserv = (string)$value; $preserv = (string)$value;
if (!empty($value) && array_key_exists('viewable', $this->attrs) && $this->attrs['viewable'] == 'false') if (!empty($value) && ((array_key_exists('viewable', $this->attrs) && $this->attrs['viewable'] === 'false') || $plaintext))
{ {
$value = str_repeat('*', strlen($preserv)); $value = str_repeat('*', strlen($preserv));
} }
@ -76,7 +78,7 @@ class Password extends Etemplate\Widget\Textbox
public function validate($cname, array $expand, array $content, &$validated=array()) public function validate($cname, array $expand, array $content, &$validated=array())
{ {
$form_name = self::form_name($cname, $this->id, $expand); $form_name = self::form_name($cname, $this->id, $expand);
$plaintext = 'true' == self::expand_name($this->attrs['plaintext'],$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
if (!$this->is_readonly($cname, $form_name)) if (!$this->is_readonly($cname, $form_name))
{ {
$value = $value_in = self::get_array($content, $form_name); $value = $value_in = self::get_array($content, $form_name);
@ -88,12 +90,12 @@ class Password extends Etemplate\Widget\Textbox
{ {
$value = $preserv; $value = $preserv;
} }
else if ($value_in == Credentials::decrypt(array('cred_password' => $preserv,'cred_pw_enc' => Credentials::SYSTEM_AES))) else if (!$plaintext && $preserv && $value_in == Credentials::decrypt(array('cred_password' => $preserv,'cred_pw_enc' => Credentials::SYSTEM_AES)))
{ {
// Don't change if they submitted the decrypted version // Don't change if they submitted the decrypted version
$value = $preserv; $value = $preserv;
} }
else if ($value_in !== $preserv) else if (!$plaintext && $value_in !== $preserv)
{ {
// Store encrypted // Store encrypted
$encryption = null; $encryption = null;