-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersonaUserIdentity.php
112 lines (99 loc) · 2.39 KB
/
PersonaUserIdentity.php
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
<?php
/**
* PersonaUserIdentity class implements from IUserIdentity
*
* @author Ruslan <KryDos> Bekenev <furyinbox@gmail.com>
* @license MIT https://raw.github.com/KryDos/persona-yii/master/LICENSE.txt
*/
class PersonaUserIdentity implements IUserIdentity
{
/**
* @var int $id current user id
*/
public $id;
/**
* @var string $_model_name model name where we will be do user search
*/
private $_model_name;
/**
* @var string $_email_field name of the email column in the table
*/
private $_email_field;
/**
* @var bool $_isAuthenticated
*/
private $_isAuthenticated = false;
/**
* @var string $_name name of the user.
*/
private $_name;
private $_states = array();
/**
* save model name and email field name
*/
function __construct($model_name = 'User', $email_field = 'email')
{
$this->_model_name = $model_name;
$this->_email_field = $email_field;
}
/**
* main function of this class.
* trying to find user by email
*
* @return bool
*/
public function authenticate()
{
$persona = new Persona();
$model = $this->_model_name;
$email_field = $this->_email_field;
if ($persona->isStatusSuccess()) {
$criteria = new CDbCriteria;
$criteria->compare($email_field, $persona->getEmail());
$user_model = $model::model()->find($criteria);
if($user_model == null)
return false;
$this->id = $user_model->id;
$this->_isAuthenticated = true;
//TODO name should me a real name or login or some readable user identifier
$this->_name = $user_model->$email_field;
return true;
}
else
return false;
}
/**
* get the user id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* get the auth status
*
* @return bool
*/
public function getIsAuthenticated()
{
return $this->_isAuthenticated;
}
/**
* get name of the user
*
* @return string email of the user
*/
public function getName()
{
return $this->_name;
}
/**
* @return empty array
*/
public function getPersistentStates()
{
return $this->_states;
}
}