Précédent   Forum du club des développeurs et IT Pro > PHP > Bibliothèques et frameworks > CakePHP
CakePHP Forum d'entraide sur le framework PHP CakePHP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 16/12/2012, 11h32   #1
runcafre91
Membre du Club
 
Homme Stéphane A.
Inscription : décembre 2008
Messages : 299
Détails du profil
Informations personnelles :
Nom : Homme Stéphane A.
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Secteur : Distribution

Informations forums :
Inscription : décembre 2008
Messages : 299
Points : 68
Points : 68
Par défaut Connexion impossible a mon espace securiser

Bonjour,

Je fais actuellement un espace memebre pour mnon site avec cakephp en suivant des tutoriel sur cake.
La je suis confronter un problème de connexion, impossible de me connecter malgrès que je met les bonne information. J'utilise le composant AUTH dans cakephp pour la connexion, ci dessous mes 3sripts:

UsersController.php
Code :
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
 
class UsersController extends AppController{
 
	function admin_index(){
		$d['users'] = $this->Paginate('User');
		$this->set($d);
	}
	function admin_edit($id = null){
		if($this->request->is('post') || $this->request->is('put')){
			$d = $this->request->data['User'];
				if($d['password'] != $d['passwordconfirm']){
					$this->Session->setflash("Les mots de passes ne correcpondent pas ","notif",array('type'=>'error'));
				}else{	
				if(empty($d['password']))
					unset($d['password']);
				$this->User->save($d);
				$this->Session->setflash("L'utilisateur a bien été enregistré ",'notif');
					}
		}elseif($id){
			$this->User->id = $id;
			$this->request->data = $this->User->read('id,username,role');	
		}
			$d = array();
			$d['roles'] = array(
				'admin' => 'admin',
				'user' => 'membre'			
			);
				$this->set($d);
	}
 
	function admin_delete($id){
		$this->User->delete($id);
		$this->Session->setflash("l'utilisateur a bien été supprimé ","notif");
		$this->redirect($this->referer());
	}
 
	function signup(){
		if($this->request->is('post')){
		$d = $this->request->data;
		$d['User']['id'] = null;		
			if(!empty($d['User']['password'])){
				$d['User']['password'] = Security::hash($d['User']['password'],null,true);	
				}	
			if($this->User->save($d,true,array('username','password','mail'))){
				$link =array('controller'=>'users','action'=>'activate',$this->User->id,'-'.md5($d['User']['password']));
				App::uses('CakeEmail','Network/Email');
				$mail = new CakeEmail();
				$mail->from('noreply@localhost.com')
					->to($d['User']['mail'])
					->subject('Test::Inscription')
					->emailFormat('html')
					->template('signup')
					->viewVars(array('username'=>$d['User']['username'],'link'=>$link))
					->send();			
				$this->Session->setFlash("Votre compte a bien été créé",'notif');
				$this->request->data = array();
			}else{
				$this->Session->setFlash("Merci de corriger les erreurs",'notif',array('type' =>'error'));
			}
		}
	}
	function  login(){
		if($this->request->is('post')){
			if($this->Auth->login()){
				$this->User->id = $this->Auth->user('id');
				$this->User->saveField('lastlogin',date('Y-m-d H:i:s'));
				$this->Session->setFlash("Vous êtres maintenant connecté",'notif');
				$this->redirect('/');
			}else{
				$this->Session->setFlash("Identifiant incorrecte",'notif',array('type'=>'error'));
				debug(Security::hash($this->request->data['User']['password']));
			}
		}
	}
	function membre_index(){
 
 
	}
	function subscribe(){
		if(!$this->Auth->user('id')){
			throw new NotfoundException();
			}
		if(!empty($this->request->data)){
		$duration = $this->request->data['duration'];
		$uid = $this->Auth->user('id');
			if(Configure:: read('Site.prices,$duration')){
			$price = number_format(Configure:: read('Site.prices,$duration'),2);
			$this->LoadModel('Transaction');
			$url = $this->Transaction->requestPaypal($price,"Compte prenium $duration mois","action=subscribe&uid=$uid&duration=$duration");
				if($url){
					$this->redirect($url);				
				}
			}
		}
	}
	function logout(){
		$this->Auth->logout();
		$this->redirect($this->referer());
		 /*$this->redirect($this->Auth->logout());*/
	}
	function password(){
	if(!empty($this->request->params['named']['token'])){
		$token = $this->request->params['named']['token'];
		$user = $this->User->find('first',array(
			'conditions' =>array('id' =>$token[0],'MD5(User.password)'=>$token[1], 'active' => 1)
			));
			if($user){
				$this->User->id =$user['User']['id'];
				$password = substr(MD5(uniqid(rand(),true)),0,8);
				$this->User->saveField('password',Securty::hash($password,null,true));
				$this->Session->setFlash("Votre mot de passe a bien été reinitialisé, voici votre nouveau mot de passe : $password",'notif');
			}else{
				$this->Session->setFlash("Le lien n'est pas valide",'notif', array('type'=>'error'));
 
			}
 
	}
		if($this->request->is('post')){
			$v = current($this->request->data);
			$user = $this->User->find('first',array(
			'conditions' => array('mail'=>$v['mail'],'active'=>1)
			));
				if(empty($users)){
					$this->Session->setFlash('Aucun utilisateur ne correspond à cet mail','notif', array('type'=>'error'));
				}else{
					App::uses('CakeEmail','Network/Email');
					$link =array('controller'=>'users','action'=>'password','token',$user['user']['id'],'-'.md5($user['User']['password']));
					$mail = new CakeEmail();
					$mail ->from('noreply@localhost.com')
						->to($user['User']['mail'])
						->subject('Test::Mot de passe oublié ?')
						->emailFormat('html')
						->template('mdp')
						->viewVars(array('username'=>$user['User']['username'],'link'=>$link))
						->send();		
			}
		}
	}
	function activate($token){
		$token = explode('-',$token);
		$user = $this->User->find('first',array(
			'conditions' =>array('id' =>$token[0],'MD5(User.password)'=>$token[1], 'active' => 0)		
		));
		If(!empty($user)){
			$this->User->id = $user['User']['id'];
			$this->User->saveField('active',1);
			$this->Session->setFlash("Votre compte a bien été activé",'notif');
			$this->Auth->login($user['User']);
		}else{
			$this->Session->setFlash("Ce lien d'activation n'est pas valide",'notif',array('type'=>'error'));		
			}
				$this->redirect('/');
				die();
 
	}
	public function edit() {
		$user_id = $this->Auth->user('id');
			if(!$user_id){
				$this->redirect('/');
				die();
			}
				$this->User->id = $user_id;
				$passError = false;
					if($this->request->is('put') || $this->request->is('post')){
						$d = $this->request->data;
						$d['User']['id'] = $user_id;
						if(!empty($d['User']['pass'])){
							if($d['User']['pass1'] == $d['User']['pass2']){
								$d['User']['password'] = Security::hash($d['User']['pass1'],null,true);						
							}else{
								$passError = true;
							}
						}	
							if($this->User->save($d,true,array('firstname','lastname','password'))){
								$this->Session->setFlash("Votre profit a bien été édité",'notif');						
							}else{
								$this->Session->setFlash("Impossible de sauvegarder",'notif',array('type'=>'error'));
						}
						if($passError)
 
						$this->User->validationErrors['pass2'] = array('les mots de passe ne correspondent pas');
					}else{
						$this->request->data = $this->User->read();
					}
					$this->request->data['User']['pass1'] = $this->request->data['User']['pass2'] = '';
			}
	}
