Skip to content

Commit

Permalink
Merge pull request #489 from buttercup/feature/change-password
Browse files Browse the repository at this point in the history
Change Password
  • Loading branch information
sallar authored Feb 2, 2018
2 parents e4ec584 + 97c85d9 commit fe65438
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 32 deletions.
2 changes: 2 additions & 0 deletions locales/en/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"archive-menu": {
"unlock": "Unlock",
"change-color": "Change Color",
"change-password": "Change Password",
"import": "Import",
"import-from-type": "From {{name}} archive (.{{extension}})",
"archive-remove-with-name": "Remove {{name}}",
Expand Down Expand Up @@ -187,6 +188,7 @@
},
"password-dialog": {
"master-password": "Master Password",
"new-password": "New Password",
"password": "Password",
"confirm-password": "Confirm Password",
"confirm": "Confirm",
Expand Down
4 changes: 3 additions & 1 deletion locales/fa/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
},
"archive-menu": {
"unlock": "رمزگشایی",
"change-color": "تغییر رمز عبور",
"change-color": "تغییر رنگ",
"change-password": "تغییر رمز عبور",
"import": "درون ریزی",
"import-from-type": "از آرشیو {{name}} (.{{extension}})",
"archive-remove-with-name": "حذف {{name}}",
Expand Down Expand Up @@ -187,6 +188,7 @@
},
"password-dialog": {
"master-password": "رمز عبور اصلی",
"new-password": "رمز عبور جدید",
"password": "رمز عبور",
"confirm-password": "تایید رمز عبور",
"confirm": "تایید",
Expand Down
32 changes: 24 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"babel-preset-react": "^6.16.0",
"babel-preset-react-optimize": "^1.0.1",
"babel-register": "^6.18.0",
"buttercup": "~1.1.1",
"buttercup": "~1.4.0",
"buttercup-importer": "~0.9.2",
"classnames": "^2.2.5",
"concurrently": "^3.5.1",
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/sidebar-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class SidebarItem extends PureComponent {
index: PropTypes.number.isRequired,
onClick: PropTypes.func.isRequired,
onLockArchive: PropTypes.func.isRequired,
onChangePassword: PropTypes.func.isRequired,
onRemoveClick: PropTypes.func.isRequired,
onArchiveUpdate: PropTypes.func.isRequired,
showImportDialog: PropTypes.func.isRequired,
Expand Down Expand Up @@ -136,6 +137,10 @@ class SidebarItem extends PureComponent {
{
label: label('lock'),
click: this.props.onLockArchive
},
{
label: label('change-password'),
click: this.props.onChangePassword
}
]
: []),
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RecentFiles extends PureComponent {
onArchiveUpdate: PropTypes.func.isRequired,
onClick: PropTypes.func.isRequired,
onLockArchive: PropTypes.func.isRequired,
onChangePassword: PropTypes.func.isRequired,
showImportDialog: PropTypes.func.isRequired
};

Expand Down Expand Up @@ -64,6 +65,7 @@ class RecentFiles extends PureComponent {
index={i}
condenced={condenced}
onLockArchive={() => this.props.onLockArchive(archive.id)}
onChangePassword={() => this.props.onChangePassword(archive.id)}
onArchiveUpdate={this.props.onArchiveUpdate}
onClick={() => this.props.onClick(archive.id)}
onRemoveClick={() => this.props.onRemoveClick(archive.id)}
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/containers/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
removeArchive,
loadOrUnlockArchive,
lockArchive,
changeArchivePassword,
updateArchive,
showImportDialog
} from '../../shared/actions/archives';
Expand All @@ -23,6 +24,7 @@ export default connect(
onRemoveClick: removeArchive,
onClick: loadOrUnlockArchive,
onLockArchive: lockArchive,
onChangePassword: changeArchivePassword,
onOpenClick: openArchive,
onNewClick: newArchive,
onArchiveUpdate: updateArchive,
Expand Down
18 changes: 18 additions & 0 deletions src/renderer/system/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,21 @@ export function showPasswordDialog(preConfirm, options = {}) {
preConfirm
});
}

