Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class registerService
- {
- private $params;
- private $error;
- private $user;
- public function getParams() { return $this->params; }
- public function setParams($params) { $this->params = $params; }
- public function getError() { return $this->error; }
- public function setError($error) { $this->error = $error; }
- public function getUser(){ return $this->user; }
- public function setUser($user){ $this->user = $user; }
- public function launchControls(){
- if(empty($this->params['username'])){
- $this->error['username'] = 'Nom utilisateur manquant';
- }
- if(strlen($this->params['username']) < 8) {
- $this->error['username'] = 'Nom utilisateur trop court 8 charactère minimum';
- } else if(strlen($this->params['username']) > 16) {
- $this->error['username'] = 'Nom utilisateur trop long 16 charactère maximum';
- }
- if(empty($this->params['password'])){
- $this->error['password'] = 'Mot de passe manquant';
- }
- if(strlen($this->params['password']) < 8) {
- $this->error['password'] = 'Mot de passe trop court 8 charactère minimum';
- } else if(strlen($this->params['password']) > 16) {
- $this->error['password'] = 'Mot de passe trop long 16 charactère maximum';
- }
- if($this->params['password'] != $this->params['confirmPassword']) {
- $this->error['confirmPassword'] = 'Les mot de passe ne sont pas identique';
- }
- if (!filter_var($this->params['email'], FILTER_VALIDATE_EMAIL)) {
- $this->error['email'] = 'Le format de l\'adresse mail n\'est pas valide';
- }
- if(empty($this->error)==false){
- return $this->error;
- }
- // $this->user = $this->checkUsernamePassword();
- // if(empty($this->user)){
- // $this->error['identifiants'] = 'Le nom d\'utilisateur ou mot de passe incorrect';
- // return $this->error;
- // }else{
- // return $this->user;
- // }
- $this->username = $this->checkUsernameExist();
- if(empty($this->username)) {
- return $this->error['username'] = 'Nom d\'utilisateur indisponible';
- }else{
- return $this->username;
- }
- $this->email = $this->checkEmailExist();
- if(empty($this->email)) {
- return $this->error['email'] = 'L\'adresse mail est déjà utiliser';
- }else{
- return $this->email;
- }
- $this->user = $this->checkUsernamePassword();
- if(empty($this->user)){
- $this->error['identifiants'] = 'Le nom d\'utilisateur ou mot de passe incorrect';
- return $this->error;
- }else{
- return $this->user;
- }
- }
- /***
- * Il est évident que cette fonction ne va pas ici!!!!
- */
- public function checkUsernameExist() {
- $username = $this->params['username'];
- $connexion = new PDO('mysql:host=localhost;dbname=blog;charset=UTF8','root','root');
- $connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $connexion->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $object = $connexion->prepare('SELECT username FROM users WHERE username=:username');
- $object->execute(array(
- 'username'=>$username
- ));
- $user = $object->fetchAll(PDO::FETCH_ASSOC);
- if(empty($user)==true){
- return $user;
- }
- return true;
- }
- public function checkEmailExist() {
- $email = $this->params['email'];
- $connexion = new PDO('mysql:host=localhost;dbname=blog;charset=UTF8','root','root');
- $connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $connexion->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $object = $connexion->prepare('SELECT email FROM users WHERE email=:email');
- $object->execute(array(
- 'email'=>$email
- ));
- $email = $object->fetchAll(PDO::FETCH_ASSOC);
- if(empty($email)==true){
- return $email;
- }
- return true;
- }
- public function checkUsernamePassword(){
- $username = $this->params['username'];
- $password = $this->params['password'];
- $connexion = new PDO('mysql:host=localhost;dbname=blog;charset=UTF8','root','root');
- $connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $connexion->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $object = $connexion->prepare('SELECT id,username FROM users WHERE username=:username AND password=:password');
- $object->execute(array(
- 'password'=>$password,
- 'username'=>$username
- ));
- $user = $object->fetchAll(PDO::FETCH_ASSOC);
- if(empty($user)==false){
- return $user;
- }
- return false;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement