Subversion Repositories Applications.annuaire

Rev

Rev 579 | Rev 583 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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