|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\PluginBundle\UserRemoteService; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* UserRemoteService. |
|
11
|
|
|
* |
|
12
|
|
|
* @ORM\Table(name="plugin_user_remote_service") |
|
13
|
|
|
* @ORM\Entity |
|
14
|
|
|
*/ |
|
15
|
|
|
class UserRemoteService |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var int |
|
19
|
|
|
* |
|
20
|
|
|
* @ORM\Column(name="id", type="integer") |
|
21
|
|
|
* @ORM\Id |
|
22
|
|
|
* @ORM\GeneratedValue |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $id; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
* |
|
29
|
|
|
* @ORM\Column(name="title", type="string", length=255, nullable=false) |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $title; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
* |
|
36
|
|
|
* @ORM\Column(name="url", type="string", length=255, nullable=false) |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $url; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return int |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getId() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->id; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param int $id |
|
50
|
|
|
* |
|
51
|
|
|
* @return $this |
|
52
|
|
|
*/ |
|
53
|
|
|
public function setId($id) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->id = $id; |
|
56
|
|
|
|
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getTitle() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->title; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param string $title |
|
70
|
|
|
* |
|
71
|
|
|
* @return UserRemoteService |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setTitle($title) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->title = $title; |
|
76
|
|
|
|
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getURL() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->url; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string $url |
|
90
|
|
|
* |
|
91
|
|
|
* @return UserRemoteService |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setURL($url) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->url = $url; |
|
96
|
|
|
|
|
97
|
|
|
return $this; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Returns a user-specific URL, with two extra query string parameters : 'username' and 'hash'. |
|
102
|
|
|
* 'hash' is generated using $salt and $userId. |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $username the URL query parameter 'username' |
|
105
|
|
|
* @param string $userId the user identifier, to build the hash |
|
106
|
|
|
* @param string $salt the salt, to build the hash |
|
107
|
|
|
* |
|
108
|
|
|
* @throws Exception on hash generation failure |
|
109
|
|
|
* |
|
110
|
|
|
* @return string the custom user URL |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getCustomUserURL($username, $userId, $salt) |
|
113
|
|
|
{ |
|
114
|
|
|
$hash = password_hash($salt.$userId, PASSWORD_BCRYPT); |
|
115
|
|
|
if (false === $hash) { |
|
116
|
|
|
throw new Exception('hash generation failed'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return sprintf( |
|
120
|
|
|
'%s%s%s', |
|
121
|
|
|
$this->url, |
|
122
|
|
|
false === strpos($this->url, '?') ? '?' : '&', |
|
123
|
|
|
http_build_query( |
|
124
|
|
|
[ |
|
125
|
|
|
'username' => $username, |
|
126
|
|
|
'hash' => $hash, |
|
127
|
|
|
] |
|
128
|
|
|
) |
|
129
|
|
|
); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|