[ Index ]
 

Code source de Dotclear 1.2.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/inc/classes/ -> class.auth.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2004 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # DotClear is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  # 
  17  # You should have received a copy of the GNU General Public License
  18  # along with DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  class auth
  24  {
  25      var $con;
  26      var $failed_redirect;
  27      
  28  	function auth(&$con,$failed_redirect='auth.php')
  29      {
  30          $this->con = $con;
  31          $this->failed_redirect = $failed_redirect;
  32      }
  33      
  34  	function check($level)
  35      {
  36          $failed = true;
  37          
  38          if (empty($_SESSION['sess_user_id']))
  39          {
  40              if (!empty($_COOKIE['dc_admin']))
  41              {
  42                  $cookie = unserialize($_COOKIE['dc_admin']);
  43                  
  44                  $failed = !$this->perform($cookie['user_id'],
  45                              $cookie['user_pwd'],$level,false,$cookie['remember']);
  46                  
  47                  if (!$failed) {
  48                      $_SESSION['sess_user_id'] = $cookie['user_id'];
  49                  }
  50              }
  51              else
  52              {
  53                  $failed = true;
  54                  $_SESSION['sess_auth_from'] = $_SERVER['REQUEST_URI'];
  55              }
  56          }
  57          else
  58          {
  59              $blog = new blog($this->con,DB_PREFIX,NULL,dc_encoding);
  60                      
  61              $failed = !$blog->checkUser($_SESSION['sess_user_id'],NULL,$level);
  62              
  63              unset($blog);
  64          }
  65          
  66          if ($failed) {
  67              header('Location: '.$this->failed_redirect);
  68              exit;
  69          }
  70      }
  71      
  72  	function perform($user_id,$user_pwd,$level,$md5=true,$remember=false)
  73      {
  74          $blog = new blog($this->con,DB_PREFIX,NULL,dc_encoding);
  75          
  76          $res = false;
  77          
  78          if($blog->checkUser($user_id,$user_pwd,$level,$md5) !== false)
  79          {
  80              $rs = $blog->getUser($user_id);
  81              
  82              $_SESSION['sess_user_level'] = $rs->f('user_level');
  83              $_SESSION['sess_user_format']= $rs->f('user_post_format');
  84              $_SESSION['sess_user_nom'] = $rs->f('user_nom');
  85              $_SESSION['sess_user_prenom'] = $rs->f('user_prenom');
  86              $_SESSION['sess_user_pseudo'] = $rs->f('user_pseudo');
  87              $_SESSION['sess_user_email'] = $rs->f('user_email');
  88              $_SESSION['sess_user_edit_size'] = $rs->f('user_edit_size');
  89              $_SESSION['sess_user_pref_cat'] = (integer) $rs->f('user_pref_cat');
  90              $_SESSION['sess_user_lang'] = $rs->f('user_lang');
  91              $_SESSION['sess_user_delta'] = $rs->f('user_delta');
  92              $_SESSION['sess_user_post_pub'] = $rs->f('user_post_pub');
  93              
  94              if($_SESSION['sess_user_pseudo'] != '')
  95                  $_SESSION['sess_user_cn'] = $_SESSION['sess_user_pseudo'];
  96              else
  97                  $_SESSION['sess_user_cn'] = trim($_SESSION['sess_user_prenom'].' '.$_SESSION['sess_user_nom']);
  98              
  99              # Création du cookie (10 jours)
 100              $user_pwd = ($md5) ? md5($user_pwd) : $user_pwd;
 101              $cookie = array('user_id' => $user_id, 'user_pwd' => $user_pwd, 'remember' => $remember);
 102              $cookie_ttl = ($remember) ? strtotime('+15 days') : 0;
 103              setcookie('dc_admin',serialize($cookie),$cookie_ttl,dc_app_url);
 104              
 105              $res = true;
 106              
 107              $blog->tiggerLog('','','Login',$rs->f('user_id'));
 108          }
 109          
 110          unset($blog);
 111          
 112          return $res;
 113      }
 114      
 115  	function userLevel($level)
 116      {
 117          return $_SESSION['sess_user_level'] >= $level;
 118      }
 119  }
 120  ?>


Généré le : Fri Feb 23 21:40:15 2007 par Balluche grâce à PHPXref 0.7