| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4a9daa3 commit 1c8aa42
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,7 +64,7 @@ class ChangePasswordController( | |||
| 64 | 64 | val form = passwordForm.bindFromFlash.getOrElse(passwordForm) | |
| 65 | 65 | ||
| 66 | 66 | val idRequest = idRequestParser(request) | |
| 67 | - api.passwordExists(request.user.auth) map { | ||
| 67 | + api.passwordExists(request.user.auth, idRequest.trackingData) map { | ||
| 68 | 68 | result => | |
| 69 | 69 | val pwdExists = result.right.toOption contains true | |
| 70 | 70 | NoCache(Ok( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,13 +95,12 @@ class ResetPasswordController( | |||
| 95 | 95 | ||
| 96 | 96 | def onSuccess(form: (String, String, String, Option[String])): Future[Result] = form match { | |
| 97 | 97 | case (password, password_confirm, email_address, returnUrl) => | |
| 98 | - | ||
| 99 | - val authResponse = api.resetPassword(token,password) | ||
| 98 | + val idRequest = idRequestParser(request) | ||
| 99 | + val authResponse = api.resetPassword(token, password, idRequest.trackingData) | ||
| 100 | 100 | signInService.getCookies(authResponse, true) map { | |
| 101 | 101 | case Left(errors) => | |
| 102 | 102 | logger.info(s"reset password errors, ${errors.toString()}") | |
| 103 | 103 | if (errors.exists("Token expired" == _.message)) { | |
| 104 | - val idRequest = idRequestParser(request) | ||
| 105 | 104 | NoCache(SeeOther(idUrlBuilder.buildUrl("/reset/resend", idRequest))) | |
| 106 | 105 | } else { | |
| 107 | 106 | val formWithError = errors.foldLeft(requestPasswordResetForm) { (form, error) => | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,7 @@ class IdApiClient( | |||
| 35 | 35 | // AUTH | |
| 36 | 36 | def authBrowser(userAuth: Auth, trackingData: TrackingData, persistent: Option[Boolean] = None): Future[Response[CookiesResponse]] = { | |
| 37 | 37 | val params = buildParams(None, Some(trackingData), Seq("format" -> "cookies") ++ persistent.map("persistent" -> _.toString)) | |
| 38 | - val headers = buildHeaders(Some(userAuth)) | ||
| 38 | + val headers = buildHeaders(Some(userAuth), extra = xForwardedForHeader(trackingData)) | ||
| 39 | 39 | val body = write(userAuth) | |
| 40 | 40 | val response = httpClient.POST(apiUrl("auth"), Some(body), params, headers) | |
| 41 | 41 | response map extract(jsonField("cookies")) | |
@@ -95,16 +95,17 @@ class IdApiClient( | |||
| 95 | 95 | def register(user: User, trackingParameters: TrackingData, returnUrl: Option[String] = None): Future[Response[User]] = { | |
| 96 | 96 | val userData = write(user) | |
| 97 | 97 | val params = buildParams(tracking = Some(trackingParameters), extra = returnUrl.map(url => Iterable("returnUrl" -> url))) | |
| 98 | - val headers = buildHeaders(extra = trackingParameters.ipAddress.map(ip => Iterable("X-Forwarded-For" -> ip))) | ||
| 98 | + val headers = buildHeaders(extra = xForwardedForHeader(trackingParameters)) | ||
| 99 | 99 | val response = httpClient.POST(apiUrl("user"), Some(userData), params, headers) | |
| 100 | 100 | response map extractUser | |
| 101 | 101 | } | |
| 102 | 102 | ||
| 103 | 103 | // PASSWORD RESET/UPDATE | |
| 104 | 104 | ||
| 105 | - def passwordExists( auth: Auth ): Future[Response[Boolean]] = { | ||
| 105 | + def passwordExists(auth: Auth, trackingData: TrackingData): Future[Response[Boolean]] = { | ||
| 106 | 106 | val apiPath = urlJoin("user", "password-exists") | |
| 107 | - val response = httpClient.GET(apiUrl(apiPath), None, buildParams(Some(auth)), buildHeaders(Some(auth))) | ||
| 107 | + val headers = buildHeaders(Some(auth), extra = xForwardedForHeader(trackingData)) | ||
| 108 | + val response = httpClient.GET(apiUrl(apiPath), None, buildParams(Some(auth)), headers) | ||
| 108 | 109 | response map extract[Boolean](jsonField("passwordExists")) | |
| 109 | 110 | } | |
| 110 | 111 | ||
@@ -122,17 +123,18 @@ class IdApiClient( | |||
| 122 | 123 | response map extractUser | |
| 123 | 124 | } | |
| 124 | 125 | ||
| 125 | - def resetPassword( token : String, newPassword : String ): Future[Response[CookiesResponse]] = { | ||
| 126 | + def resetPassword( token : String, newPassword: String, trackingData: TrackingData): Future[Response[CookiesResponse]] = { | ||
| 126 | 127 | val apiPath = urlJoin("pwd-reset", "reset-pwd-for-user") | |
| 127 | 128 | val postBody = write(TokenPassword(token, newPassword)) | |
| 128 | - val response = httpClient.POST(apiUrl(apiPath), Some(postBody), clientAuth.parameters, clientAuth.headers) | ||
| 129 | + val headers = clientAuth.headers ++ buildHeaders(extra = xForwardedForHeader(trackingData)) | ||
| 130 | + val response = httpClient.POST(apiUrl(apiPath), Some(postBody), clientAuth.parameters, headers) | ||
| 129 | 131 | response map extract(jsonField("cookies")) | |
| 130 | 132 | } | |
| 131 | 133 | ||
| 132 | 134 | def sendPasswordResetEmail(emailAddress : String, trackingParameters: TrackingData): Future[Response[Unit]] = { | |
| 133 | 135 | val apiPath = urlJoin("pwd-reset", "send-password-reset-email") | |
| 134 | 136 | val params = buildParams(tracking = Some(trackingParameters), extra = Iterable("email-address" -> emailAddress, "type" -> "reset")) | |
| 135 | - val response = httpClient.GET(apiUrl(apiPath), None, params, buildHeaders()) | ||
| 137 | + val response = httpClient.GET(apiUrl(apiPath), None, params, buildHeaders(extra = xForwardedForHeader(trackingParameters))) | ||
| 136 | 138 | response map extractUnit | |
| 137 | 139 | } | |
| 138 | 140 | ||
@@ -141,7 +143,7 @@ class IdApiClient( | |||
| 141 | 143 | def userEmails(userId: String, trackingParameters: TrackingData): Future[Response[Subscriber]] = { | |
| 142 | 144 | val apiPath = urlJoin("useremails", userId) | |
| 143 | 145 | val params = buildParams(tracking = Some(trackingParameters)) | |
| 144 | - val response = httpClient.GET(apiUrl(apiPath), None, params, buildHeaders()) | ||
| 146 | + val response = httpClient.GET(apiUrl(apiPath), None, params, buildHeaders(extra = xForwardedForHeader(trackingParameters))) | ||
| 145 | 147 | response map extract(jsonField("result")) | |
| 146 | 148 | } | |
| 147 | 149 | ||
@@ -168,7 +170,13 @@ class IdApiClient( | |||
| 168 | 170 | ||
| 169 | 171 | def resendEmailValidationEmail(auth: Auth, trackingParameters: TrackingData, returnUrlOpt: Option[String]): Future[Response[Unit]] = { | |
| 170 | 172 | val extraParams = returnUrlOpt.map(url => List("returnUrl" -> url)) | |
| 171 | - httpClient.POST(apiUrl("user/send-validation-email"), None, buildParams(Some(auth), Some(trackingParameters), extraParams), buildHeaders(Some(auth))) map extractUnit | ||
| 173 | + httpClient | ||
| 174 | + .POST( | ||
| 175 | + apiUrl("user/send-validation-email"), | ||
| 176 | + None, | ||
| 177 | + buildParams(Some(auth), Some(trackingParameters), extraParams), | ||
| 178 | + buildHeaders(Some(auth), xForwardedForHeader(trackingParameters))) | ||
| 179 | + .map(extractUnit) | ||
| 172 | 180 | } | |
| 173 | 181 | ||
| 174 | 182 | def deleteTelephone(auth: Auth): Future[Response[Unit]] = | |
@@ -197,8 +205,13 @@ class IdApiClient( | |||
| 197 | 205 | def post(apiPath: String, | |
| 198 | 206 | auth: Option[Auth] = None, | |
| 199 | 207 | trackingParameters: Option[TrackingData] = None, | |
| 200 | - body: Option[String] = None): Future[Response[HttpResponse]] = | ||
| 201 | - httpClient.POST(apiUrl(apiPath), body, buildParams(auth, trackingParameters), buildHeaders(auth)) | ||
| 208 | + body: Option[String] = None): Future[Response[HttpResponse]] = { | ||
| 209 | + httpClient.POST( | ||
| 210 | + apiUrl(apiPath), | ||
| 211 | + body, | ||
| 212 | + buildParams(auth, trackingParameters), | ||
| 213 | + buildHeaders(auth, trackingParameters.map(xForwardedForHeader))) | ||
| 214 | + } | ||
| 202 | 215 | ||
| 203 | 216 | def delete(apiPath: String, | |
| 204 | 217 | auth: Option[Auth] = None, | |
@@ -213,11 +226,7 @@ class IdApiClient( | |||
| 213 | 226 | private def buildParams(auth: Option[Auth] = None, | |
| 214 | 227 | tracking: Option[TrackingData] = None, | |
| 215 | 228 | extra: Parameters = Iterable.empty): Parameters = { | |
| 216 | - extra ++ clientAuth.parameters ++ | ||
| 217 | - auth.map(_.parameters) ++ | ||
| 218 | - tracking.map({ trackingData => | ||
| 219 | - trackingData.parameters ++ trackingData.ipAddress.map(ip => "ip" -> ip) | ||
| 220 | - }) | ||
| 229 | + extra ++ clientAuth.parameters ++ auth.map(_.parameters) | ||
| 221 | 230 | } | |
| 222 | 231 | ||
| 223 | 232 | private def buildHeaders(auth: Option[Auth] = None, extra: Parameters = Iterable.empty): Parameters = { | |
@@ -231,6 +240,12 @@ class IdApiClient( | |||
| 231 | 240 | slug.stripPrefix("/").stripSuffix("/") | |
| 232 | 241 | }) mkString "/" | |
| 233 | 242 | } | |
| 243 | + | ||
| 244 | + private def xForwardedForHeader(trackingParameters: TrackingData): Parameters = | ||
| 245 | + trackingParameters | ||
| 246 | + .ipAddress | ||
| 247 | + .map(ip => Iterable("X-Forwarded-For" -> ip)) | ||
| 248 | + .getOrElse(Iterable.empty) | ||
| 234 | 249 | } | |
| 235 | 250 | ||
| 236 | 251 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,12 +97,12 @@ class ResetPasswordControllerTest | |||
| 97 | 97 | ||
| 98 | 98 | val fakeRequest = FakeRequest(POST, "/reset_password" ).withFormUrlEncodedBody("password" -> "newpassword", "password-confirm" -> "newpassword", "email-address" -> "test@somewhere.com") | |
| 99 | 99 | "when the token provided is valid" - { | |
| 100 | - when(api.resetPassword(MockitoMatchers.any[String], MockitoMatchers.any[String])).thenReturn(Future.successful(Right(cookieResponse))) | ||
| 100 | + when(api.resetPassword(MockitoMatchers.any[String], MockitoMatchers.any[String], MockitoMatchers.any[TrackingData])).thenReturn(Future.successful(Right(cookieResponse))) | ||
| 101 | 101 | when(signInService.getCookies(MockitoMatchers.any[Future[Response[CookiesResponse]]], MockitoMatchers.anyBoolean())(MockitoMatchers.any[ExecutionContext])).thenReturn(Future.successful(Right(cookieList))) | |
| 102 | 102 | ||
| 103 | 103 | "should call the api the password with the provided new password and token" in Fake { | |
| 104 | 104 | resetPasswordController.resetPassword("1234", None)(fakeRequest) | |
| 105 | - verify(api).resetPassword(MockitoMatchers.eq("1234"), MockitoMatchers.eq("newpassword")) | ||
| 105 | + verify(api).resetPassword(MockitoMatchers.eq("1234"), MockitoMatchers.eq("newpassword"), MockitoMatchers.eq(identityRequest.trackingData)) | ||
| 106 | 106 | } | |
| 107 | 107 | "should return password confirmation view in" in Fake { | |
| 108 | 108 | val result = resetPasswordController.resetPassword("1234", None)(fakeRequest) | |
@@ -112,10 +112,10 @@ class ResetPasswordControllerTest | |||
| 112 | 112 | } | |
| 113 | 113 | ||
| 114 | 114 | "when the reset token has expired" - { | |
| 115 | - when(api.resetPassword(MockitoMatchers.any[String], MockitoMatchers.any[String])).thenReturn(Future.successful(Right(cookieResponse))) | ||
| 115 | + when(api.resetPassword(MockitoMatchers.any[String], MockitoMatchers.any[String], MockitoMatchers.any[TrackingData])).thenReturn(Future.successful(Right(cookieResponse))) | ||
| 116 | 116 | when(signInService.getCookies(MockitoMatchers.any[Future[Response[CookiesResponse]]], MockitoMatchers.anyBoolean())(MockitoMatchers.any[ExecutionContext])).thenReturn(Future.successful(Left(tokenExpired))) | |
| 117 | 117 | ||
| 118 | - when(api.resetPassword("1234","newpassword")).thenReturn(Future.successful(Left(tokenExpired))) | ||
| 118 | + when(api.resetPassword("1234","newpassword", identityRequest.trackingData)).thenReturn(Future.successful(Left(tokenExpired))) | ||
| 119 | 119 | "should redirect to request request new password with a token expired" in Fake { | |
| 120 | 120 | val result = resetPasswordController.resetPassword("1234", None)(fakeRequest) | |
| 121 | 121 | status(result) should equal(SEE_OTHER) | |
@@ -126,7 +126,7 @@ class ResetPasswordControllerTest | |||
| 126 | 126 | "when the reset token is not valid" - { | |
| 127 | 127 | when(signInService.getCookies(MockitoMatchers.any[Future[Response[CookiesResponse]]], MockitoMatchers.anyBoolean())(MockitoMatchers.any[ExecutionContext])).thenReturn(Future.successful(Left(accesssDenied))) | |
| 128 | 128 | ||
| 129 | - when(api.resetPassword("1234", "newpassword")).thenReturn(Future.successful(Left(accesssDenied))) | ||
| 129 | + when(api.resetPassword("1234", "newpassword", identityRequest.trackingData)).thenReturn(Future.successful(Left(accesssDenied))) | ||
| 130 | 130 | "should redirect to request new password with a problem resetting your password" in Fake { | |
| 131 | 131 | val result = resetPasswordController.resetPassword("1234", None)(fakeRequest) | |
| 132 | 132 | status(result) should equal(SEE_OTHER) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments