diff --git a/IJR_CallbackDefines.php b/IJR_CallbackDefines.php index 05e168d..f411eec 100644 --- a/IJR_CallbackDefines.php +++ b/IJR_CallbackDefines.php @@ -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'); diff --git a/jsonrpc.php b/jsonrpc.php index ee83012..50666eb 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -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); } @@ -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(); \ No newline at end of file