export function showConfirmedPasswordDialog(
preConfirm,
firstDialogOptions = {},
secondDialogOptions = {}
) {
return showPasswordDialog(undefined, firstDialogOptions).then(firstPassword =>
showPasswordDialog(password => {
if (firstPassword !== password) {
return Promise.reject(new Error(i18n.t('error.passwords-dont-match')));
}
if (typeof preConfirm === 'function') {
return preConfirm(password);
}
return Promise.resolve();
}, secondDialogOptions)
);
}
8 changes: 5 additions & 3 deletions src/renderer/system/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { ipcRenderer as ipc } from 'electron';
export function enqueue(channelName, fn, stack) {
const id = uuid.v4();

ipc.once(`channel:execute:${id}`, () => {
ipc.once(`channel:execute:${id}`, async () => {
const output = fn();
const result = output instanceof Promise ? output : Promise.resolve(output);
result.then(() => ipc.send(`channel:resolve:${id}`));
if (output instanceof Promise) {
await output;
}
ipc.send(`channel:resolve:${id}`);
});

ipc.send('channel:enqueue', {
Expand Down
47 changes: 29 additions & 18 deletions src/shared/actions/archives.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { ipcRenderer as ipc } from 'electron';
import { createAction } from 'redux-actions';
import { ArchiveTypes } from '../buttercup/types';
import { importHistory } from '../buttercup/import';
import { showPasswordDialog } from '../../renderer/system/dialog';
import {
showPasswordDialog,
showConfirmedPasswordDialog
} from '../../renderer/system/dialog';
import { reloadGroups } from './groups';
import {
ARCHIVES_ADD,
Expand All @@ -20,7 +23,8 @@ import {
addArchiveToArchiveManager,
lockArchiveInArchiveManager,
removeArchiveFromArchiveManager,
unlockArchiveInArchiveManager
unlockArchiveInArchiveManager,
updateArchivePassword
} from '../buttercup/archive';
import i18n from '../i18n';

Expand All @@ -45,6 +49,22 @@ export const removeArchive = payload => () => {
return removeArchiveFromArchiveManager(payload);
};

export const changeArchivePassword = payload => () => {
showConfirmedPasswordDialog(
undefined,
{
title: i18n.t('password-dialog.new-password')
},
{
title: i18n.t('password-dialog.confirm-password')
}
)
.then(password => {
updateArchivePassword(payload, password);
})
.catch(() => {});
};

export const lockArchive = payload => dispatch => {
return lockArchiveInArchiveManager(payload).then(archiveId => {
dispatch(lockArchiveInStore(archiveId));
Expand Down Expand Up @@ -92,22 +112,13 @@ export const addArchive = payload => async (dispatch, getState) => {
}

// Otherwise show a confirmation too.
return showPasswordDialog()
.then(firstPassword =>
showPasswordDialog(
password => {
if (firstPassword !== password) {
return Promise.reject(
new Error(i18n.t('error.passwords-dont-match'))
);
}
return addToArchive(password);
},
{
title: i18n.t('password-dialog.confirm-password')
}
)
)
return showConfirmedPasswordDialog(
addToArchive,
{},
{
title: i18n.t('password-dialog.confirm-password')
}
)
.then(dispatchLoad)
.catch(() => {});
};
Expand Down
9 changes: 9 additions & 0 deletions src/shared/buttercup/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ export function saveWorkspace(archiveId) {
.then(shouldSave => (shouldSave ? workspace.save() : null));
});
}

export function updateArchivePassword(archiveId, newPassword) {
const manager = getSharedArchiveManager();
const passwordCredentials = createCredentials.fromPassword(newPassword);

enqueue('saves', () => {
return manager.updateArchiveCredentials(archiveId, passwordCredentials);
});
}
2 changes: 1 addition & 1 deletion src/shared/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ i18n.init({
contextSeparator: '-',
debug: false,
saveMissingTo: 'all',
saveMissing: true,
saveMissing: false,
returnEmptyString: false
});

Expand Down

0 comments on commit fe65438

Please sign in to comment.