Subversion Repositories Applications.annuaire

Rev

Rev 587 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 587 Rev 616
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
11
		$login = urlencode($login); // pour les espaces dans le nom d'utilisateur
12
		$password = urlencode($password);
12
		$password = urlencode($password);
13
		$url = "http://identify.plantnet-project.org/api/security/token/create?_username=$login&_password=$password";
13
		$url = "http://identify.plantnet-project.org/api/security/token/create?_username=$login&_password=$password";
14
 
14
 
15
		$curl = curl_init();
15
		$curl = curl_init();
16
		curl_setopt($curl, CURLOPT_URL, $url);
16
		curl_setopt($curl, CURLOPT_URL, $url);
17
		curl_setopt($curl, CURLOPT_POST, true);
17
		curl_setopt($curl, CURLOPT_POST, true);
18
		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 !
19
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
19
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
20
		$res = curl_exec($curl);
20
		$res = curl_exec($curl);
21
		curl_close($curl);
21
		curl_close($curl);
22
 
22
 
23
		// var_dump($res); exit;
23
		// var_dump($res); exit;
24
		$res = json_decode($res, true);
24
		$res = json_decode($res, true);
25
		//var_dump($res);
25
		//var_dump($res);
26
		if (!empty($res['JWT'])) {
26
		if (!empty($res['JWT'])) {
27
			$this->jetonPartenaire = $res['JWT'];
27
			$this->jetonPartenaire = $res['JWT'];
28
			$jetonDecode = $this->auth->decoderJetonManuellement($this->jetonPartenaire);
28
			$jetonDecode = $this->auth->decoderJetonManuellement($this->jetonPartenaire);
29
			// stockage pour traitement dans les autres méthodes
29
			// stockage pour traitement dans les autres méthodes
30
			$this->data = $jetonDecode['details'];
30
			$this->data = $jetonDecode['details'];
31
			//var_dump($jeton);
31
			//var_dump($jeton);
32
			if ( !empty($this->data['email'])) {
32
			if ( !empty($this->data['email'])) {
33
				//var_dump($this->data['email']);
33
				//var_dump($this->data['email']);
34
				return true;
34
				return true;
35
			}
35
			}
36
		}
36
		}
37
		return false;
37
		return false;
38
	}
38
	}
39
 
39
 
40
	protected function getNomPartenaire() {
40
	protected function getNomPartenaire() {
41
		return "plantnet";
41
		return "plantnet";
42
	}
42
	}
43
 
43
 
44
	public function getCourriel() {
44
	public function getCourriel() {
45
		return $this->data['email'];
45
		return $this->data['email'];
46
	}
46
	}
47
 
47
 
48
	protected function getId() {
48
	protected function getId() {
49
		// la clef primaire est le "username" dans Pl@ntNet, apparemment
49
		// la clef primaire est le "username" dans Pl@ntNet, apparemment
50
		return $this->data['username'];
50
		return $this->data['username'];
51
	}
51
	}
52
 
52
 
53
	protected function getValeursProfilPartenaire() {
53
	protected function getValeursProfilPartenaire() {
54
		return array(
54
		return array(
55
			'nom' => $this->data['lastname'],
55
			'nom' => $this->data['lastname'],
56
			'prenom' => $this->data['firstname'],
56
			'prenom' => $this->data['firstname'],
57
			'email' => $this->data['email'],
57
			'email' => $this->data['email'],
58
			'pseudo' => $this->data['username']
58
			'pseudo' => $this->data['username']
59
		);
59
		);
60
	}
60
	}
61
 
61
 
62
	/*public function getTimestampMajPartenaire() {
62
	/*public function getTimestampMajPartenaire() {
63
		return 420000000000;
63
		return 420000000000;
64
	}*/
64
	}*/
65
}
65
}