跳转至内容

XQuery/URL 驱动授权

来自维基教科书,开放的书籍,开放的世界

您想在页面渲染之前检查用户是否已登录。

此示例将使用自定义控制器.xql 文件来实现这一点。


示例控制器.xql 文件

(:  Protected resource: user is required to log in with valid credentials.
   If the login fails or no credentials were provided, the request is
redirected
   to the login.xml page. :)
else if ($exist:resource eq 'protected.xml') then
   let $login := local:set-user()
   return
       if ($login) then
           <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
               {$login}
               <view>
                   <forward url="style.xql"/>
               </view>
           </dispatch>
       else
           <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
               <forward url="login.xml"/>
               <view>
                 <forward url="style.xql"/>
               </view>
           </dispatch>

else
   (: everything else is passed through :)
   <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
       <cache-control cache="yes"/>
   </dispatch>
华夏公益教科书