Merge pull request #5486 from duplicati/feature/improve-initial-password-setup

Added a dialog for changing the server passphrase.
This commit is contained in:
Kenneth Skovhede
2024-08-27 18:27:07 +02:00
committed by GitHub
6 changed files with 87 additions and 11 deletions
+1
View File
@@ -103,6 +103,7 @@
<script type="text/javascript" src="scripts/controllers/PauseController.js?v=2.0.0.7"></script>
<script type="text/javascript" src="scripts/controllers/CommandlineController.js?v=2.0.0.7"></script>
<script type="text/javascript" src="scripts/controllers/ThrottleController.js?v=2.0.0.7"></script>
<script type="text/javascript" src="scripts/controllers/ChangePasswordController.js?v=2.0.0.7"></script>
<script type="text/javascript" src="scripts/filters/timeremaining.js?v=2.0.0.7"></script>
<script type="text/javascript" src="scripts/filters/highlight.js?v=2.0.0.7"></script>
@@ -176,17 +176,55 @@ backupApp.controller('AppController', function($scope, $cookies, $location, AppS
var dt = data.data['max-download-speed'];
$scope.throttle_active = (ut != null && ut.trim().length != 0) || (dt != null && dt.trim().length != 0);
var has_asked = data.data['has-asked-for-password-change'];
var autogen_passphrase = data.data['autogenerated-passphrase'];
if (!has_asked && autogen_passphrase == "True") {
var has_asked = AppUtils.parseBoolString(data.data['has-asked-for-password-change']);
var autogen_passphrase = AppUtils.parseBoolString(data.data['autogenerated-passphrase']);
if (!has_asked && autogen_passphrase) {
DialogService.dialog(
gettextCatalog.getString('First run setup'),
gettextCatalog.getString('Duplicati needs to be secured with a passphrase and a random passphrase has been generated for you.\nIf you open Duplicati from the tray icon, you do not need a passphrase, but if you plan to open it from another location you need to set a passphrase you know.\nDo you want to set a passphrase now?'),
[gettextCatalog.getString('No'), gettextCatalog.getString('Yes')],
[gettextCatalog.getString('Yes'), gettextCatalog.getString('No')],
function(btn) {
AppService.patch('/serversettings', { 'has-asked-for-password-change': 'true'}, {'headers': {'Content-Type': 'application/json'}});
if (btn == 1) {
$location.path('/settings');
// Set the flag so we don't ask again
AppService.patch('/serversettings', { 'has-asked-for-password-change': 'true'});
}
else
{
DialogService.htmlDialog(
gettextCatalog.getString('Change server password'),
'templates/changepassword.html',
[gettextCatalog.getString('OK'), gettextCatalog.getString('Cancel')],
function(index, text, cur) {
if (index != 0)
return;
AppService.patch('/serversettings',
{
'has-asked-for-password-change': 'true',
'server-passphrase': cur.remotePassword
})
.then(function() {}, AppUtils.connectionError);
},
null,
function(index, text, cur) {
if (index != 0)
return true;
if (cur.remotePassword == null || cur.remotePassword.length == 0)
{
alert("Please enter a passphrase");
return false;
}
if(cur.remotePassword != cur.confirmPassword)
{
alert("Passwords do not match");
return false;
}
return true;
}
);
}
}
);
@@ -0,0 +1,6 @@
backupApp.controller('ChangePasswordController', function($scope, gettextCatalog) {
$scope.selection = $scope.$parent.state.CurrentItem;
$scope.selection.remotePassword = '';
$scope.selection.confirmPassword = '';
});
@@ -23,8 +23,11 @@ backupApp.controller('DialogController', function($scope, DialogService, gettext
$scope.onButtonClick = function(index) {
var cur = $scope.state.CurrentItem;
var input = cur.textarea;
DialogService.dismissCurrent();
if (cur.validate && !cur.validate(index, input, cur))
return;
DialogService.dismissCurrent();
if (cur.callback)
cur.callback(index, input, cur);
};
@@ -69,17 +69,18 @@ backupApp.service('DialogService', function(gettextCatalog) {
});
};
this.htmlDialog = function(title, htmltemplate, buttons, callback, onshow) {
this.htmlDialog = function(title, htmltemplate, buttons, callback, onshow, validate) {
return this.enqueueDialog({
'htmltemplate': htmltemplate,
'title': title,
'callback': callback,
'buttons': buttons,
'onshow': onshow
'onshow': onshow,
'validate': validate
});
};
this.textareaDialog = function(title, message, placeholder, textarea, buttons, buttonTemplate, callback, onshow) {
this.textareaDialog = function(title, message, placeholder, textarea, buttons, buttonTemplate, callback, onshow, validate) {
return this.enqueueDialog({
'enableTextarea': true,
'title': title,
@@ -89,7 +90,8 @@ backupApp.service('DialogService', function(gettextCatalog) {
'callback': callback,
'buttons': buttons,
'buttonTemplate': buttonTemplate,
'onshow': onshow
'onshow': onshow,
'validate': validate
});
};
@@ -0,0 +1,26 @@
<div ng-controller="ChangePasswordController" class="passwordoptions">
<form class="styled">
<ul>
<div class="input mixed multiple">
<label for="password" translate>New Password</label><br />
<input
type="password"
id="password"
name="password"
ng-model="selection.remotePassword"
/>
</div>
<div class="input mixed multiple">
<label for="confirm-password" translate>Confirm new password</label
><br />
<input
type="password"
id="confirm-password"
name="confirm-password"
ng-model="selection.confirmPassword"
autocomplete="new-password"
/>
</div>
</ul>
</form>
</div>