From 5230cd11589d6dfc5c4c2a2e89709d43913f91ef Mon Sep 17 00:00:00 2001 From: duncdrum Date: Thu, 5 Dec 2019 21:25:01 +0100 Subject: [PATCH 01/10] add mysec prompt --- generators/app/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generators/app/index.js b/generators/app/index.js index 80e4101f..b331bd49 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -130,6 +130,16 @@ module.exports = class extends Generator { // message: 'How would you like to build your app?', // default: 'ant' // }, + { + when: response => { + return response.apptype[1] === 'application' + }, + type: 'confirm', + name: 'mysec', + message: 'should your app have a secure area?', + default: false, + store: true + }, // Path related { From 04355d4ca55efe3eb7bef8fe69eed05b7c7db476 Mon Sep 17 00:00:00 2001 From: duncdrum Date: Thu, 5 Dec 2019 22:53:36 +0100 Subject: [PATCH 02/10] feat(mysec): add mysec app files --- generators/app/templates/app.xql | 42 ++++++++++ generators/app/templates/config.xqm | 5 ++ .../app/templates/mysec/admin/controller.xql | 77 +++++++++++++++++ .../app/templates/mysec/admin/index.html | 17 ++++ .../app/templates/mysec/admin/security.html | 18 ++++ .../mysec/templates/login-panel.html | 38 +++++++++ .../app/templates/mysec/templates/page.html | 82 +++++++++++++++++++ 7 files changed, 279 insertions(+) create mode 100644 generators/app/templates/mysec/admin/controller.xql create mode 100644 generators/app/templates/mysec/admin/index.html create mode 100644 generators/app/templates/mysec/admin/security.html create mode 100644 generators/app/templates/mysec/templates/login-panel.html create mode 100644 generators/app/templates/mysec/templates/page.html diff --git a/generators/app/templates/app.xql b/generators/app/templates/app.xql index 626e6583..874e8f3d 100755 --- a/generators/app/templates/app.xql +++ b/generators/app/templates/app.xql @@ -28,3 +28,45 @@ declare function app:foo($node as node(), $model as map(*)) {

Dummy templating function.

}; + <%_ if (mysec == true) { %> +declare function app:test($node as node(), $model as map(*)) { +

Dummy template output generated by function app:test at {current-dateTime()}. The templating + function was triggered by the class attribute class="app:test".

+}; + +declare function app:if-attribute-set($node as node(), $model as map(*), $attribute as xs:string) { + let $isSet := + (exists($attribute) and request:get-attribute($attribute)) + return + if ($isSet) then + templates:process($node/node(), $model) + else + () +}; + +declare function app:if-attribute-unset($node as node(), $model as map(*), $attribute as xs:string) { + let $isSet := + (exists($attribute) and request:get-attribute($attribute)) + return + if (not($isSet)) then + templates:process($node/node(), $model) + else + () +}; + +declare function app:username($node as node(), $model as map(*)) { + let $user:= request:get-attribute("org.exist-db.mysec.user") + let $name := if ($user) then sm:get-account-metadata($user, xs:anyURI('http://axschema.org/namePerson')) else 'Guest' + return if ($name) then $name else $user +}; + +declare + %templates:wrap +function app:userinfo($node as node(), $model as map(*)) as map(*) { + let $user:= request:get-attribute("org.exist-db.mysec.user") + let $name := if ($user) then sm:get-account-metadata($user, xs:anyURI('http://axschema.org/namePerson')) else 'Guest' + let $group := if ($user) then sm:get-user-groups($user) else 'guest' + return + map { "user-id" : $user, "user-name" : $name, "user-groups" : $group} +}; +<% } %> diff --git a/generators/app/templates/config.xqm b/generators/app/templates/config.xqm index 001fea7f..0cc22ba6 100755 --- a/generators/app/templates/config.xqm +++ b/generators/app/templates/config.xqm @@ -4,7 +4,12 @@ xquery version "3.1"; : A set of helper functions to access the application context from : within a module. :) + (: TODO: module namespace seems preconfigured :) +(: module namespace config="<%- defuri %>/<%- defcoll %>/<%- short %>/config"; :) + declare namespace templates="http://exist-db.org/xquery/templates"; + declare namespace repo="http://exist-db.org/xquery/repo"; + declare namespace expath="http://expath.org/ns/pkg"; (: Determine the application root collection from the current module load path. :) diff --git a/generators/app/templates/mysec/admin/controller.xql b/generators/app/templates/mysec/admin/controller.xql new file mode 100644 index 00000000..e16d2b05 --- /dev/null +++ b/generators/app/templates/mysec/admin/controller.xql @@ -0,0 +1,77 @@ +xquery version "3.0"; + +import module namespace login="http://exist-db.org/xquery/login" at "resource:org/exist/xquery/modules/persistentlogin/login.xql"; +import module namespace functx="http://www.functx.com"; + +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 $local:login_domain := "org.exist-db.mysec"; +declare variable $local:user := $local:login_domain || '.user'; + +let $logout := request:get-parameter("logout", ()) +let $set-user := login:set-user($local:login_domain, (), false()) +return +if ($exist:path eq '') then + + + + +else if (($exist:path eq "/") or ($logout)) then + + + + +else if (ends-with($exist:resource, ".html")) then + if (request:get-attribute("org.exist-db.mysec.user")) then + (: the html page is run through view.xql to expand templates :) + + + + + + + + + + + + + + else + + + + + + + + + + + + + + + +(: Resource paths starting with $shared are loaded from the shared-resources app :) +else if (contains($exist:path, "/$shared/")) then + + + + + +else if (starts-with($exist:path, "/resources")) then + (: images, css are contained in the top /resources/ collection. :) + (: Relative path requests from sub-collections are redirected there :) + + + +else + (: everything else is passed through :) + + + diff --git a/generators/app/templates/mysec/admin/index.html b/generators/app/templates/mysec/admin/index.html new file mode 100644 index 00000000..8d7ad4e7 --- /dev/null +++ b/generators/app/templates/mysec/admin/index.html @@ -0,0 +1,17 @@ + +
+
+
+ +
+

The page template uses the Bootstrap CSS library for the page layout.

+
+
+
+

Application Info

+
+
+
+
\ No newline at end of file diff --git a/generators/app/templates/mysec/admin/security.html b/generators/app/templates/mysec/admin/security.html new file mode 100644 index 00000000..8d4c5c2d --- /dev/null +++ b/generators/app/templates/mysec/admin/security.html @@ -0,0 +1,18 @@ + +
+
+
+ +
+

This is a protected page. You must be logged in as a user with the appropriate + privileges.

+
+
+
+

Application Info

+
+
+
+
diff --git a/generators/app/templates/mysec/templates/login-panel.html b/generators/app/templates/mysec/templates/login-panel.html new file mode 100644 index 00000000..12910bd3 --- /dev/null +++ b/generators/app/templates/mysec/templates/login-panel.html @@ -0,0 +1,38 @@ + + diff --git a/generators/app/templates/mysec/templates/page.html b/generators/app/templates/mysec/templates/page.html new file mode 100644 index 00000000..860a1331 --- /dev/null +++ b/generators/app/templates/mysec/templates/page.html @@ -0,0 +1,82 @@ + + + + <%- title %> + + + + + +