Subversion Repositories Applications.annuaire

Rev

Rev 580 | Rev 587 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 580 Rev 583
1
<?php
1
<?php
2
 
2
 
3
require "AuthPartner.php";
3
require "AuthPartner.php";
4
 
4
 
5
/**
5
/**
6
 * Permet de se connecter à l'annuaire de Tela Botanica à l'aide d'un compte Pl@ntNet / identify
6
 * Permet de se connecter à l'annuaire de Tela Botanica à l'aide d'un compte Pl@ntNet / identify
7
 */
7
 */
8
class AuthPartnerPlantnet extends	AuthPartner {
8
class AuthPartnerPlantnet extends	AuthPartner {
9
 
9
 
10
	public function verifierAcces($login, $password) {
10
	public function verifierAcces($login, $password) {
-
 
11
		$login = urlencode($login); // pour les espaces dans le nom d'utilisateur
-
 
12
		$password = urlencode($password);
11
		$url = "http://identify-test.plantnet-project.org/api/security/token/create?_username=$login&_password=$password";
13
		$url = "http://identify-test.plantnet-project.org/api/security/token/create?_username=$login&_password=$password";
12
 
14
 
13
		$curl = curl_init();
15
		$curl = curl_init();
14
		curl_setopt($curl, CURLOPT_URL, $url);
16
		curl_setopt($curl, CURLOPT_URL, $url);
15
		curl_setopt($curl, CURLOPT_POST, true);
17
		curl_setopt($curl, CURLOPT_POST, true);
16
		curl_setopt($curl, CURLOPT_POSTFIELDS, array()); // nécessaire dans les versions modernes de libcurl sinon on se prend un 400 !
18
		curl_setopt($curl, CURLOPT_POSTFIELDS, array()); // nécessaire dans les versions modernes de libcurl sinon on se prend un 400 !
17
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
19
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
18
		$res = curl_exec($curl);
20
		$res = curl_exec($curl);
19
		curl_close($curl);
21
		curl_close($curl);
20
 
22
 
21
		//var_dump($res);
23
		// var_dump($res); exit;
22
		$res = json_decode($res, true);
24
		$res = json_decode($res, true);
23
		//var_dump($res);
25
		//var_dump($res);
24
		if (!empty($res['JWT'])) {
26
		if (!empty($res['JWT'])) {
25
			$this->jetonPartenaire = $res['JWT'];
27
			$this->jetonPartenaire = $res['JWT'];
26
			$jetonDecode = $this->auth->decoderJetonManuellement($this->jetonPartenaire);
28
			$jetonDecode = $this->auth->decoderJetonManuellement($this->jetonPartenaire);
27
			// stockage pour traitement dans les autres méthodes
29
			// stockage pour traitement dans les autres méthodes
28
			$this->data = $jetonDecode['details'];
30
			$this->data = $jetonDecode['details'];
29
			//var_dump($jeton);
31
			//var_dump($jeton);
30
			if ( !empty($this->data['email'])) {
32
			if ( !empty($this->data['email'])) {
31
				//var_dump($this->data['email']);
33
				//var_dump($this->data['email']);
32
				return true;
34
				return true;
33
			}
35
			}
34
		}
36
		}
35
		return false;
37
		return false;
36
	}
38
	}
37
 
39
 
38
	protected function getNomPartenaire() {
40
	protected function getNomPartenaire() {
39
		return "plantnet";
41
		return "plantnet";
40
	}
42
	}
41
 
43
 
42
	protected function getCourriel() {
44
	public function getCourriel() {
43
		return $this->data['email'];
45
		return $this->data['email'];
44
	}
46
	}
45
 
47
 
46
	protected function getId() {
48
	protected function getId() {
47
		// la clef primaire est le "username" dans Pl@ntNet, apparemment
49
		// la clef primaire est le "username" dans Pl@ntNet, apparemment
48
		return $this->data['username'];
50
		return $this->data['username'];
49
	}
51
	}
50
 
52
 
51
	protected function getValeursProfilPartenaire() {
53
	protected function getValeursProfilPartenaire() {
52
		return array(
54
		return array(
53
			'nom' => $this->data['lastname'],
55
			'nom' => $this->data['lastname'],
54
			'prenom' => $this->data['firstname'],
56
			'prenom' => $this->data['firstname'],
55
			'email' => $this->data['email'],
57
			'email' => $this->data['email'],
56
			'pseudo' => $this->data['username']
58
			'pseudo' => $this->data['username']
57
		);
59
		);
58
	}
60
	}
59
 
61
 
60
	/*public function getTimestampMajPartenaire() {
62
	/*public function getTimestampMajPartenaire() {
61
		return 420000000000;
63
		return 420000000000;
62
	}*/
64
	}*/
63
}
65
}