home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / sample.js < prev    next >
Encoding:
Text File  |  2004-07-12  |  2.1 KB  |  84 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. cocoon.load("resource://org/apache/cocoon/webapps/authentication/flow/javascript/auth.js");
  17.  
  18. function isLoggedIn() {
  19.   var handler = cocoon.parameters["handler"];
  20.  
  21.   if (auth_isAuthenticated(handler)) {
  22.     success();
  23.   } else {
  24.     failure();
  25.   }
  26. }
  27.  
  28. function protect() {
  29.   var handler = cocoon.parameters["handler"];
  30.  
  31.   if (auth_checkAuthentication(handler,"")) {
  32.     success();
  33.   } else {
  34.     // already redirected by auth_checkAuthentication
  35.   }
  36. }
  37.  
  38. function login() {
  39.   var handler = cocoon.parameters["handler"];
  40.  
  41.   if (auth_isAuthenticated(handler)) {
  42.     success();
  43.   } else if (auth_login(handler, null, cocoon.parameters)) {
  44.     success();
  45.   } else {
  46.     failure();
  47.   }
  48. }
  49.  
  50. function logout() {
  51.   var handler = cocoon.parameters["handler"];
  52.  
  53.   auth_logout(handler);
  54.   failure();
  55. }
  56.  
  57. function success() {
  58.   var internal = cocoon.parameters["protected-internal"];
  59.   var redirect = cocoon.parameters["protected-redirect"];
  60.   
  61.   if (internal != null) {
  62.     cocoon.sendPage(internal);
  63.   } else if (redirect != null) {
  64.     cocoon.redirectTo(redirect);
  65.   } else {
  66.     throw new Error("No protected redirection parameter given");
  67.   }
  68. }
  69.  
  70. function failure() {
  71.  
  72.   var internal = cocoon.parameters["failure-internal"];
  73.   var redirect = cocoon.parameters["failure-redirect"];  
  74.  
  75.   if (internal != null) {
  76.     cocoon.sendPage(internal);
  77.   } else if (redirect != null) {
  78.     cocoon.redirectTo(redirect);
  79.   } else {
  80.     // Why does this throw cause an error?
  81.     throw new Error("No failure redirection parameter given");
  82.   }
  83. }
  84.