import Control.Monad.Trans
import Data.Maybe
import Network.HTTP.Lucu
-import Network.URI hiding (path)
import Rakka.Authorization
import Rakka.Environment
import Rakka.Resource
-import Rakka.SystemConfig
-import System.FilePath
import Text.XML.HXT.Arrow hiding (when)
{-
[GET /users]
- <rdf:RDF>
- <rdf:Description rdf:about="http://.../users">
- <users>
- <rdf:Bag>
- <rdf:li rdf:resource="http://.../users/foo" />
- <rdf:li rdf:resource="http://.../users/bar" />
- ...
- </rdf:Bag>
- </users>
- </rdf:Description>
- </rdf:RDF>
+ <users>
+ <user id="foo" />
+ <user id="bar" />
+ ...
+ </users>
[GET /users/foo]
204 No Content
where
returnUserList :: Resource ()
returnUserList
- = do BaseURI baseURI <- getSysConf (envSysConf env)
- users <- liftIO $ getUserList $ envAuthDB env
+ = do users <- liftIO $ getUserList $ envAuthDB env
runIdempotentA' $ proc ()
-> do tree <- ( eelem "/"
- += ( eelem "rdf:RDF"
- += sattr "xmlns" "http://cielonegro.org/terms/"
- += sattr "xmlns:rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- += ( eelem "rdf:Description"
- += sattr "rdf:about" (uriToString id (mkUserURI baseURI Nothing) "")
- += ( eelem "users"
- += ( eelem "rdf:Bag"
- += ( constL users
- >>>
- ( eelem "rdf:li"
- += attr "rdf:resource" ( arr ( \ name ->
- uriToString
- id
- (mkUserURI baseURI $ Just name)
- ""
- )
- >>>
- mkText
- )
- )
- )
- )
- )
+ += ( eelem "users"
+ += ( constL users
+ >>>
+ ( eelem "user"
+ += attr "id" mkText
+ )
)
)
) -< ()
returnA -< outputXml tree
- mkUserURI :: URI -> Maybe String -> URI
- mkUserURI baseURI Nothing = baseURI { uriPath = uriPath baseURI </> "users" }
- mkUserURI baseURI (Just x) = baseURI { uriPath = uriPath baseURI </> "users" </> x }
-
returnUser :: String -> Resource ()
returnUser name
= do users <- liftIO $ getUserList $ envAuthDB env
(function () {
- var identityDecoder = function (src) {
- return src;
- };
+ var identityDecoder = function (src) {
+ return src;
+ };
- var identityEncoder = function (src) {
- return src;
- };
+ var identityEncoder = function (src) {
+ return src;
+ };
- var mapDecoder = function (src) {
- var map = {};
- var lines = src.split(/\n/);
+ var mapDecoder = function (src) {
+ var map = {};
+ var lines = src.split(/\n/);
- $.each(lines, function () {
- var m = this.match(/^(\S+)\s+(\S+)$/);
+ $.each(lines, function () {
+ var m = this.match(/^(\S+)\s+(\S+)$/);
- map[ m[1] ] = m[2];
- });
+ map[ m[1] ] = m[2];
+ });
- return map;
- };
+ return map;
+ };
- var mapEncoder = function (map) {
- var lines = [];
+ var mapEncoder = function (map) {
+ var lines = [];
- $.each(map, function (key) {
- lines.push(key + " " + this);
- });
+ $.each(map, function (key) {
+ lines.push(key + " " + this);
+ });
- return lines.join("\n");
- };
+ return lines.join("\n");
+ };
- var boolDecoder = function (src) {
- return src == "*";
- };
+ var boolDecoder = function (src) {
+ return src == "*";
+ };
- var boolEncoder = function (bool) {
- return bool ? "*" : "";
- };
+ var boolEncoder = function (bool) {
+ return bool ? "*" : "";
+ };
- var decoder_of = {
- siteName : identityDecoder,
- baseURI : identityDecoder,
- defaultPage: identityDecoder,
- styleSheet : identityDecoder,
- languages : mapDecoder,
- globalLock : boolDecoder
- };
+ var decoder_of = {
+ siteName : identityDecoder,
+ baseURI : identityDecoder,
+ defaultPage: identityDecoder,
+ styleSheet : identityDecoder,
+ languages : mapDecoder,
+ globalLock : boolDecoder
+ };
- var encoder_of = {
- siteName : identityEncoder,
- baseURI : identityEncoder,
- defaultPage: identityEncoder,
- styleSheet : identityEncoder,
- languages : mapEncoder,
- globalLock : boolEncoder
- };
+ var encoder_of = {
+ siteName : identityEncoder,
+ baseURI : identityEncoder,
+ defaultPage: identityEncoder,
+ styleSheet : identityEncoder,
+ languages : mapEncoder,
+ globalLock : boolEncoder
+ };
- var cachedConf = null;
+ var cachedConf = null;
- var isValidBaseURI = function (str) {
- parseUri.options.strictMode = true;
- var uri = parseUri(str);
+ var isValidBaseURI = function (str) {
+ parseUri.options.strictMode = true;
+ var uri = parseUri(str);
- return (uri.protocol != "" &&
- uri.authority != "" &&
- uri.path != "" &&
- uri.path.match(/\/$/) &&
- uri.query == "" &&
- uri.anchor == "");
- };
+ return (uri.protocol != "" &&
+ uri.authority != "" &&
+ uri.path != "" &&
+ uri.path.match(/\/$/) &&
+ uri.query == "" &&
+ uri.anchor == "");
+ };
- var isValidMap = function (src) {
- return src.match(/^\S+\s+\S+(?:\n\S+\s+\S+)*\n?$/) != null;
- };
+ var isValidMap = function (src) {
+ return src.match(/^\S+\s+\S+(?:\n\S+\s+\S+)*\n?$/) != null;
+ };
+
+ Rakka.getUserList = function () {
+ var users = [];
+
+ $.ajax({
+ type: "GET",
+ url: Rakka.baseURI + "users",
+ async: false,
+ beforeSend: function (req) {
+ Rakka.setAuthorization(req);
+ },
+ success: function (xml) {
+ $(xml).find("user").each(function () {
+ users.push(this.getAttribute("id"));
+ });
+ },
+ error: function (req) {
+ throw new Error(req.status + " " + req.statusText);
+ }
+ });
+
+ return users;
+ };
Rakka.getSystemConfig = function () {
if (cachedConf != null) {
return conf;
};
- Rakka.showConfigPanel = function () {
- var conf = Rakka.getSystemConfig();
- var $area = Rakka.switchScreen();
-
- $area.append($.H1({}, "Configuration"));
+ var appendConfigPanel = function ($area) {
+ var conf = Rakka.getSystemConfig();
+ $area.append($.H1({}, "Configuration"));
var fldSiteName
= $.INPUT({type: "text", value: conf.siteName});
$area.append(configPanel);
};
- $(document).ready(function () {
- $("input.configButton")
- .click(function () {
- Rakka.showConfigPanel();
- });
- });
+ var appendUsersPanel = function ($area) {
+ $area.append($.H2({}, "Users"));
+ $area.append($.H3({}, "Existing Users"));
+
+ var tbody = $.TBODY();
+
+ var usersPanel
+ = $.TABLE({className: "pageEditor"},
+ $.THEAD({},
+ $.TR({},
+ $.TH({}, "User ID"),
+ $.TH({}, "Change Password"),
+ $.TH({}, "Delete User")
+ )
+ ),
+ tbody
+ );
+
+ var updateUserList = function () {
+ var users = Rakka.getUserList();
+
+ $(tbody).empty();
+
+ $.each(users, function () {
+ var id = this;
+ var tr = $.TR({},
+ $.TD({}, id),
+ $.TD({}, ""),
+ $.TD({}, "")
+ );
+ tbody.appendChild(tr);
+ });
+ };
+ updateUserList();
+
+ $area.append(usersPanel);
+ };
+
+ Rakka.showConfigPanel = function () {
+ var $area = Rakka.switchScreen();
+
+ appendConfigPanel($area);
+ appendUsersPanel($area);
+ };
+ $(document).ready(function () {
+ $("input.configButton")
+ .click(function () {
+ Rakka.showConfigPanel();
+ });
+ });
})();
\ No newline at end of file