1 | <?php |
||
7 | class ProfileController extends HTMLController |
||
8 | { |
||
9 | 1 | public function setup() |
|
13 | |||
14 | /** |
||
15 | * Edit a profile |
||
16 | * |
||
17 | * @param Player $me The player's profile to edit |
||
18 | * @param Request $request |
||
19 | * @param bool $self Whether a player is editing their own profile, |
||
20 | * instead of an admin editing another player's |
||
21 | * profile |
||
22 | * @return array |
||
23 | */ |
||
24 | public function editAction(Player $me, Request $request, $self = true) |
||
25 | { |
||
26 | $creator = new ProfileFormCreator($me); |
||
27 | $creator->setEditingSelf($self); |
||
28 | $form = $creator->create()->handleRequest($request); |
||
29 | |||
30 | if ($form->isValid()) { |
||
31 | if (!$self && $form->has('verify_email') && $form->get('verify_email')->isClicked()) { |
||
32 | // An admin is editing a form and has chosen to verify a |
||
33 | // player's e-mail address |
||
34 | $me->setVerified(true); |
||
35 | |||
36 | // Reset the form so that the "verify email" button gets hidden |
||
37 | $form = $creator->create()->handleRequest($request); |
||
38 | } else { |
||
39 | $creator->update($form, $me); |
||
40 | |||
41 | $email = $form->get('email')->getData(); |
||
42 | if ($email !== $me->getEmailAddress()) { |
||
43 | // User has changed their address, send a confirmation mail |
||
44 | $me->setEmailAddress($email); |
||
45 | |||
46 | if ($self) { |
||
47 | $this->sendConfirmationMessage($me); |
||
48 | } else { |
||
49 | // Admins can set users' e-mail addresses at will, without |
||
50 | // having to send them confirmation messages |
||
51 | $me->setVerified(true); |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | $message = ($self) ? "Your profile has been updated." : $me->getUsername() . "'s profile has been updated."; |
||
57 | $this->getFlashBag()->add("success", $message); |
||
58 | } |
||
59 | |||
60 | return $this->render('Profile/edit.html.twig', array( |
||
61 | "editingSelf" => $self, |
||
62 | "player" => $me, |
||
63 | "form" => $form->createView() |
||
64 | )); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @todo Expire verification codes |
||
69 | */ |
||
70 | public function confirmAction(Player $me, $token) |
||
90 | |||
91 | public function showAction(Player $me) |
||
95 | |||
96 | /** |
||
97 | * Send a confirmation e-mail to a player |
||
98 | * @param Player $player The receiving player |
||
99 | */ |
||
100 | private function sendConfirmationMessage($player) |
||
129 | } |
||
130 |