Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions IJR_CallbackDefines.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ private function defineWikiMethods()
$this->obj['help'] = 'Tries to login with the given credentials and sets auth cookies.';
$this->methods[] = $this->obj;

/* Function to create user */
$this->obj['method'] = 'dokuwiki.createUser';
$this->obj['callback'] = 'this:createUser';
$this->obj['args'] = array('string','string','string','string');
$this->obj['help'] = 'Creates an user, based on the Username and password provided';
$this->methods[] = $this->obj;

$this->obj['method'] = 'dokuwiki.getPagelist';
$this->obj['callback'] = 'this:readNamespace';
$this->obj['args'] = array('string','struct');
Expand Down
48 changes: 45 additions & 3 deletions jsonrpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ function addCallback($method, $callback, $args, $help, $public=false){


function call($methodname, $args){
if(!in_array($methodname,$this->public_methods) && !$this->checkAuth()){
return new IJR_Error(-32603, 'server error. not authorized to call method "'.$methodname.'".');
}
if($methodname != "dokuwiki.login") { // Allow the login function to pass through, since no session will exist at this point
if(!in_array($methodname,$this->public_methods) && !$this->checkAuth()){
return new IJR_Error(-32603, 'server error. not authorized to call method "'.$methodname.'".');
}
}

return parent::call($methodname, $args);
}

Expand Down Expand Up @@ -697,6 +700,45 @@ public function login($user,$pass){
return auth_login($user,$pass,false,true);
}
}

/**
* Helps create a new user remotely.
*
* Copied from the register() function auth.php
*/
public function createUser($login, $pass, $fullname, $email) {
global $lang;
global $conf;
/* @var DokuWiki_Auth_Plugin $auth */
global $auth;

// gather input
$login = trim($auth->cleanUser($login));
$fullname = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $fullname));
$email = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $email));
$pass = $pass;

if(empty($login) || empty($fullname) || empty($email)) {
return new IJR_Error(-32602, 'Empty login / fullname / email');
}

//check mail
if(!mail_isvalid($email)) {
return new IJR_Error(-32602, 'Invalid E-mail');
}

//okay try to create the user
if(!$auth->triggerUserMod('create', array($login, $pass, $fullname, $email))) {
return new IJR_Error(-32099, 'Error creating user');
}

// send notification about the new user
$subscription = new Subscription();
$subscription->send_register($login, $fullname, $email);

// are we done?
return 1;
}
}

$server = new dokuwiki_jsonrpc_server();