?>
mon model : users.php
Code :
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
<?php
 
class User extends AppModel{
 
	public $validate = array(
		'username' => array(
			array(
			'rule' =>'alphanumeric',
			'required' =>true,
			'allowEmpty' => false,
			'message' => "Votre pseudo n'est pas valide")
		),
			array(
				'rule' => 'isUnique',
				'message' => "Ce pseudo est déja pris"
				),			
 
		'mail' => array(
			array(
			'rule' => 'email',
			'required' => true,
			'allowEmpty' => false,
			'message' => "Votre email n'est pas valide")
		),
			array(
				'rule' => 'isUnique',
				'message' => "Cet email est déja pris"
				),
 
		'password' => array(
				'rule' => 'notEmpty',
				'message' => "Vous devez entrer un mot de passe",
				'allowEmpty' => false
				)
		);
 
	function beforeSave($options = array()){
		if(!empty($this->data['User']['password'])){
			$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
			}
		return true;
	}
}
?>
et mon AppController.php
Code :
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
<?php
 
App::uses('Controller', 'Controller');
 
class AppController extends Controller {
 
	public $helpers = array('Text','Form','Html', 'Session', 'Date');
 
	public $components = array('Session','Cookie',
		'Auth' => array(
			'authenticate' =>array(
				'Form' => array(
					'scope'=>array('User.active'=>1)
					)
				)
			)		
	);
	function beforeFilter(){
	$this->Auth->loginAction =array('controller'=>'users','action'=>'login','admin'=>false);
/** Système d'authentification par controller*/
	$this->Auth->authorize= array('controller');
 
 
	if(!isset($this->request->params['prefix'])){
		$this->Auth->allow();
	}
		if(isset($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin'){
            $this->layout = 'admin';
		}
	}
	function isAuthorized($user){
		if(!isset($this->request->params['prefix'])){
			return true;
		}
		$roles = array(
			'admin'=> 10,
			'user' => 5
		);
			if(isset($roles[$this->request->params['prefix']])){
				$lvlAction = $roles[$this->request->params['prefix']];
				$lvlUser = $roles[$user['role']];
					if($lvlUser >= $lvlAction){
						return true;
					}else{
							return false;
					}
				}
				return false;
			}
}
Ca fais une semaine que j'essaie de trouver la solution et je suis bloquer dans l'avancement de mon projet

merci de votre aide

Runcafre91
runcafre91 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/02/2013, 21h16   #2
x-zolezzi
Membre confirmé
 
Homme Xavier ZOLEZZI
Étudiant
Inscription : juin 2008
Messages : 136
Détails du profil
Informations personnelles :
Nom : Homme Xavier ZOLEZZI
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2008
Messages : 136
Points : 235
Points : 235
Bonjour, je ne sais pas si c'est pas un peu tard, mais pourriez-vous mettre la structure de votre tables "users" ainsi que la ligne de votre utilisateur pour voir si tout est correct ?
__________________
Afin d'améliorer la qualité des forums pensez à marquer en lorsque le problème est clôturé.
Mais aussi d'indiquer les messages utiles [pouce vert] pour que les personnes ayant le même problème trouvent rapidement leur réponse.

Réalisation : http://www.batifac.com - Outil de devis & facture en ligne
x-zolezzi est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 01h19.


 
 
 
 
Partenaires

Hébergement Web