Guest User

Validation.class.php

a guest
Jun 16th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php
  2. require_once('..\classes.php');
  3.  
  4.     class Validation {
  5.         var $nick;
  6.         var $password1;
  7.         var $password2;
  8.         var $mail;
  9.         var $response;
  10.        
  11.         function validateNick( $nick ) {            
  12.             $this -> nick   = $nick;
  13.             $pattern        = '/^[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*$/';            
  14.             $dbPdo          = Helper::dbConnect();            
  15.             $dbQuery        = ' SELECT `Nick` FROM `Users`
  16.                                WHERE `Nick` = :nick  
  17.                              ';
  18.            
  19.             $dbStmt = $dbPdo -> prepare($dbQuery);
  20.             $dbStmt -> bindValue(':nick', $this -> nick, PDO::PARAM_STR);
  21.             $dbStmt -> execute();
  22.             if( $dbStmt -> rowCount() > 0 ) {
  23.                 $this -> response[0] = false;
  24.                 $this -> response[1] = 'Nick \''.$this -> nick.'\' już istanieje w systemie.';
  25.                
  26.             }
  27.             else {            
  28.                 if( preg_match($pattern, $this -> nick ) > 0 && strlen( $this -> nick ) >= 3 ) {
  29.                
  30.                     $this -> response[0] = true;
  31.                 }
  32.                 else {
  33.                     $this -> response[0] = false;
  34.                     $this -> response[1] = 'Twój nick jest za krótki lub zawiera niedozwolone znaki.';
  35.                 }
  36.             }
  37.             $dbStmt -> closeCursor();
  38.             unset($dbStmt);
  39.            
  40.             return $this->response;
  41.         }
  42.        
  43.         function validateMail( $mail ) {
  44.             $this -> mail   = $mail;
  45.             $pattern        = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$/';
  46.             $dbPdo          = Helper::dbConnect();
  47.             $dbQuery        = ' SELECT `Mail` FROM `Users`
  48.                                WHERE `Mail` = :mail
  49.                              ';
  50.            
  51.             $dbStmt = $dbPdo -> prepare($dbQuery);
  52.             $dbStmt -> bindValue(':mail', $this -> mail, PDO::PARAM_STR);
  53.             $dbStmt -> execute();            
  54.             if( $dbStmt -> rowCount() > 0 ) {
  55.                 $this -> response[0] = false;
  56.                 $this -> response[1] = 'Adres e-mail \''.$this -> mail.'\' już istnieje w systemie.';
  57.             }
  58.             else {
  59.                 if( preg_match($pattern, $this -> mail ) > 0 ) {
  60.                     $this -> response[0] = true;
  61.                 }
  62.                 else {
  63.                     $this -> response[0] = false;
  64.                     $this -> response[1] = 'Podany adres e-mail jest niepoprawny.';
  65.                 }
  66.             }
  67.             $dbStmt -> closeCursor();
  68.             unset($dbStmt);
  69.            
  70.             return $this->response;
  71.         }
  72.  
  73.         function validatePassword( $password1, $password2 ) {
  74.             $this -> password1 = $password1;
  75.             $this -> password2 = $password2;
  76.             if( $password1 === $password2 ) {
  77.                 $this -> response[0] = true;
  78.             }
  79.             else {
  80.                 $this -> response[0] = false;
  81.                 $this -> response[1] = 'Hasła różnią się od siebie.';
  82.             }
  83.            
  84.             return $this->response;
  85.         }
  86.     }
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment