2012-08-02 12:39:30 +04:00
|
|
|
<?php
|
2012-08-02 15:55:23 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-02 12:39:30 +04:00
|
|
|
|
2012-10-17 19:35:19 +04:00
|
|
|
use OCA\Encryption\Keymanager;
|
2012-08-09 14:19:51 +04:00
|
|
|
|
2012-08-02 12:39:30 +04:00
|
|
|
OCP\JSON::checkAppEnabled('files_encryption');
|
|
|
|
OCP\JSON::checkLoggedIn();
|
|
|
|
OCP\JSON::callCheck();
|
|
|
|
|
|
|
|
$mode = $_POST['mode'];
|
2012-08-09 14:19:51 +04:00
|
|
|
$changePasswd = false;
|
|
|
|
$passwdChanged = false;
|
|
|
|
|
|
|
|
if ( isset($_POST['newpasswd']) && isset($_POST['oldpasswd']) ) {
|
|
|
|
$oldpasswd = $_POST['oldpasswd'];
|
|
|
|
$newpasswd = $_POST['newpasswd'];
|
|
|
|
$changePasswd = true;
|
|
|
|
$passwdChanged = Keymanager::changePasswd($oldpasswd, $newpasswd);
|
|
|
|
}
|
2012-08-02 12:39:30 +04:00
|
|
|
|
|
|
|
$query = \OC_DB::prepare( "SELECT mode FROM *PREFIX*encryption WHERE uid = ?" );
|
|
|
|
$result = $query->execute(array(\OCP\User::getUser()));
|
|
|
|
|
2012-08-02 15:55:23 +04:00
|
|
|
if ($result->fetchRow()){
|
2012-08-02 12:39:30 +04:00
|
|
|
$query = OC_DB::prepare( 'UPDATE *PREFIX*encryption SET mode = ? WHERE uid = ?' );
|
|
|
|
} else {
|
|
|
|
$query = OC_DB::prepare( 'INSERT INTO *PREFIX*encryption ( mode, uid ) VALUES( ?, ? )' );
|
|
|
|
}
|
2012-08-09 15:47:27 +04:00
|
|
|
|
2012-08-09 14:19:51 +04:00
|
|
|
if ( (!$changePasswd || $passwdChanged) && $query->execute(array($mode, \OCP\User::getUser())) ) {
|
|
|
|
OCP\JSON::success();
|
|
|
|
} else {
|
|
|
|
OCP\JSON::error();
|
|
|
|
}
|