1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpDraft\Controllers\Commish; |
4
|
|
|
|
5
|
|
|
use \Silex\Application; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
8
|
|
|
use PhpDraft\Domain\Models\UserProfile; |
9
|
|
|
use PhpDraft\Domain\Entities\LoginUser; |
10
|
|
|
use PhpDraft\Domain\Models\PhpDraftResponse; |
11
|
|
|
|
12
|
|
|
class UserProfileController { |
13
|
|
|
public function Get(Application $app, Request $request) { |
|
|
|
|
14
|
|
|
$user = $app['phpdraft.LoginUserService']->GetCurrentUser(); |
15
|
|
|
|
16
|
|
|
if (empty($user)) { |
17
|
|
|
return $app->json(new PhpDraftResponse(false)); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
return $app->json(new UserProfile($user->id, $user->email, $user->name), Response::HTTP_OK); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function Put(Application $app, Request $request) { |
24
|
|
|
$validity = $app['phpdraft.LoginUserValidator']->IsUserProfileUpdateValid($request); |
25
|
|
|
|
26
|
|
|
if (!$validity->success) { |
27
|
|
|
return $app->json($validity, Response::HTTP_BAD_REQUEST); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$response = $app['phpdraft.LoginUserService']->UpdateUserProfile($request); |
31
|
|
|
|
32
|
|
|
return $app->json($response, $response->responseType()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function InviteNewCommissioner(Application $app, Request $request) { |
36
|
|
|
$user = new LoginUser(); |
37
|
|
|
|
38
|
|
|
$user->enabled = 0; |
39
|
|
|
$user->email = $request->get('email'); |
40
|
|
|
$user->name = $request->get('name'); |
41
|
|
|
|
42
|
|
|
$message = $request->get('message'); |
43
|
|
|
|
44
|
|
|
$validity = $app['phpdraft.LoginUserValidator']->isInviteNewUserValid($user, $message); |
45
|
|
|
|
46
|
|
|
if (!$validity->success) { |
47
|
|
|
return $app->json($validity, $validity->responseType()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$response = $app['phpdraft.UsersService']->InviteNewUser($user, $message); |
51
|
|
|
|
52
|
|
|
return $app->json($response, $response->responseType()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.