Source for file Login.class.php

Documentation is available at Login.class.php

  1. <?php
  2. /**
  3.  * R.E. Login 2.0 - Login - class/Login.class.php
  4.  *
  5.  * Bejelentkezés műveletei<br />
  6.  * <br />
  7.  * <b>Dátum:</b> 2010.04.02.
  8.  *
  9.  * <b>Szerző weboldala:</b> {@link http://rimelek.hu/}<br />
  10.  * <b>Login weblapja:</b> {@link http://rimelek.hu/meghivos-loginrendszer-r-e-login-v2-0 R.E. Login v2.0}
  11.  *
  12.  * @author Takács Ákos (Rimelek), programmer [at] rimelek [dot] hu
  13.  * @copyright Copyright (C) 2010, Takács Ákos
  14.  * @license http://www.gnu.org/licenses/gpl.html
  15.  * @package RELogin
  16.  * @version 2.0
  17.  */
  18.  
  19. /**
  20.  * @ignore
  21.  */
  22. require_once System::getIncLoginDir().'classes/User.class.php';
  23.  
  24. /**
  25.  * Login műveleteit tartalmazó osztály
  26.  *
  27.  * <b>Szerző weboldala:</b> {@link http://rimelek.hu/}<br />
  28.  * <b>Login weblapja:</b> {@link http://rimelek.hu/meghivos-loginrendszer-r-e-login-v2-0 R.E. Login v2.0}
  29.  *
  30.  * @see InvalidAccountException
  31.  * @see NotActivatedException
  32.  * @see LoginBlockedException
  33.  * @see BannedException
  34.  *
  35.  * @author Takács Ákos (Rimelek), programmer [at] rimelek [dot] hu
  36.  * @copyright Copyright (C) 2010, Takács Ákos
  37.  * @license http://www.gnu.org/licenses/gpl.html
  38.  * @package RELogin
  39.  */
  40. class Login
  41. {
  42.     /**
  43.      * Hibák tömbje
  44.      *
  45.      * @var array 
  46.      */
  47.     private static $errors=array();
  48.  
  49.     /**
  50.      * Usernevet tartalmazó input mező neve
  51.      *
  52.      * @var string 
  53.      */
  54.     private static $userNameVar;
  55.  
  56.     /**
  57.      * Jelszót tartalmaző input mező neve
  58.      *
  59.      * @var string 
  60.      */
  61.     private static $userPassVar;
  62.  
  63.     /**
  64.      * Ha épp most loginolt be a user, akkor true. Egyébként false
  65.      *
  66.      * @var bool 
  67.      */
  68.     private static $submit false;
  69.  
  70.     /**
  71.      * Új hibaüzenet hozzáadása
  72.      *
  73.      * @param string $error Hibaüzenet
  74.      */
  75.     public static function addError($error)
  76.     {
  77.         self::$errors[$error;
  78.     }
  79.  
  80.     /**
  81.      * Usernév és jelszóhash sessionbe helyezése (Referenciaként paraméterekben visszaadása)
  82.      * 
  83.      * @param string $userName Usernév mező neve. Usernév kerül bele utána
  84.      * @param string $userPass Jelszó mező neve, Jelszó hash kerül bele utána
  85.      */
  86.     private static function init(&$userName,&$userPass
  87.     {
  88.         if(self::$submit = isset($_POST['login']))
  89.         {
  90.             Session::getInstance()->setLifetimeisset($_POST['login']['remember']360*24*3600 );
  91.         }
  92.         if (isset($_POST['login'][$userName]and self::$submit)
  93.         {
  94.             $_SESSION['s'.$userName$_POST['login'][$userName];
  95.         }
  96.         if (isset($_POST['login'][$userPass]and self::$submit)
  97.         {
  98.             $_SESSION['s'.$userPassself::getPasswordHash($_POST['login'][$userPass]);
  99.         
  100.         if (!isset($_SESSION['s'.$userName]))
  101.         {
  102.             $_SESSION['s'.$userName'';
  103.         }
  104.         if (!isset($_SESSION['s'.$userPass]))
  105.         {
  106.             $_SESSION['s'.$userPass'';
  107.         }
  108.         $userName $_SESSION['s'.$userName];
  109.         $userPass $_SESSION['s'.$userPass];
  110.     }
  111.  
  112.     /**
  113.      * User beléptetése
  114.      * 
  115.      * @param string $userName Usernév input mező neve
  116.      * @param string $userPass Jelszó input mező neve
  117.      * @return boolean True, ha beléphet, false, ha nem léphet be
  118.      */
  119.     public static function authUser($userName,$userPass)
  120.     {
  121.         self::$userNameVar=$userName;
  122.         self::$userPassVar=$userPass;
  123.         self::init($userName,$userPass);
  124.  
  125.         $user System::$user new User($userName,$userPass);
  126.         
  127.         if (self::$submit and isset($_POST['login'][self::$userNameVar]and  empty($user->username))
  128.         {
  129.             require_once System::getIncLoginDir().'classes/exceptions/InvalidAccountException.class.php';
  130.             throw new InvalidAccountException("Hibás név / jelszó!");
  131.         }
  132.         else if (!empty($user->T_users_useremailand $user->T_users_useremail != $user->T_profiles_useremail)
  133.         {
  134.             require_once System::getIncLoginDir().'classes/exceptions/NotActivatedException.class.php';
  135.             throw new NotActivatedException("Aktiváld hozzáférésed az emailben kapott linkkel!");
  136.         }
  137.         else if ($user->rank('banned'))
  138.         {
  139.             require_once System::getIncLoginDir().'classes/exceptions/BannedException.class.php';
  140.             throw new BannedException("Hozzáférésed tiltva van!");
  141.         }
  142.         $return !empty($user->usernameand !count(self::$errors);
  143.  
  144.         if ($return and Config::LOGIN_BLOCKED and !$user->rank(array('admin','owner')))
  145.         {
  146.             require_once System::getIncLoginDir().'classes/exceptions/LoginBlockedException.class.php';
  147.             throw new LoginBlockedException("A belépés ideiglenesen tiltva. Próbálkozz később!");
  148.         }
  149.  
  150.         if (self::$submit and $return)
  151.         {
  152.             $user->logintime date('Y-m-d H:i:s');
  153.             $user->onlinestatus 1;
  154.         }
  155.         return $return;
  156.     }
  157.  
  158.     /**
  159.      * Hibák visszaaádsa
  160.      *
  161.      * @return array 
  162.      */
  163.     public static function getErrors(
  164.     {
  165.         return self::$errors;    
  166.     }
  167.  
  168.     /**
  169.      * User kiléptetése
  170.      */
  171.     public static function logout()
  172.     {
  173.         $_SESSION['s'.self::$userNameVar]='';
  174.         $_SESSION['s'.self::$userPassVar]='';
  175.         if (System::$logged)
  176.         {
  177.             System::$user->onlinestatus 0;
  178.         }
  179.         Session::getInstance()->setLifetime(0);
  180.     }
  181.  
  182.     /**
  183.      * Jelszóhash generálása
  184.      *
  185.      * Megadható a sózáshoz használt string a metódusban.
  186.      *
  187.      * @param string $password Jelszó
  188.      * @return string Sózott jelszóhash
  189.      */
  190.     public static function getPasswordHash($password)
  191.     {
  192.         return md5(sha1($password " "." R.E. Login 2.0 " sha1($password));
  193.     }
  194.  
  195.     /**
  196.      * Megváltoztatja a session-ben levő jelszóhasht.
  197.      *
  198.      * @param string $password 
  199.      */
  200.     public static function changePassword($password)
  201.     {
  202.         $_SESSION['s'.self::$userPassVar$password;
  203.     }
  204. }
  205. ?>

Documentation generated on Sun, 04 Apr 2010 22:43:45 +0200 by phpDocumentor 1.4.1