Skip to content

Commit 72add8d

Browse files
committed
some way towards translations
1 parent ae3614b commit 72add8d

File tree

6 files changed

+71
-47
lines changed

6 files changed

+71
-47
lines changed

composer.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AppBundle/Controller/RestPasswordManagementController.php

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ public function requestResetAction(Request $request)
4949
}
5050

5151
if (null === $user) {
52-
return new JsonResponse(['Invalid username' => $username], Response::HTTP_FORBIDDEN);
52+
return new JsonResponse(
53+
$this->get('translator')->trans(
54+
'resetting.request.invalid_username',
55+
[ '%username%' => $username ],
56+
'FOSUserBundle'
57+
),
58+
Response::HTTP_FORBIDDEN
59+
);
5360
}
5461

5562
$event = new GetResponseUserEvent($user, $request);
@@ -60,9 +67,10 @@ public function requestResetAction(Request $request)
6067
}
6168

6269
if ($user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
63-
return new JsonResponse(sprintf('Password reset request is already in progress. Please check your email: %s',
64-
$this->getObfuscatedEmail($user)
65-
), Response::HTTP_FORBIDDEN);
70+
return new JsonResponse(
71+
$this->get('translator')->trans('resetting.password_already_requested', [], 'FOSUserBundle'),
72+
Response::HTTP_FORBIDDEN
73+
);
6674
}
6775

6876
if (null === $user->getConfirmationToken()) {
@@ -92,9 +100,14 @@ public function requestResetAction(Request $request)
92100
return $event->getResponse();
93101
}
94102

95-
return new JsonResponse(sprintf('Password reset request accepted, please check your email: %s',
96-
$this->getObfuscatedEmail($user)
97-
));
103+
return new JsonResponse(
104+
$this->get('translator')->trans(
105+
'resetting.check_email',
106+
[ '%email%' => $this->getObfuscatedEmail($user) ],
107+
'FOSUserBundle'
108+
),
109+
Response::HTTP_OK
110+
);
98111
}
99112

100113
/**
@@ -120,6 +133,7 @@ public function confirmResetAction(Request $request)
120133

121134
if (null === $user) {
122135
return new JsonResponse(
136+
// no translation provided for this in \FOS\UserBundle\Controller\ResettingController
123137
sprintf('The user with "confirmation token" does not exist for value "%s"', $token),
124138
Response::HTTP_BAD_REQUEST
125139
);
@@ -149,13 +163,19 @@ public function confirmResetAction(Request $request)
149163
$userManager->updateUser($user);
150164

151165
if (null === $response = $event->getResponse()) {
152-
return new JsonResponse('Successfully updated password', Response::HTTP_OK);
166+
return new JsonResponse(
167+
$this->get('translator')->trans('resetting.flash.success', [], 'FOSUserBundle'),
168+
Response::HTTP_OK
169+
);
153170
}
154171

155172
// unsure if this is now needed / will work the same
156173
$dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
157174

158-
return new JsonResponse('Successfully updated password', Response::HTTP_OK);
175+
return new JsonResponse(
176+
$this->get('translator')->trans('resetting.flash.success', [], 'FOSUserBundle'),
177+
Response::HTTP_OK
178+
);
159179
}
160180

161181
/**
@@ -224,11 +244,17 @@ public function changeAction(Request $request, UserInterface $user)
224244
$userManager->updateUser($user);
225245

226246
if (null === $response = $event->getResponse()) {
227-
return new JsonResponse('Successfully updated password', Response::HTTP_OK);
247+
return new JsonResponse(
248+
$this->get('translator')->trans('change_password.flash.success', [], 'FOSUserBundle'),
249+
Response::HTTP_OK
250+
);
228251
}
229252

230253
$dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
231254

232-
return new JsonResponse('Successfully updated password', Response::HTTP_OK);
255+
return new JsonResponse(
256+
$this->get('translator')->trans('change_password.flash.success', [], 'FOSUserBundle'),
257+
Response::HTTP_OK
258+
);
233259
}
234260
}

src/AppBundle/Features/Context/RestApiContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public function theResponseCodeShouldBe($code)
291291
*
292292
* @param string $text
293293
*
294-
* @Then /^(?:the )?response should contain "([^"]*)"$/
294+
* @Then /^(?:the )?response should contain "((?:[^"]|\\")*)"$/
295295
*/
296296
public function theResponseShouldContain($text)
297297
{

src/AppBundle/Features/password_change.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Feature: Handle password changing via the RESTful API
5353
}
5454
"""
5555
Then the response code should be 200
56-
And the response should contain "Successfully updated password"
56+
And the response should contain "The password has been changed"
5757

5858
Scenario: Cannot change password with bad current password
5959
When I am successfully logged in with username: "peter", and password: "testpass"
@@ -68,7 +68,7 @@ Feature: Handle password changing via the RESTful API
6868
}
6969
"""
7070
Then the response code should be 400
71-
And the response should contain "This value should be the user's current password."
71+
And the response should contain "This value should be the user's current password."
7272

7373
Scenario: Cannot change password with mismatched new password
7474
When I am successfully logged in with username: "peter", and password: "testpass"

src/AppBundle/Features/password_reset.feature

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,30 @@ Feature: Handle password changing via the RESTful API
1616
############################
1717
## Password Reset Request ##
1818
############################
19-
2019
Scenario: Cannot request a password reset for an invalid username
2120
When I send a "POST" request to "/password/reset/request" with body:
2221
"""
2322
{ "username": "davey" }
2423
"""
2524
Then the response code should be 403
26-
And the response should contain "Invalid username"
25+
And the response should contain "The username or email address \u0022davey\u0022 does not exist"
26+
# silly
2727

28-
@this
2928
Scenario: Can request a password reset for a valid username
3029
When I send a "POST" request to "/password/reset/request" with body:
3130
"""
3231
{ "username": "peter" }
3332
"""
3433
Then the response code should be 200
35-
And the response should contain "Password reset request accepted, please check your email"
34+
And the response should contain "An email has been sent to ...@test.com. It contains a link you must click to reset your password."
3635

3736
Scenario: Cannot request another password reset for an account already requesting, but not yet actioning the reset request
3837
When I send a "POST" request to "/password/reset/request" with body:
3938
"""
4039
{ "username": "john" }
4140
"""
4241
Then the response code should be 403
43-
And the response should contain "Password reset request is already in progress. Please check your email"
42+
And the response should contain "The password for this user has already been requested within the last 24 hours."
4443

4544

4645

@@ -102,7 +101,7 @@ Feature: Handle password changing via the RESTful API
102101
}
103102
"""
104103
Then the response code should be 200
105-
And the response should contain "Successfully updated password"
104+
And the response should contain "The password has been reset successfully"
106105
And I send a "POST" request to "/login" with body:
107106
"""
108107
{

src/AppBundle/Features/profile.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Feature: Manage User profile data via the RESTful API
4545
"""
4646
Then the response code should be 400
4747

48-
@fail
4948
Scenario: Can replace their own profile
5049
When I send a "PUT" request to "/profile/1" with body:
5150
"""

0 commit comments

Comments
 (0)