summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/ajax/mode.php
blob: f1a026ca43144f88c68a4b668022fc91a5c55410 (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
<?php
/**
 * Copyright (c) 2012, Bjoern Schiessle <schiessle@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */

//TODO: Handle switch between client and server side encryption

use OCA_Encryption\Keymanager;

OCP\JSON::checkAppEnabled('files_encryption');
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();

$mode = $_POST['mode'];
$changePasswd = false;
$passwdChanged = false;

if ( isset($_POST['newpasswd']) && isset($_POST['oldpasswd']) ) {
	$oldpasswd = $_POST['oldpasswd'];
	$newpasswd = $_POST['newpasswd'];
	$changePasswd = true;
	$passwdChanged = Keymanager::changePasswd($oldpasswd, $newpasswd);
}

$query = \OC_DB::prepare( "SELECT mode FROM *PREFIX*encryption WHERE uid = ?" );
$result = $query->execute(array(\OCP\User::getUser()));

if ($result->fetchRow()){
	$query = OC_DB::prepare( 'UPDATE *PREFIX*encryption SET mode = ? WHERE uid = ?' );
} else {
	$query = OC_DB::prepare( 'INSERT INTO *PREFIX*encryption ( mode, uid ) VALUES( ?, ? )' );
}

if ( (!$changePasswd || $passwdChanged) && $query->execute(array($mode, \OCP\User::getUser())) ) {
	OCP\JSON::success();
} else {
	OCP\JSON::error();
}