Bonjour,
J'ai bien suivit le tuto pour l'identification des utilisateurs avec mot de passe encoder sha1
J'ai un probleme quand on modifie la fiche d'un utilisteur et qu'on ne change que le nom et rien d'autre.
Le mot de passe se trouve aché à nouveau ce qui le change.
Mon model
Module
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 <?php class model_users extends abstract_model{ protected $sClassRow='row_users'; protected $sTable='users'; protected $sConfig='pdoMysql'; protected $tId=array('id'); public static function getInstance(){ return self::_getInstance(__CLASS__); } public function findById($uId){ return $this->findOne('SELECT * FROM '.$this->sTable.' WHERE id=?',$uId ); } public function findAllProfs(){ return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE statut_id=2 ORDER BY nom ASC'); } public function findAllByStatut($statut_id){ return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE statut_id=? ORDER BY nom ASC',$statut_id); } public function findAllEleves(){ return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE statut_id=1 ORDER BY nom DESC'); } public function findAll(){ return $this->findMany('SELECT * FROM '.$this->sTable. ' ORDER BY nom ASC'); } public function findSessionById($eleveId){ return $this->findOne('SELECT sessions.nom FROM sessions, classes, users WHERE sessions.id=classes.session_id AND users.classe_id=classes.id AND users.id=?',$eleveId ); } public function findAllByProf($classe_id){ return $this->findMany('SELECT users.* FROM `classesProfs`, users, classes WHERE classesProfs.user_id=users.id AND classesProfs.classe_id=? AND users.statut_id<>1 group BY users.nom ORDER BY nom ASC',$classe_id ); } public function findAllByclasse($classe_id){ return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE classe_id=? ORDER BY nom ASC',$classe_id ); } public function getSelect(){ $tab=$this->findAll(); $tSelect=array(); if($tab){ foreach($tab as $oRow){ $tSelect[ $oRow->id ]=$oRow->nom; } } return $tSelect; } public function getSelectAllProfs(){ $tab=$this->findAllProfs(); $tSelect=array(); if($tab){ foreach($tab as $oRow){ $tSelect[ $oRow->id ]=$oRow->nom; } } return $tSelect; } public function getSelectAllEleves(){ $tab=$this->findAllEleves(); $tSelect=array(); if($tab){ foreach($tab as $oRow){ $tSelect[ $oRow->id ]=$oRow->nom; } } return $tSelect; } public function getListAccount(){ $tAccount=$this->findAll(); $tLoginPassAccount=array(); foreach($tAccount as $oAccount){ $tLoginPassAccount[$oAccount->login][$oAccount->pass]=$oAccount; } return $tLoginPassAccount; } } class row_users extends abstract_row{ protected $sClassModel='model_users'; /*exemple jointure public function findAuteur(){ return model_auteur::getInstance()->findById($this->auteur_id); } */ /*exemple test validation*/ private function getCheck(){ $oPluginValid=new plugin_valid($this->getTab()); $oPluginValid->isNotEmpty('nom','Obligatoire'); $oPluginValid->isNotEmpty('prenom','Obligatoire'); //on check que l'email est rempli if($this->mail!=''){ //si il est rempli, on verifie le format de l'email ;) $oPluginValid->isEmailValid('mail','Mail incorrect'); } /* renseigner vos check ici $oPluginValid->isEqual('champ','valeurB'); $oPluginValid->isNotEqual('champ','valeurB'); $oPluginValid->isUpperThan('champ','valeurB'); $oPluginValid->isUpperOrEqualThan('champ','valeurB'); $oPluginValid->isLowerThan('champ','valeurB'); $oPluginValid->isLowerOrEqualThan('champ','valeurB'); $oPluginValid->isEmpty('champ'); $oPluginValid->isNotEmpty('champ'); $oPluginValid->isEmailValid('champ'); $oPluginValid->matchExpression('champ','/[0-9]/'); $oPluginValid->notMatchExpression('champ','/[a-zA-Z]/'); */ return $oPluginValid; } public function isValid(){ return $this->getCheck()->isValid(); } public function getListError(){ return $this->getCheck()->getListError(); } public function save(){ if(!$this->isValid()){ return false; } //on force en majuscule $this->nom=strtoupper($this->nom); $this->prenom=ucfirst($this->prenom); //On hache le passW $this->pass=sha1($this->pass); parent::save(); return true; } }Ma vue
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 <?php class module_monCompte extends abstract_module{ public function before(){ $this->oLayout=new _layout('template1'); $this->oLayout->addModule('menu','menu::left'); } public function _index(){ //on considere que la page par defaut est la page de listage $this->_show(); } public function _edit(){ $tMessage=$this->save(); $oUsers=model_users::getInstance()->findById(_root::getAuth()->getAccount()->id); $oView=new _view('monCompte::edit'); $oView->oUsers=$oUsers; $oView->tId=model_users::getInstance()->getIdTab(); $oView->tJoinmodel_statutsNoEleve=model_statuts::getInstance()->getSelectNoEleve(); $oView->tJoinmodel_statutsEleve=model_statuts::getInstance()->getSelectEleve(); $oView->tJoinmodel_classes=model_classes::getInstance()->getSelect(); $oPluginXsrf=new plugin_xsrf(); $oView->token=$oPluginXsrf->getToken(); $oView->tMessage=$tMessage; $this->oLayout->add('main',$oView); } public function _editPW(){ $tMessage=$this->save(); $oUsers=model_users::getInstance()->findById(_root::getAuth()->getAccount()->id); $oView=new _view('monCompte::editPW'); $oView->oUsers=$oUsers; $oView->tId=model_users::getInstance()->getIdTab(); $oPluginXsrf=new plugin_xsrf(); $oView->token=$oPluginXsrf->getToken(); $oView->tMessage=$tMessage; $this->oLayout->add('main',$oView); } public function _show(){ $oUsers=model_users::getInstance()->findById(_root::getAuth()->getAccount()->id); $oView=new _view('monCompte::show'); $oView->oUsers=$oUsers; $oView->tJoinmodel_statuts=model_statuts::getInstance()->getSelect(); $oView->tJoinmodel_classes=model_classes::getInstance()->getSelect(); $this->oLayout->add('main',$oView); } public function save(){ if(!_root::getRequest()->isPost() ){ //si ce n'est pas une requete POST on ne soumet pas return null; } $oPluginXsrf=new plugin_xsrf(); if(!$oPluginXsrf->checkToken( _root::getParam('token') ) ){ //on verifie que le token est valide return array('token'=>$oPluginXsrf->getMessage() ); } $iId=_root::getParam('id',null); if($iId==null){ $oUsers=new row_users; }else{ $oUsers=model_users::getInstance()->findById( _root::getParam('id',null) ); } $tId=model_users::getInstance()->getIdTab(); $tColumn=model_users::getInstance()->getListColumn(); foreach($tColumn as $sColumn){ if(isset($_FILES[$sColumn]) and $_FILES[$sColumn]['size'] > 0){ $sNewFileName='data/upload/'.$sColumn.'_'.date('Ymdhis'); $oPluginUpload=new plugin_upload($_FILES[$sColumn]); $oPluginUpload->saveAs($sNewFileName); $oUsers->$sColumn=$oPluginUpload->getPath(); continue; }else if( _root::getParam($sColumn,null) ==null ){ continue; }else if( in_array($sColumn,$tId)){ continue; } $oUsers->$sColumn=_root::getParam($sColumn,null) ; } if($oUsers->isValid()){ $oUsers->save(); //une fois enregistre on redirige (vers la page show) _root::redirect('monCompte::show'); }else{ return $oUsers->getListError(); } } public function delete(){ if(!_root::getRequest()->isPost() ){ //si ce n'est pas une requete POST on ne soumet pas return null; } $oPluginXsrf=new plugin_xsrf(); if(!$oPluginXsrf->checkToken( _root::getParam('token') ) ){ //on verifie que le token est valide return array('token'=>$oPluginXsrf->getMessage() ); } $oUsers=model_users::getInstance()->findById( _root::getParam('id',null) ); $oUsers->delete(); //une fois enregistre on redirige (vers la page show) _root::redirect('monCompte::show'); } public function after(){ $this->oLayout->show(); } } /*variables #select $oView->tJoinusers=users::getInstance()->getSelect();#fin_select #uploadsave if(isset($_FILES[$sColumn]) and $_FILES[$sColumn]['size'] > 0){ $sNewFileName='data/upload/'.$sColumn.'_'.date('Ymdhis'); $oPluginUpload=new plugin_upload($_FILES[$sColumn]); $oPluginUpload->saveAs($sNewFileName); $oUsers->$sColumn=$oPluginUpload->getPath(); continue; }else #fin_uploadsave variables*/
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 <?php $oPluginHtml=new plugin_html?> <form action="" method="POST" > <?php foreach($this->tId as $sColumn):?> <input type="hidden" name="<?php echo $sColumn ?>" value="<?php echo $this->oUsers->$sColumn ?>" /> <?php if($this->tMessage and isset($this->tMessage[$sColumn])): echo implode(',',$this->tMessage[$sColumn]); endif;?> <?php endforeach;?> <table class="tb_edit"> <?php if(_root::getACL()->can('admin','statut')):?> <tr> <th>nom</th> <td><input name="nom" value="<?php echo $this->oUsers->nom ?>" /><?php if($this->tMessage and isset($this->tMessage['nom'])): echo implode(',',$this->tMessage['nom']); endif;?></td> </tr> <tr> <th>prenom</th> <td><input name="prenom" value="<?php echo $this->oUsers->prenom ?>" /><?php if($this->tMessage and isset($this->tMessage['prenom'])): echo implode(',',$this->tMessage['prenom']); endif;?></td> </tr> <?php else: ?> <tr> <th>nom</th> <td><?php echo $this->oUsers->nom ?></td> </tr> <tr> <th>prenom</th> <td><?php echo $this->oUsers->prenom ?></td> </tr> <?php endif ?> <tr> <th>login</th> <td><input name="login" value="<?php echo $this->oUsers->login ?>" /><?php if($this->tMessage and isset($this->tMessage['login'])): echo implode(',',$this->tMessage['login']); endif;?></td> </tr> <tr> <th>mail</th> <td><input name="mail" value="<?php echo $this->oUsers->mail ?>" /><?php if($this->tMessage and isset($this->tMessage['mail'])): echo implode(',',$this->tMessage['mail']); endif;?></td> </tr> <?php if(_root::getACL()->can('admin','statut')):?> <tr> <th>statut</th> <td><?php echo $oPluginHtml->getSelect('statut_id',$this->tJoinmodel_statutsNoEleve,$this->oUsers->statut_id)?><?php if($this->tMessage and isset($this->tMessage['statut_id'])): echo implode(',',$this->tMessage['statut_id']); endif;?></td> </tr> <?php endif ?> <?php if(_root::getACL()->can('eleve','statut') ):?> <tr> <th>classe</th> <td><?php echo $this->tJoinmodel_classes[$this->oUsers->classe_id]?></td> </tr> <?php endif;?> </table> <input type="hidden" name="token" value="<?php echo $this->token?>" /> <?php if($this->tMessage and isset($this->tMessage['token'])): echo $this->tMessage['token']; endif;?> <input type="submit" value="Modifier" /> <a href="<?php echo $this->getLink('monCompte::show')?>">Annuler</a> </form>
Partager