custom fields added to edit login page

This commit is contained in:
Kyle Spearrin 2017-09-21 13:21:09 -04:00
parent 96585b183d
commit 7a31783ea4
3 changed files with 112 additions and 1 deletions

View File

@ -43,6 +43,7 @@ angular
login.password = loginData.Password && loginData.Password !== '' ? cryptoService.decrypt(loginData.Password, key) : null;
login.notes = loginData.Notes && loginData.Notes !== '' ? cryptoService.decrypt(loginData.Notes, key) : null;
login.totp = loginData.Totp && loginData.Totp !== '' ? cryptoService.decrypt(loginData.Totp, key) : null;
login.fields = _service.decryptFields(key, loginData.Fields);
}
if (!encryptedLogin.Attachments) {
@ -134,6 +135,28 @@ angular
return deferred.promise;
};
_service.decryptFields = function (key, encryptedFields) {
var unencryptedFields = [];
if (encryptedFields) {
for (var i = 0; i < encryptedFields.length; i++) {
unencryptedFields.push(_service.decryptField(key, encryptedFields[i]));
}
}
return unencryptedFields;
};
_service.decryptField = function (key, encryptedField) {
if (!encryptedField) throw "encryptedField is undefined or null";
return {
type: encryptedField.Type.toString(),
name: encryptedField.Name && encryptedField.Name !== '' ? cryptoService.decrypt(encryptedField.Name, key) : null,
value: encryptedField.Value && encryptedField.Value !== '' ? cryptoService.decrypt(encryptedField.Value, key) : null
};
};
_service.decryptFolders = function (encryptedFolders) {
if (!encryptedFolders) throw "encryptedFolders is undefined or null";
@ -234,7 +257,8 @@ angular
username: !unencryptedLogin.username || unencryptedLogin.username === '' ? null : cryptoService.encrypt(unencryptedLogin.username, key),
password: !unencryptedLogin.password || unencryptedLogin.password === '' ? null : cryptoService.encrypt(unencryptedLogin.password, key),
totp: !unencryptedLogin.totp || unencryptedLogin.totp === '' ? null : cryptoService.encrypt(unencryptedLogin.totp, key)
}
},
fields: _service.encryptFields(unencryptedLogin.fields, key)
};
if (unencryptedLogin.attachments && attachments) {
@ -274,6 +298,33 @@ angular
return deferred.promise;
};
_service.encryptFields = function (unencryptedFields, key) {
if (!unencryptedFields || !unencryptedFields.length) {
return null;
}
var encFields = [];
for (var i = 0; i < unencryptedFields.length; i++) {
if (!unencryptedFields[i]) {
continue;
}
encFields.push(_service.encryptField(unencryptedFields[i], key));
}
return encFields;
};
_service.encryptField = function (unencryptedField, key) {
if (!unencryptedField) throw "unencryptedField is undefined or null";
return {
type: parseInt(unencryptedField.type),
name: unencryptedField.name ? cryptoService.encrypt(unencryptedField.name, key) : null,
value: unencryptedField.value ? cryptoService.encrypt(unencryptedField.value.toString(), key) : null
};
};
_service.encryptFolders = function (unencryptedFolders, key) {
if (!unencryptedFolders) throw "unencryptedFolders is undefined or null";

View File

@ -54,6 +54,21 @@
}
};
$scope.addField = function () {
$scope.login.fields.push({
type: 0,
name: null,
value: null
});
}
$scope.removeField = function (field) {
var index = $scope.login.fields.indexOf(field);
if (index > -1) {
$scope.login.fields.splice(index, 1);
}
}
$scope.clipboardSuccess = function (e) {
e.clearSelection();
selectPassword(e);

View File

@ -112,6 +112,51 @@
<textarea id="notes" name="Notes" class="form-control" ng-model="login.notes"
ng-readonly="readOnly" api-field></textarea>
</div>
<h4>
<i class="fa fa-list-ul"></i> Custom Fields
<a class="btn btn-link" href="#" ng-click="addField()">
<i class="fa fa-lg fa-plus-circle"></i> Add
</a>
</h4>
<div class="row" ng-repeat="field in login.fields">
<div class="col-sm-3">
<div class="form-group">
<label for="field_name{{$index}}">Name</label>
<input type="text" id="field_name{{$index}}" name="Field.Name{{$index}}" class="form-control" ng-model="field.name" />
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="field_type{{$index}}">Type</label>
<select id="field_type{{$index}}" name="Field.Type{{$index}}" class="form-control" ng-model="field.type">
<option value="0">Text</option>
<option value="1">Hidden</option>
<option value="2">Boolean</option>
</select>
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<div class="pull-right password-options" ng-if="field.type === '1'">
<i class="fa fa-lg fa-eye" uib-tooltip="Toggle Visibility" tooltip-placement="left"
password-viewer="#field_value{{$index}}"></i>
</div>
<label for="field_value{{$index}}">Value</label>
<input ng-attr-type="{{field.type === '0' ? 'text' : 'password'}}" id="field_value{{$index}}"
name="Field.Value{{$index}}" class="form-control" ng-model="field.value" ng-if="field.type !== '2'" />
<div ng-if="field.type === '2'">
<input type="checkbox" id="field_value{{$index}}" name="Field.Value{{$index}}" ng-model="field.value"
data-ng-true-value="'true'" />
</div>
</div>
</div>
<div class="col-md-1">
<a href="#" ng-click="removeField(field)">
<i class="fa fa-remove fa-lg"></i>
<span class="sr-only">Remove</span>
</a>
</div>
</div>
<div class="checkbox" ng-if="!hideFavorite">
<label>
<input type="checkbox" ng-model="login.favorite" name="Favorite" />