Skip to content

Commit

Permalink
Adding missing dbauth.xql and setting version to 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsah committed May 24, 2018
1 parent 7597c01 commit d4baf9a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions expath-pkg.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://expath.org/ns/pkg" name="http://gawati.org/client-data" abbrev="gawati-client-data" version="1.6" spec="1.0">
<package xmlns="http://expath.org/ns/pkg" name="http://gawati.org/client-data" abbrev="gawati-client-data" version="1.7" spec="1.0">
<title>Client Data</title>
<dependency package="http://exist-db.org/apps/shared"/>
</package>
</package>
45 changes: 45 additions & 0 deletions modules/dbauth.xql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module namespace dbauth="http://gawati.org/1.0/client/dbauth";

declare namespace xmldb="http://exist-db.org/xquery/xmldb";
import module namespace config="http://gawati.org/client-data/config" at "./config.xqm";

(:
: This module provides 2 functions to enable writing to the database. Default
: eXist-db execution context is "guest", cannot write to the db using "guest".
: call dbauth:login() before calling a statement that writes a document to the db.
: after that call dbauth:logout() to change execution context back to guest
:
:)



(:
: Logs in to the writable collection as specified in config:storage-info()
:
:)
declare function dbauth:login() {
let $s-map := config:storage-info()
return dbauth:login($s-map)
};

(:
: Logs in to the writable collection as specified in the passed storage map
:
:)
declare function dbauth:login($s-map) {
let $log-in := xmldb:login($s-map("db-path"), $s-map("user"), $s-map("pw"))
return $log-in
};


declare function dbauth:logout() {
let $s-map := config:storage-info()
let $logout := dbauth:logout($s-map)
return $logout
};

declare function dbauth:logout($s-map) {
let $log-in := xmldb:login($s-map("db-path"), "guest", "guest")
let $logout:=session:invalidate()
return $logout
};

0 comments on commit d4baf9a

Please sign in to comment.