|
1
|
|
|
<?php |
|
2
|
|
|
namespace installation\controller; |
|
3
|
|
|
use core\App; |
|
4
|
|
|
use core\auth\Encrypt; |
|
5
|
|
|
use core\HTML\flashmessage\FlashMessage; |
|
6
|
|
|
|
|
7
|
|
|
class InstallUtilisateur { |
|
8
|
|
|
private $nom; |
|
9
|
|
|
private $prenom; |
|
10
|
|
|
private $pseudo; |
|
11
|
|
|
private $mdp; |
|
12
|
|
|
private $erreur; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
|
16
|
|
|
public function __construct($nom, $prenom, $pseudo, $mdp, $verif_mdp) { |
|
17
|
|
|
$this->nom = $this->setTestChamp($nom, "nom"); |
|
18
|
|
|
$this->prenom = $this->setTestChamp($prenom, "nom"); |
|
19
|
|
|
$this->pseudo = $this->setTestChamp($pseudo, "nom"); |
|
20
|
|
|
$this->mdp = $this->setTestMdp($mdp, $verif_mdp); |
|
21
|
|
|
|
|
22
|
|
|
if ($this->erreur == true) { |
|
23
|
|
|
FlashMessage::setFlash("<ul>".$this->nom.$this->prenom.$this->pseudo.$this->mdp."</ul>"); |
|
24
|
|
|
} |
|
25
|
|
|
else { |
|
26
|
|
|
$this->setInscrireUtilisateur(); |
|
27
|
|
|
|
|
28
|
|
|
FlashMessage::setFlash("Le compte super admin a bien été créé", "success"); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
|
36
|
|
|
public function getErreur() { |
|
37
|
|
|
return $this->erreur; |
|
38
|
|
|
} |
|
39
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
|
44
|
|
|
/** |
|
45
|
|
|
* @param $nom |
|
46
|
|
|
* @param $champ |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
private function setTestChamp($nom, $champ) { |
|
50
|
|
|
if (strlen($nom) >= 3) { |
|
51
|
|
|
return $nom; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->erreur = true; |
|
55
|
|
|
return "<li>Votre ".$champ." doit être de trois caractère minimum</li>"; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param $mdp |
|
60
|
|
|
* @param $verif_mdp |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
private function setTestMdp($mdp, $verif_mdp) { |
|
64
|
|
|
if ($mdp != $verif_mdp) { |
|
65
|
|
|
$this->erreur = true; |
|
66
|
|
|
return "<li>Vos mots de passe sont différents</li>"; |
|
67
|
|
|
} |
|
68
|
|
|
else { |
|
69
|
|
|
return $mdp; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* insertion du super user |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setInscrireUtilisateur() { |
|
77
|
|
|
$dbc = App::getDb(); |
|
78
|
|
|
|
|
79
|
|
|
$dbc->insert("pseudo", $this->pseudo) |
|
80
|
|
|
->insert("nom", $this->nom) |
|
81
|
|
|
->insert("prenom", $this->prenom) |
|
82
|
|
|
->insert("mdp", Encrypt::setEncryptMdp($this->mdp)) |
|
83
|
|
|
->insert("mdp_params", Encrypt::getParams()) |
|
84
|
|
|
->insert("last_change_mdp", date("Y-m-d")) |
|
85
|
|
|
->insert("img_profil", "profil/defaut.png") |
|
86
|
|
|
->insert("img_profil_blog", "profil/defaut_blog.png") |
|
87
|
|
|
->insert("valide", 1) |
|
88
|
|
|
->insert("acces_admin", 1) |
|
89
|
|
|
->insert("liste_droit", 0) |
|
90
|
|
|
->insert("super_admin", 1) |
|
91
|
|
|
->into("identite") |
|
92
|
|
|
->set(); |
|
93
|
|
|
} |
|
94
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
|
95
|
|
|
} |