]> git.andy128k.dev Git - ipf.git/commitdiff
refactor: move authAdmin into static class
authoravl <alex.litovchenko@gmail.com>
Fri, 28 Nov 2008 14:28:53 +0000 (16:28 +0200)
committeravl <alex.litovchenko@gmail.com>
Fri, 28 Nov 2008 14:28:53 +0000 (16:28 +0200)
ipf/admin/app.php
ipf/admin/views.php

index ba5a905b9dabe8d5770f5a40bbe6f4dd4a743484..94c75a8698fecd5431b2f6521d42d3c6233e0b37 100644 (file)
@@ -18,4 +18,18 @@ class IPF_Admin_App extends IPF_Application{
             array('regex'=>'logout/$#i', 'func'=>'IPF_Admin_Views_Logout'),
         );
     }
+
+       static function checkAdminAuth($request){
+           $ok = true;
+           if ($request->user->isAnonymous())
+               $ok = false;
+           elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
+               $ok = false;
+
+           if ($ok)
+               return true;
+           else
+               return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
+       }
+
 }
\ No newline at end of file
index 9d1d72f3899f83fbc3762ba63d23708ffa31433c..331eaa79b24a5bf098b6f4bee14749d281cca7f5 100644 (file)
@@ -1,20 +1,7 @@
 <?php
 
-function checkAdminAuth($request){
-    $ok = true;
-    if ($request->user->isAnonymous())
-        $ok = false;
-    elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
-        $ok = false;
-
-    if ($ok)
-        return true;
-    else
-        return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
-}
-
 function IPF_Admin_Views_Index($request, $match){
-    $ca = checkAdminAuth($request);
+    $ca = IPF_Admin_App::checkAdminAuth($request);
     if ($ca!==true) return $ca;
 
     $apps = array();
@@ -66,7 +53,7 @@ function IPF_Admin_Views_Index($request, $match){
 }
 
 function IPF_Admin_Views_ListItems($request, $match){
-    $ca = checkAdminAuth($request);
+    $ca = IPF_Admin_App::checkAdminAuth($request);
     if ($ca!==true) return $ca;
 
     $lmodel = $match[2];
@@ -83,7 +70,7 @@ function IPF_Admin_Views_ListItems($request, $match){
 }
 
 function IPF_Admin_Views_EditItem($request, $match){
-    $ca = checkAdminAuth($request);
+    $ca = IPF_Admin_App::checkAdminAuth($request);
     if ($ca!==true) return $ca;
 
     $lapp = $match[1];
@@ -104,7 +91,7 @@ function IPF_Admin_Views_EditItem($request, $match){
 }
 
 function IPF_Admin_Views_DeleteItem($request, $match){
-    $ca = checkAdminAuth($request);
+    $ca = IPF_Admin_App::checkAdminAuth($request);
     if ($ca!==true) return $ca;
 
     $lapp = $match[1];
@@ -126,7 +113,7 @@ function IPF_Admin_Views_DeleteItem($request, $match){
 
 
 function IPF_Admin_Views_AddItem($request, $match){
-    $ca = checkAdminAuth($request);
+    $ca = IPF_Admin_App::checkAdminAuth($request);
     if ($ca!==true) return $ca;
 
     $lapp = $match[1];
@@ -144,7 +131,7 @@ function IPF_Admin_Views_AddItem($request, $match){
 }
 
 function IPF_Admin_Views_ChangePassword($request, $match){
-    $ca = checkAdminAuth($request);
+    $ca = IPF_Admin_App::checkAdminAuth($request);
     if ($ca!==true) return $ca;
 
     $lapp = 'auth';