summaryrefslogtreecommitdiffstats
path: root/apps/encryption/js/settings-personal.js
blob: 75ebab5059ca051fe85444f73dc2aa4d648a1e5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
 * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */

OC.Encryption = _.extend(OC.Encryption || {}, {
	updatePrivateKeyPassword: function () {
		var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
		var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
		OC.msg.startSaving('#ocDefaultEncryptionModule .msg');
		$.post(
			OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'),
			{
				oldPassword: oldPrivateKeyPassword,
				newPassword: newPrivateKeyPassword
			}
		).done(function (data) {
				OC.msg.finishedSuccess('#ocDefaultEncryptionModule .msg', data.message);
			})
			.fail(function (jqXHR) {
				OC.msg.finishedError('#ocDefaultEncryptionModule .msg', JSON.parse(jqXHR.responseText).message);
			});
	}
});

$(document).ready(function () {

	// Trigger ajax on recoveryAdmin status change
	$('input:radio[name="userEnableRecovery"]').change(
		function () {
			var recoveryStatus = $(this).val();
			OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...');
			$.post(
				OC.generateUrl('/apps/encryption/ajax/userSetRecovery'),
				{
					userEnableRecovery: recoveryStatus
				}
			).done(function (data) {
					OC.msg.finishedSuccess('#userEnableRecovery .msg', data.data.message);
				})
				.fail(function (jqXHR) {
					OC.msg.finishedError('#userEnableRecovery .msg', JSON.parse(jqXHR.responseText).data.message);
				});
			// Ensure page is not reloaded on form submit
			return false;
		}
	);

	// update private key password

	$('input:password[name="changePrivateKeyPassword"]').keyup(function (event) {
		var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
		var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
		if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '') {
			$('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled");
			if (event.which === 13) {
				OC.Encryption.updatePrivateKeyPassword();
			}
		} else {
			$('button:button[name="submitChangePrivateKeyPassword"]').attr("disabled", "true");
		}
	});

	$('button:button[name="submitChangePrivateKeyPassword"]').click(function () {
		OC.Encryption.updatePrivateKeyPassword();
	});

});