phpUserTrack
[ class tree: phpUserTrack ] [ index: phpUserTrack ] [ all elements ]

Source for file liblogin.php

Documentation is available at liblogin.php

  1. <?php
  2.  
  3. require_once('libdb.php');
  4.  
  5. define("ADMIN_NAME""Admin");
  6. define("GUEST_NAME""Guest");
  7. define("ADMIN_LEVEL"9);
  8. define("USER_LEVEL",  1);
  9. define("GUEST_LEVEL"0);
  10.  
  11. class LoginException extends Exception {
  12.     
  13.     function __construct($message null$code 0{
  14.         parent::__construct($message$code);
  15.     }
  16.     
  17. }
  18.  
  19. class login extends phpusertrack_db {
  20.     
  21.     private $_username;     //Username given on sign-up
  22.     private $_uid;       //Random value generated on current login
  23.     private $_userlevel GUEST_LEVEL;    //The level to which the user pertains
  24.     private $_isLoggedIn false;    //True if user is logged in, false otherwise
  25.     private $_userinfo array();  //The array holding all user info
  26.     
  27.     function login($checkLogin false{
  28.         global $conf;
  29.         global $smarty;
  30.         
  31.         if (isset($_SESSION['uid'])) {
  32.             $sql 'select * from phpusertrack_users where id=\'' $_SESSION['uid''\'';
  33.             $dat $this->_query($sql);
  34.             $this->_username $dat[0]['username'];
  35.             $this->_uid $dat[0]['id'];
  36.             $this->_userlevel $dat[0]['userlevel'];
  37.             $_SESSION['uid'$this->_uid;
  38.             $this->_isLoggedIn true;
  39.             $smarty->assign('userlevel'$this->_userlevel);
  40.         else if ($conf['allowanonymous']{
  41.             $this->_username GUEST_NAME;
  42.             $this->_isLoggedIn true;
  43.             $smarty->assign('userlevel'$this->_userlevel);
  44.         else {
  45.             $this->_isLoggedIn false;
  46.         }
  47.         
  48.         if ($checkLogin{
  49.             $this->checkLogin();
  50.         }
  51.     }
  52.     
  53.     function checkLogin({
  54.         if (!$this->_isLoggedIn{
  55.             throw new LoginException();
  56.         }
  57.     }
  58.     
  59.     function submit_login($username$password{
  60.         try {
  61.             $sql 'select * from phpusertrack_users where username=\'' $username '\' and password=\'' md5($password'\' limit 1';
  62.             $dat $this->_query($sql);
  63.             if (count($dat0{
  64.                 $this->_username $dat[0]['username'];
  65.                 $this->_uid $dat[0]['id'];
  66.                 $this->_isLoggedIn true;
  67.                 $this->_userlevel $dat[0]['userlevel'];
  68.                 $_SESSION['uid'$this->_uid;
  69.             }
  70.             return $this->isLoggedIn();
  71.         catch (Exception $e{
  72.             throw new Exception($this->_db->toString());
  73.         }
  74.     }
  75.     
  76.     function isLoggedIn({
  77.         return $this->_isLoggedIn;
  78.     }
  79.     
  80.     function isGuest({
  81.         if ($this->_userlevel == GUEST_LEVEL{
  82.             return true;
  83.         else {
  84.             return false;
  85.         }
  86.     }
  87.     
  88. }
  89.  
  90. /* class login extends phpusertrack_db {
  91.     
  92.     private $_username;     //Username given on sign-up
  93.     private $_uid;       //Random value generated on current login
  94.     private $_userlevel = GUEST_LEVEL;    //The level to which the user pertains
  95.     private $_isLoggedIn = false;    //True if user is logged in, false otherwise
  96.     private $_userinfo = array();  //The array holding all user info
  97.     
  98.     function login() {
  99.         global $conf;
  100.         
  101.         $this->_isLoggedIn = $this->checkLogin();
  102.         die;
  103.  
  104.           if(!$this->_isLoggedIn){
  105.               if ($conf['allowanonymous']) {
  106.                 $this->_isLoggedIn = true;
  107.                 $this->_userlevel = 0;
  108.                 return true;
  109.               } else {
  110.                   $this->_isLoggedIn = false;
  111.                 return false;
  112.               }
  113.         }
  114.         return true;
  115.     }
  116.     
  117.     function checkLogin(){
  118.         global $smarty;
  119.         if (isset($_SESSION['uid'])) {
  120.             try {
  121.                 $this->_connect();
  122.                 $sql = 'select * from phpusertrack_users where id=\'' . $_SESSION['uid'] . '\'';
  123.                 $dat = $this->_query($sql);
  124.                 $this->_username = $dat[0]['username'];
  125.                 $this->_uid = $dat[0]['id'];
  126.                 $this->_isLoggedIn = true;
  127.                 $this->_userlevel = $dat[0]['userlevel'];
  128.                 $_SESSION['uid'] = $this->_uid;
  129.             } catch (Exception $e) {
  130.                 throw new LoginException($this->_db->toString());
  131.             }
  132.         } else if (!$conf['allowanonymous']) {
  133.             throw new LoginException();
  134.         }
  135.         $smarty->assign('userlevel', $this->_userlevel);
  136.         return $this->isLoggedIn();
  137.     }
  138.     
  139.     function isLoggedIn() {
  140.         return $this->_isLoggedIn;
  141.     }
  142.     
  143.     function isGuest() {
  144.         if ($this->_userlevel == 0) {
  145.             return true;
  146.         } else {
  147.             return false;
  148.         }
  149.     }
  150.     
  151.     function submit_login($username, $password) {
  152.         try {
  153.             $this->_connect();
  154.             $sql = 'select * from phpusertrack_users where username=\'' . $username . '\' and password=\'' . md5($password) . '\' limit 1';
  155.             $dat = $this->_query($sql);
  156.             if (count($dat) > 0) {
  157.                 $this->_username = $dat[0]['username'];
  158.                 $this->_uid = $dat[0]['id'];
  159.                 $this->_isLoggedIn = true;
  160.                 $this->_userlevel = $dat[0]['userlevel'];
  161.                 $_SESSION['uid'] = $this->_uid;
  162.             }
  163.             return $this->isLoggedIn();
  164.         } catch (Exception $e) {
  165.             throw new Exception($this->_db->toString());
  166.         }
  167.     }
  168.     
  169. } */
  170.  
  171. ?>

Documentation generated on Tue, 06 Nov 2007 09:22:04 -0800 by phpDocumentor 1.4.0a2