Membre::setPseudo()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 11
nc 3
nop 1
1
<?php
2
	namespace core\auth;
3
4
5
	use core\App;
6
	
7
	class Membre {
8
		protected $id_identite;
9
		protected $nom;
10
		protected $prenom;
11
		protected $mail;
12
		protected $pseudo;
13
		protected $img;
14
		protected $mdp;
15
		protected $valide;
16
		protected $erreur = "";
17
		
18
		private $debut_lien;
19
		
20
		//------------------------------ constructeur-----------------------------------
21
		//Récupérer en base de données les infos du membre
22
		public function __construct($id_identite = null) {
23
			$this->debut_lien = IMGROOT."profil/";
24
25
			if ($id_identite != null) {
26
				$this->getInfosMembre($id_identite);
27
			}
28
		}
29
		//------------------------------ fin constructeur -----------------------------------
30
		
31
		
32
		
33
		//------------------------------ getter-----------------------------------
34
		public function getIdidentite() {
35
			return $this->id_identite;
36
		}
37
		public function getNom() {
38
			return $this->nom;
39
		}
40
		public function getPrenom() {
41
			return $this->prenom;
42
		}
43
		public function getPseudo() {
44
			return $this->pseudo;
45
		}
46
		public function getMail() {
47
			return $this->mail;
48
		}
49
		public function getImg() {
50
			return $this->img;
51
		}
52
		public function getMdp() {
53
			return $this->mdp;
54
		}
55
		public function getValide() {
56
			return $this->valide;
57
		}
58
		public function getErreur() {
59
			return $this->erreur;
60
		}
61
		
62
		/**
63
		 * @param $id_identite
64
		 * function that get all infos of a member
65
		 */
66
		private function getInfosMembre($id_identite) {
67
			$dbc = App::getDb();
68
			
69
			$query = $dbc->select()->from("identite")->where("ID_identite", "=", $id_identite)->get();
70
			
71
			if ((is_array($query)) && (count($query) > 0)) {
72
				foreach ($query as $obj) {
73
					$this->id_identite = $obj->ID_identite;
74
					$this->nom = $obj->nom;
75
					$this->prenom = $obj->prenom;
76
					$this->mail = $obj->mail;
77
					$this->pseudo = $obj->pseudo;
78
					$this->mdp = $obj->mdp;
79
					$this->valide = $obj->valide;
80
					$this->img = $obj->img_profil;
81
				}
82
			}
83
		}
84
		//------------------------------ fin getter -----------------------------------
85
		
86
		
87
		
88
		//------------------------------ setter-----------------------------------
89
90
		/**
91
		 * @param string $new_pseudo
92
		 */
93
		public function setPseudo($new_pseudo) {
94
			$dbc = \core\App::getDb();
95
			
96
			//si pseudo trop court
97
			if ((strlen($new_pseudo) < 5) || (strlen($new_pseudo) > 15)) {
98
				$err = "Votre pseudo doit être entre 5 et 15 caractères";
99
				$this->erreur = $err;
100
			}
101
			else if ($dbc->rechercherEgalite("identite", "pseudo", $new_pseudo) == false) {
102
				$err = "Ce pseudo est déjà utilisé, veuillez en choisir un autre";
103
				$this->erreur = $err;
104
			}
105
			else {
106
				$dbc->update("pseudo", $new_pseudo)->from("identite")->where("ID_identite", "=", $_SESSION["idlogin".CLEF_SITE])->set();
107
				$this->pseudo = $new_pseudo;
108
			}
109
		}
110
111
		/**
112
		 * @param string $old_mdp
113
		 * @param string $new_mdp
114
		 * @param string $verif_new_mdp
115
		 */
116
		public function setMdp($old_mdp, $new_mdp, $verif_new_mdp) {
117
			$dbc = \core\App::getDb();
118
119
			$mdp = Encrypt::setDecryptMdp($this->mdp, $this->id_identite);
120
121
			//si mdp trop court
122
			if (md5($old_mdp) != $mdp) {
123
				$err = "Votre mot de passe est incorrect";
124
				$this->erreur = $err;
125
			}
126
			else if ($new_mdp != $verif_new_mdp) {
127
				$err = "Vos mots de passe sont différents";
128
				$this->erreur = $err;
129
			}
130
			else {
131
				$mdpok = Encrypt::setEncryptMdp($new_mdp, $this->id_identite);
132
				//le nouveau mdp est bon on update
133
				$dbc->update("mdp", $mdpok)->from("identite")->where("ID_identite", "=", $this->id_identite)->set();
134
135
				$this->mdp = $mdpok;
136
			}
137
		}
138
		//------------------------------ fin setter -----------------------------------
139
	}