Reputation: 375
I'm not sure how does the Xquery works on the server. I know the syntax,but not sure how to implement it for my site.
For example. I have site that stored the username and password in XML file. Now I want to verify the username and password for log in or sign up.
How can I do this? Do I just write a Xquery file and upload to the server and then call it?
Upvotes: 0
Views: 134
Reputation: 2176
Please find below an example of a basic authentication module that runs on top of Sausalito.
module namespace auth = "[project logical uri]lib/auth";
import module namespace base64 = "http://www.zorba-xquery.com/modules/converters/base64";
import module namespace req = "http://www.28msec.com/modules/http/request";
import module namespace res = "http://www.28msec.com/modules/http/response";
declare variable $auth:login := "login";
declare variable $auth:password := "password";
declare function auth:authorize() as empty-sequence()
{
let $auth := "Basic " || string(base64:encode($html:login || ":" || $html:password)) eq req:header-value("Authorization")
return
if(not($auth) and not($unprotected)) then
error($res:unauthorized);
else
();
};
Upvotes: 1