|
1
|
|
|
<?php |
|
2
|
|
|
class PendingUserAPI extends ProfilesAdminAPI |
|
3
|
|
|
{ |
|
4
|
|
|
public function setup($app) |
|
5
|
|
|
{ |
|
6
|
|
|
$app->get('[/]', array($this, 'listPendingUsers')); |
|
7
|
|
|
$app->get('/{hash}[/]', array($this, 'showPendingUser')); |
|
8
|
|
|
$app->delete('/{hash}[/]', array($this, 'deletePendingUser')); |
|
9
|
|
|
$app->map(['GET', 'POST'], '/{hash}/Actions/activate[/]', array($this, 'activatePendingUser')); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
public function listPendingUsers($request, $response, $args) |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
$this->validateIsAdmin($request); |
|
15
|
|
|
$odata = $request->getAttribute('odata', new \ODataParams(array())); |
|
16
|
|
|
$auth = AuthProvider::getInstance(); |
|
17
|
|
|
$users = $auth->getPendingUsersByFilter($odata->filter, $odata->select, $odata->top, $odata->skip, |
|
18
|
|
|
$odata->orderby); |
|
19
|
|
|
return $response->withJson($users); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function showPendingUser($request, $response, $args) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->validateIsAdmin($request); |
|
25
|
|
|
$user = \AuthProvider::getInstance()->getPendingUsersByFilter(new \Data\Filter("hash eq '".$args['hash']."'")); |
|
26
|
|
|
if($user === false) |
|
27
|
|
|
{ |
|
28
|
|
|
return $response->withStatus(404); |
|
29
|
|
|
} |
|
30
|
|
|
if(!is_object($user) && isset($user[0])) |
|
31
|
|
|
{ |
|
32
|
|
|
$user = $user[0]; |
|
33
|
|
|
} |
|
34
|
|
|
return $response->withJson($user); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function deletePendingUser($request, $response, $args) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->validateIsAdmin($request); |
|
40
|
|
|
$auth = \AuthProvider::getInstance(); |
|
41
|
|
|
$res = $auth->deletePendingUsersByFilter(new \Data\Filter("hash eq '".$args['hash']."'")); |
|
42
|
|
|
return $response->withJson($res); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function activatePendingUser($request, $response, $args) |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
$user = $request->getAttribute('user'); |
|
48
|
|
|
if($user === false) |
|
49
|
|
|
{ |
|
50
|
|
|
throw new Exception('Must be logged in', \Http\Rest\ACCESS_DENIED); |
|
51
|
|
|
} |
|
52
|
|
|
$auth = \AuthProvider::getInstance(); |
|
53
|
|
|
$user = $auth->getPendingUsersByFilter(new \Data\Filter("hash eq '$hash'")); |
|
|
|
|
|
|
54
|
|
|
if($user === false || !isset($user[0])) |
|
55
|
|
|
{ |
|
56
|
|
|
return $response->withStatus(404); |
|
57
|
|
|
} |
|
58
|
|
|
$res = $auth->activatePendingUser($user[0]); |
|
59
|
|
|
if($request->isGet()) |
|
60
|
|
|
{ |
|
61
|
|
|
$uri = '../../activate_error.php'; |
|
62
|
|
|
if($res) |
|
63
|
|
|
{ |
|
64
|
|
|
$uri = '../../'; |
|
65
|
|
|
} |
|
66
|
|
|
return $response->withStatus(302)->withHeader('Location', $uri); |
|
67
|
|
|
} |
|
68
|
|
|
else |
|
69
|
|
|
{ |
|
70
|
|
|
return $response->withJson($res); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
|
75
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.