-
Notifications
You must be signed in to change notification settings - Fork 2
/
controller.xql
executable file
·92 lines (87 loc) · 3.19 KB
/
controller.xql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
xquery version "3.1";
import module namespace login="http://exist-db.org/xquery/login"
at "resource:org/exist/xquery/modules/persistentlogin/login.xql";
declare variable $exist:path external;
declare variable $exist:resource external;
declare variable $exist:controller external;
declare variable $exist:prefix external;
declare variable $exist:root external;
declare variable $exist:context external;
declare variable $local:login-domain := "org.exist.login";
declare function local:user-allowed ($user) as xs:boolean {
not(empty($user)) and $user ne "guest"
};
let $login := login:set-user($local:login-domain, (), false())
let $user := request:get-attribute($local:login-domain || ".user")
return (
util:log('info', $exist:path),
if ($exist:path eq '')
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
)
else if ($exist:path eq "/login")
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/login.html">
<cache-control cache="no"/>
<set-header name="Cache-Control" value="no-cache"/>
</forward>
</dispatch>
)
else if ($exist:path eq "/logout")
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="/exist/{$exist:prefix}/{$exist:controller}/?logout=true">
<cache-control cache="no"/>
<set-header name="Cache-Control" value="no-cache"/>
</redirect>
</dispatch>
)
(: from this point you need to be logged in :)
else if (not(local:user-allowed($user)))
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="/exist/{$exist:prefix}/{$exist:controller}/login">
<cache-control cache="no"/>
<set-header name="Cache-Control" value="no-cache"/>
</redirect>
</dispatch>
)
else if ($exist:path eq "/")
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/index.html"/>
</dispatch>
)
else if ($exist:path eq "/documents/")
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/list-image-links.xq"/>
</dispatch>
)
else if ($exist:path eq "/labels/")
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/get-labels.xq"/>
</dispatch>
)
else if ($exist:path eq "/annotator/")
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/annotator.html"/>
</dispatch>
)
else if (starts-with($exist:path, "/api/"))
then (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/../web-annotation-service/modules/route.xq"/>
</dispatch>
)
else (
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<cache-control cache="yes"/>
</dispatch>
)
)