Pisze (dla praktyki) system wypozyczania ksiazek. Narazie skonczylem system rejestracji uzytkownikow. Jest to pierwszy projekt w OOP jaki robie wiec napewno sa bledy. Prosba o sprwadzenie formy i wskazowki jak i co polepszyc . Tak towyglada w plikach:
projekt/config/config.php
projekt/config/database.php
projekt/class/user.class.php
projekt/class/userException.class.php
projekt/controller/register.control.php
projekt/register.php
A tu kod:
config/config.php
<?php $local=TRUE; }else { $local= FALSE; } //determine location of files and the URL of the site: //allow for development on different servers. if($local){ $debug=TRUE; //define the constants: } // if there was a live server then the condition would have included live server defines $debug=FALSE; } // Custom defined error handler - no need to define it as of yet. ?>
class/user.class.php
/* * user.class.php * Adds user : First Name, Second Name, Email, ID - auto increment * Checks if email is already in the db. - Unique email field * Adds user into the detabase */ class user{ //db private $conn; public $name,$surname,$email; public $password; public $_message; // for assigning errors function __construct($db){ $this->conn=$db; } /* *Name: not numeric, less then 10 characters */ function checkName($name){ $this->name=$name; return $this->name; } Throw New userException($this->_message,0); } /* * Surname: not numeric, less then 10 characters */ function checkSurname($surname){ $this->Surname=$surname; return $this->urname; } Throw New userException($this->_message,1); } /* * The password's first character must be a letter, it must contain at least 4 * characters and no more than 15 characters and no characters other than letters, * numbers and the underscore may be used */ function checkPassword($password){ $this->password=$password; return $this->password; }else{ Throw New userException($this->_message,2); } } /* * Password hashing */ function setPassword($password){ $this->password=sha1($password); return $password; } function create(){ $query= "insert into users SET name=?, Surname=?, email=?, password=?"; $stmt = $this->conn->prepare($query); $stmt->bindParam(1,$this->name); $stmt->bindParam(2,$this->Surname); $stmt->bindParam(3,$this->email); $stmt->bindParam(4,$this->password); if($stmt->execute()){ return TRUE; }else{ Throw New Exception('email'); } }// end of create() } // end of main if
class/exception.class.php
class userException extends Exception{ public function getDetails(){ switch ($this->code){ case 0: return '</br>Name. '; break; case 1: return '</br>Surname</br>Details given do not meet required criteria'; break; case 2: return 'Password must contain 1 character, special sign, upper and lower case letters'; break; case 3: return 'There is something wrong with the email'; default: return 'no Further information is available'; break; } } }
controller/register.control.php
if($_SERVER['REQUEST_METHOD']=='POST' && filter_var($_POST['em'],FILTER_VALIDATE_EMAIL) ){ include_once('./class/user.class.php'); include_once('./config/database.php'); require_once('./class/exception.class.php'); $database = new Database; $db=$database->getConnection(); $user= new user($db); try{ $user ->name =$_POST['fn']; $user->checkName($user->name); $user ->Surname = $_POST['sn']; $user->checkSurname($user->Surname); $user ->password= $_POST['ps']; $user->checkPassword($user->password); $user ->setPassword($user->password); $user ->email = $_POST['em']; if($user->create()){ } }catch(userException $e){ echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>"; } } // end of secondary if } // end of main if
view/register.php
<!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags always come first --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous"> <link rel="stylesheet" href= "css/bootstrap-theme.min.css"> </head> <body> <h1>Registration Form</h1> <!-- jQuery first, then Bootstrap JS. --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script> </body> </html> <!-- header --> <?php require_once('controller/register.control.php'); ?> <div id="wrapper"> <div class="col-xs-3"> <form class="form-block" action="" method="post"> <div class="form-group"> <label for="exampleInputName2">Name</label> <input type="text" class="form-control" name="fn" id="exampleInputName2" placeholder="First Name"> </div> <div class="form-group"> <label for="exampleInputName2">Surname</label> <input type="text" class="form-control" name="sn" id="exampleInputName2" placeholder="Surname"> </div> <div class="form-group"> <label for="exampleInputName2">Password</label> <input type="text" class="form-control" name="ps" id="exampleInputName2" placeholder="Password"> </div> <div class="form-group"> <label for="exampleInputEmail2">Email</label> <input type="email" class="form-control" name="em" id="exampleInputEmail2" placeholder="email adress"> </div> <button type="submit" name="send" class="btn btn-primary">Register</button> </form> </div> </div>