Skip to content
This repository
Newer
Older
100644 116 lines (94 sloc) 4.237 kb
bd44a839 » eedeebee
2012-02-21 Support for processing (validating, recording, and redirecting) the l…
1 xquery version "1.0-ml";
2
3 import module namespace json="http://marklogic.com/json" at "/lib/mljson/lib/json.xqy";
4 import module namespace path="http://marklogic.com/mljson/path-parser" at "/lib/mljson/lib/path-parser.xqy";
5 import module namespace users="users" at "/lib/users.xqy";
6 import module namespace util="http://markmail.org/util" at "/lib/util.xqy";
7 import module namespace param="http://marklogic.com/rundmc/params" at "modules/params.xqy";
8
9
10 let $orig-url := xdmp:get-request-url()
11 let $query-string := substring-after($orig-url, '?')
12 let $valid-url := xdmp:get-request-field("r")
13 let $invalid-url := "/license/default.xqy"
14
15 let $params := for $p in param:params()
16 where not($p/@name/string() = ("r", "password", "password_conf"))
17 return concat($p/@name/string(), "=", xdmp:url-encode($p/string()))
18
19 let $string-params := string-join($params, "&")
20
9758e9af » eedeebee
2012-02-21 Updates to license/signup stuff.
21 let $version := xdmp:get-request-field("version")
bd44a839 » eedeebee
2012-02-21 Support for processing (validating, recording, and redirecting) the l…
22 let $name := xdmp:get-request-field("name")
23 let $email := xdmp:get-request-field("email")
24 let $passwd := xdmp:get-request-field("password")
25 let $signup := xdmp:get-request-field("signup") eq "1"
26 let $type := xdmp:get-request-field("type")
27
28 let $cpus := xdmp:get-request-field("cpus")
29 let $platform := xdmp:get-request-field("platform")
30 let $hostname := xdmp:get-request-field("hostname")
31 let $target := xdmp:get-request-field("target")
32
33 let $company := xdmp:get-request-field("company")
34 let $school := xdmp:get-request-field("school")
35 let $yog := xdmp:get-request-field("yog")
36
37
38 let $valid-url := fn:concat($valid-url, "?",
9758e9af » eedeebee
2012-02-21 Updates to license/signup stuff.
39 "version=", xdmp:url-encode($version),
40 "&hostname=", xdmp:url-encode($hostname),
bd44a839 » eedeebee
2012-02-21 Support for processing (validating, recording, and redirecting) the l…
41 "&cpus=", xdmp:url-encode($cpus),
42 "&platform=", xdmp:url-encode($platform),
43 "&target=", xdmp:url-encode($target),
44 "&type=", xdmp:url-encode($type),
45 "&company=", xdmp:url-encode(if ($type eq "express") then $company else $school),
46 "&email=", xdmp:url-encode($email))
47
48 let $invalid-url := fn:concat($invalid-url, "?", $string-params, "&retrying=1")
49
50 let $valid-type := if ($type eq 'express') then
51 xdmp:get-request-field("company")
52 else
53 xdmp:get-request-field("yog") and xdmp:get-request-field("school")
54
55 let $valid :=
56 if ($signup) then
57 $name and $email and $passwd and ($passwd eq xdmp:get-request-field("password_conf"))
58 and util:validateEmail($email)
59 and not(users:emailInUse($email))
60 and $valid-type
61 else
62 $email and
63 $passwd and
64 users:checkCreds($email, $passwd) and
65 $valid-type
66
67 let $error := if ($signup) then
68 if (users:emailInUse($email)) then
69 "&inuse=1"
70 else
71 if ($passwd ne xdmp:get-request-field("password_conf")) then
72 "&nonmatching=1"
73 else
74 ""
75 else
76 if (not(users:checkCreds($email, $passwd))) then
77 "&badpassword=1"
78 else
79 ""
80
81 let $invalid-url := concat($invalid-url, $error)
82
83 let $meta := (
84 <cpus>{$cpus}</cpus>,
85 <platform>{$platform}</platform>,
86 <hostname>{$hostname}</hostname>
87 )
88
89 let $name := if ($valid) then
90 if ($signup) then
91 let $list := xdmp:get-request-field("dev-list")
92 let $mktg-list := xdmp:get-request-field("mktg-list")
93
94 return
95 users:createUserAndRecordLicense($name, $email, $passwd, $list, $mktg-list, $company, $school, $yog, $meta)/name/string()
96 else
97 if ($type eq 'express') then
98 users:recordExpressLicense($email, $company, $meta)/name/string()
99 else
100 users:recordAcademicLicense($email, $school, $yog, $meta)/name/string()
101 else
102 $name
103
9758e9af » eedeebee
2012-02-21 Updates to license/signup stuff.
104 let $hash := doc("/private/license-hash.xml")/hash/string()
72c4cf56 » eedeebee
2012-02-22 Use rnumber along with hash
105 let $rnumber := doc("/private/license-hash.xml")/id/string()
9758e9af » eedeebee
2012-02-21 Updates to license/signup stuff.
106
107 let $valid-url := concat($valid-url,
108 "&amp;licensee=", xdmp:url-encode($name),
109 "&amp;hash=", xdmp:url-encode($hash),
72c4cf56 » eedeebee
2012-02-22 Use rnumber along with hash
110 "&amp;rnumber=", xdmp:url-encode($rnumber),
9758e9af » eedeebee
2012-02-21 Updates to license/signup stuff.
111 "")
bd44a839 » eedeebee
2012-02-21 Support for processing (validating, recording, and redirecting) the l…
112
113 let $_ := xdmp:log($valid-url)
114
115 return
116 xdmp:redirect-response(if ($valid) then $valid-url else $invalid-url)
Something went wrong with that request. Please try again.