|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpDraft\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use \Silex\Application; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
use PhpDraft\Domain\Models\PhpDraftResponse; |
|
9
|
|
|
use PhpDraft\Domain\Entities\Draft; |
|
10
|
|
|
|
|
11
|
|
|
class UserController |
|
12
|
|
|
{ |
|
13
|
|
|
public function Get(Application $app, Request $request) { |
|
|
|
|
|
|
14
|
|
|
$response = $app['phpdraft.LoginUserService']->GetAll(); |
|
15
|
|
|
|
|
16
|
|
|
return $app->json($response, $response->responseType()); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function Update(Application $app, Request $request) { |
|
20
|
|
|
$user_id = $request->get('id'); |
|
21
|
|
|
$user = $app['phpdraft.LoginUserRepository']->LoadById($user_id); |
|
22
|
|
|
$user->email = $request->get('email'); |
|
23
|
|
|
$user->name = $request->get('name'); |
|
24
|
|
|
$user->roles = $request->get('roles'); |
|
25
|
|
|
|
|
26
|
|
|
//Coerce down to a 1 or 0 type |
|
27
|
|
|
$enabVal = $request->get('enabled'); |
|
|
|
|
|
|
28
|
|
|
$enabled = $request->get('enabled') == true; |
|
29
|
|
|
$user->enabled = $enabled ? 1 : 0; |
|
30
|
|
|
|
|
31
|
|
|
$validity = $app['phpdraft.LoginUserValidator']->IsAdminUserUpdateValid($user); |
|
32
|
|
|
|
|
33
|
|
|
if(!$validity->success) { |
|
34
|
|
|
return $app->json($validity, $validity->responseType()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$app['phpdraft.LoginUserRepository']->Update($user); |
|
38
|
|
|
|
|
39
|
|
|
$response = new PhpDraftResponse(true, array()); |
|
40
|
|
|
|
|
41
|
|
|
return $app->json($response, $response->responseType()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function Delete(Application $app, Request $request) { |
|
45
|
|
|
$user_id = $request->get('user_id'); |
|
46
|
|
|
$user = $app['phpdraft.LoginUserRepository']->LoadById($user_id); |
|
47
|
|
|
|
|
48
|
|
|
if($app['phpdraft.LoginUserService']->CurrentUserIsAdmin($user)) { |
|
49
|
|
|
$response = new PhpDraftResponse(false, array()); |
|
50
|
|
|
$response->errors[] = "Unable to delete user - user is admin."; |
|
51
|
|
|
|
|
52
|
|
|
return $app->json($response, $response->responseType()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$response = $app['phpdraft.LoginUserService']->DeleteUser($user); |
|
56
|
|
|
|
|
57
|
|
|
return $app->json($response, $response->responseType()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.