Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('..\classes.php');
- class Validation {
- var $nick;
- var $password1;
- var $password2;
- var $mail;
- var $response;
- function validateNick( $nick ) {
- $this -> nick = $nick;
- $pattern = '/^[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*$/';
- $dbPdo = Helper::dbConnect();
- $dbQuery = ' SELECT `Nick` FROM `Users`
- WHERE `Nick` = :nick
- ';
- $dbStmt = $dbPdo -> prepare($dbQuery);
- $dbStmt -> bindValue(':nick', $this -> nick, PDO::PARAM_STR);
- $dbStmt -> execute();
- if( $dbStmt -> rowCount() > 0 ) {
- $this -> response[0] = false;
- $this -> response[1] = 'Nick \''.$this -> nick.'\' już istanieje w systemie.';
- }
- else {
- if( preg_match($pattern, $this -> nick ) > 0 && strlen( $this -> nick ) >= 3 ) {
- $this -> response[0] = true;
- }
- else {
- $this -> response[0] = false;
- $this -> response[1] = 'Twój nick jest za krótki lub zawiera niedozwolone znaki.';
- }
- }
- $dbStmt -> closeCursor();
- unset($dbStmt);
- return $this->response;
- }
- function validateMail( $mail ) {
- $this -> mail = $mail;
- $pattern = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$/';
- $dbPdo = Helper::dbConnect();
- $dbQuery = ' SELECT `Mail` FROM `Users`
- WHERE `Mail` = :mail
- ';
- $dbStmt = $dbPdo -> prepare($dbQuery);
- $dbStmt -> bindValue(':mail', $this -> mail, PDO::PARAM_STR);
- $dbStmt -> execute();
- if( $dbStmt -> rowCount() > 0 ) {
- $this -> response[0] = false;
- $this -> response[1] = 'Adres e-mail \''.$this -> mail.'\' już istnieje w systemie.';
- }
- else {
- if( preg_match($pattern, $this -> mail ) > 0 ) {
- $this -> response[0] = true;
- }
- else {
- $this -> response[0] = false;
- $this -> response[1] = 'Podany adres e-mail jest niepoprawny.';
- }
- }
- $dbStmt -> closeCursor();
- unset($dbStmt);
- return $this->response;
- }
- function validatePassword( $password1, $password2 ) {
- $this -> password1 = $password1;
- $this -> password2 = $password2;
- if( $password1 === $password2 ) {
- $this -> response[0] = true;
- }
- else {
- $this -> response[0] = false;
- $this -> response[1] = 'Hasła różnią się od siebie.';
- }
- return $this->response;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment