<?php

// Init owncloud
require_once('lib/base.php');

$username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
$yubikey_prefix = $_POST["yubikey"];

OC_JSON::checkLoggedIn();
if(!OC_Group::inGroup( OC_User::getUser(), 'admin' )){
	OC_JSON::error( array( "data" => array( "message" => "Authentication error" )));
	exit();
}

// Return Success story
if( OC_Preferences::setValue($username, 'user_yubikey', 'identity', $yubikey_prefix)){
	OC_JSON::success(array("data" => array( "yubikey_prefix" => $yubikey_prefix )));
}
else{
	OC_JSON::error(array("data" => array( "message" => "Unable to change Yubikey prefix" )));
}

?>
