Jeff PHP framework  0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
authentication.class.php
Go to the documentation of this file.
00001 <?php
00021 class authentication {
00022 
00034         public static function check() {
00035 
00036                 $registry = registry::instance();
00037 
00038                 if(isset($_GET['login'])) {
00039 
00040                         $redirect = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : $registry->router->linkHref(null, null);
00041 
00042                         if(($username = cleanInput('post', 'user', 'string')) && ($password = cleanInput('post', 'password', 'string'))) {
00043                                 $user = user::getFromAuth($username, $password);        
00044                                 if(self::checkUser($user)) {
00045                                         $_SESSION['userid'] = $user->id;
00046                                         header('Location: '.$redirect);
00047                                         exit;
00048                                 }
00049                         }       
00050                         
00051                         Error::errorMessage(array("error"=>__("authError")), $redirect);
00052                 }
00053                 elseif(isset($_GET['logout'])) {
00054                         unset($_SESSION);
00055                         session_destroy();
00056                         header('Location: '.$registry->router->linkHref(null, null));
00057                         exit();
00058                 }
00059                 else {
00060                         $registry->user = null;
00061                         $registry->admin = false;
00062 
00063                         if(isset($_SESSION['userid'])) {
00064                                 $registry->user = new user($_SESSION['userid']);
00065                                 if(access::check('main', $registry->admin_privilege)) {
00066                                         $registry->admin = true;
00067                                 }
00068                         }
00069                         else {
00070                                 $registry->user = new StdClass();
00071                                 $registry->user->groups = 5;
00072                                 $registry->user->id = 0;
00073                         }
00074                 }
00075 
00076 
00077         }
00078 
00087         public static function checkUser($user) {
00088 
00089                 $registry = registry::instance();
00090 
00091                 if(!$user) return false;
00092 
00093                 $registry->user = $user;
00094                 if( ($user && $registry->site=='main') || 
00095                     ($registry->site=='admin' && access::check($registry, 'main', $registry->admin_view_privilege))) 
00096                     return true;
00097 
00098                 return false;
00099         }
00100 
00101 }
00102 
00103 ?>