Facebook
From Stained Pintail, 9 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 486
  1. <?
  2.  
  3.         class ENGINE_front_logowanie extends CMS
  4.         {
  5.                 public $valid = false;
  6.                
  7.                 function defaulted()
  8.                 {
  9.                         header('Location: '.$this->config['root']);
  10.                 }
  11.                
  12.                 function zaloguj()
  13.                 {
  14.  
  15.                 $b=$_POST['back']!='' ? $_POST['back'] : '/uzytkownik/';
  16.                
  17.                
  18.                         if(isset($_POST['email']) && isset($_POST['pass']))
  19.                         {
  20.                                 $data = $this->slashesData($_POST,'add');
  21.                                  
  22.                                
  23.                                 $res  = $this->db->dbQuery("SELECT * FROM customers WHERE email='".$data['email']."' AND pass=sha1('".$data['pass']."') AND access=1");
  24.                                 $data = $this->db->assocAll($res);
  25.  
  26.                                 if($data)
  27.                                 {
  28.                                         $fields = array('firstname','secondname','company','street','nr1',
  29.                                                                                                         'nr2','postcode','city','fax','phone','nip','email');
  30.                                                                                        
  31.                                         foreach($fields as $field)
  32.                                                 $_SESSION[$field] = $data[0][$field];
  33.                                        
  34.                                         $_SESSION['id'] = $data[0]['id'];
  35.                                         $_SESSION['auth']  = md5(time());
  36.                                         unset($_SESSION['pass']);
  37.                                        
  38.                                         $d = array();
  39.                                         $d['idUser'] = $data[0]['id'];
  40.                                         $d['ip'] = $_SERVER['REMOTE_ADDR'];
  41.                                         $d['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
  42.                                         $d['data_dodania'] = time();
  43.                                        
  44.                                         $this->contents->table = 'login_logs';
  45.                                         $this->contents->data = $d;
  46.                                         $this->contents->insert();
  47.                                        
  48.                                        
  49.                                         $res = $this->db->dbQuery("SELECT * FROM customers_groups WHERE id=".$data[0]['grupa']);
  50.                                         $rabat = $this->db->result($res,'rabat');
  51.                                        
  52.                                         $_SESSION['rabat'] = $rabat;
  53.                                        
  54.                                 }
  55.                                 else
  56.                                 {
  57.                                         if($_POST['back']=='/koszyk/platnosc.html')
  58.                                                 {header('location:../koszyk/platnosc.html?error=pass');exit();}
  59.                                         $this->contents->assign('error',true);
  60.                                 }
  61.                         }
  62.                         else
  63.                                 $this->contents->assign('form',true);
  64.                        
  65.                        
  66.                         if($_POST['back']=='/koszyk/platnosc.html' && $_SESSION['rabat'])
  67.                                 $b = '/koszyk/udziel_rabatu.html';
  68.                        
  69.                        
  70.                         if(isset($_SESSION['auth']) && $_SESSION['auth']==true) {
  71.                         $this->loadModule('logs');
  72.                         $this->logs->insert("Uzytkownik sie zalogowal");
  73.                                         header("Location: ..".$b);
  74.                                         exit();
  75.                         }
  76.                         $this->contents->display('system/zaloguj.html');
  77.                 }
  78.                
  79.                 function wyloguj()
  80.                 {
  81.                         if(!isset($_SESSION['auth'])) header("Location: ".$this->config['root']);
  82.                         $_SESSION['id']=0;
  83.                         session_destroy();
  84.                         $_SESSION = array();
  85.                         $_SESSION['id']=0;
  86.                         /*$this->setHeaderToTpl('Refresh','5; URL=../');
  87.                         $this->putHeaderToTpl('contents');
  88.                         $this->contents->assign('system','logout');
  89.                         echo '<META HTTP-EQUIV="Refresh" CONTENT="5;URL='.$this->config['root'].'">';
  90.                         $this->contents->display('system/login.html');
  91.                         */
  92.                         header("location:/?mess=Zostałeś wylogowany");
  93.                 }
  94.  
  95.         function przypomnij_haslo()
  96.         {
  97.             if(isset($_POST['email']))
  98.                         {
  99.                                 $fields = array(
  100.                                         'email' => array(
  101.                                                 'reguired' => true,
  102.                                                 'regxp2'    => '[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}',
  103.                                                 'length_min'  => 6,
  104.                                                 'length_max'  => 128,
  105.                                                 'db'              => array('table'=>'customers','field'=>'email'),
  106.                                                 'dbrequired'  => true
  107.                                         )
  108.                                 );
  109.                                 $this->validationFields($fields,$_POST,'contents');
  110.                                 if($this->valid)
  111.                                         $this->remaindPassword();
  112.                         }
  113.             $this->contents->display('forms/remain_password.html');
  114.         }
  115.                 function zmien_haslo()
  116.         {
  117.             if(strlen($_POST['pass'])>2 AND $_POST['pass']==$_POST['pass1'])
  118.                         {
  119.                                 $this->db->dbQuery("Update customers set pass ='".sha1(mysql_real_escape_string($_POST['pass']))."' where id=".$_SESSION['id']);
  120.                                
  121.                                 header("Location: zmien_haslo.html?mess=Hasło zostało zmienione!");
  122.                                
  123.                                 $this->contents->assign('ch',true);
  124.                         }
  125.             $this->contents->display('forms/zmien_haslo.html');
  126.         }
  127.        
  128.         function remaindPassword()
  129.         {
  130.                         $new_pass='now'.rand(11,2339);
  131.                         $this->contents->table = 'customers';
  132.                         $this->contents->cond = "email='".mysql_real_escape_string($_POST['email'])."'";
  133.                         $this->contents->order = false;
  134.                        
  135.                         $this->contents->data=array('tmppass'=>$new_pass);
  136.                         $this->contents->update();
  137.                        
  138.                         $user = $this->contents->getContent();
  139.                        
  140.                          
  141.                        
  142.                         $this->contents->assign('hash',sha1($user['email']));
  143.                         $this->contents->assign('new_pass',$new_pass);
  144.                         $msg = mysql_escape_string($this->contents->fetch('system/remain_password_email.html'));
  145.                        
  146.                         $this->contents->display('system/remain_password.html');
  147.                        
  148.                         $this->sendEmailMsg($this->config['remain_password_msg_from'],$this->config['remain_password_msg_email'],$_POST['email'], $this->config['remain_password_msg_title'], $msg);
  149.                        
  150.                         exit;
  151.                 }
  152.                
  153.                 function akceptujHaslo()
  154.                 {
  155.                         $res = $this->db->dbQuery("UPDATE customers set pass=sha1(tmppass) WHERE sha1(email)='".mysql_escape_string($_GET['hash'])."'");
  156.                        
  157.                        
  158.                         if($this->db->affected())
  159.                                 header('Location: ../?mess=Twoje hasło zostało aktywowane');
  160.                         else
  161.                                 header('Location: ../?mess=Twój link stracił ważność lub jest niepoprawny');
  162.                 }
  163.        
  164.         }
  165.        
  166. ?>