Skip to content

Commit 7e95c26

Browse files
Merge pull request guardian#24082 from guardian/bt/remove-change-password-page
Remove change password page
2 parents 0b01b40 + e9820f1 commit 7e95c26

16 files changed

+37
-359
lines changed

common/app/navigation/AuthenticationComponentEvent.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ object AuthenticationComponentEvent {
1010
case object RegisterToRecommend extends ComponentEventId("register_to_recommend_comment")
1111
case object SigninRedirect extends ComponentEventId("signin_redirect_for_action")
1212
case object SigninFromFormStack extends ComponentEventId("signin_from_formstack")
13-
case object SigninFromPasswordResetConfirmation extends ComponentEventId("signin_from_password_reset_confirmation")
1413

1514
def createAuthenticationComponentEventParams(componentEventId: ComponentEventId): String =
1615
createAuthenticationComponentEventTuple(componentEventId) match {
Lines changed: 6 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,22 @@
11
package controllers
22

33
import common.ImplicitControllerExecutionContext
4-
import model.{ApplicationContext, IdentityPage, NoCache, ReturnJourney}
4+
import model.ApplicationContext
5+
import play.api.http.HttpConfiguration
56
import play.api.mvc._
6-
import play.api.data.{Form, Forms}
7-
import play.api.data.Forms._
8-
import services._
97
import utils.SafeLogging
10-
import form.Mappings
11-
import idapiclient.IdApiClient
12-
import play.filters.csrf.{CSRFAddToken, CSRFCheck}
13-
import actions.AuthenticatedActions
14-
import play.api.i18n.{Messages, MessagesProvider}
15-
16-
import scala.concurrent.Future
17-
import idapiclient.requests.PasswordUpdate
18-
import pages.IdentityHtmlPage
19-
import play.api.http.HttpConfiguration
8+
import conf.Configuration
209

2110
class ChangePasswordController(
22-
api: IdApiClient,
23-
authenticatedActions: AuthenticatedActions,
24-
authenticationService: AuthenticationService,
25-
idRequestParser: IdRequestParser,
26-
idUrlBuilder: IdentityUrlBuilder,
27-
csrfCheck: CSRFCheck,
28-
csrfAddToken: CSRFAddToken,
29-
signInService: PlaySigninService,
3011
val controllerComponents: ControllerComponents,
3112
val httpConfiguration: HttpConfiguration,
3213
)(implicit context: ApplicationContext)
3314
extends BaseController
3415
with ImplicitControllerExecutionContext
35-
with SafeLogging
36-
with Mappings
37-
with implicits.Forms {
38-
39-
import authenticatedActions.fullAuthAction
40-
41-
val page = IdentityPage("/password/change", "Change Password")
42-
43-
private val passwordForm = Form(
44-
mapping(
45-
("oldPassword", optional(Forms.text)),
46-
("newPassword1", Forms.text),
47-
("newPassword2", Forms.text),
48-
)(PasswordFormData.apply)(PasswordFormData.unapply),
49-
)
50-
51-
private def passwordFormWithConstraints(implicit messagesProvider: MessagesProvider): Form[PasswordFormData] =
52-
Form(
53-
mapping(
54-
("oldPassword", optional(idPassword)),
55-
("newPassword1", idPassword),
56-
("newPassword2", idPassword),
57-
)(PasswordFormData.apply)(PasswordFormData.unapply) verifying (
58-
Messages("error.passwordsMustMatch"), { _.passwordsMatch }
59-
) verifying (
60-
Messages("error.passwordMustChange"), { _.passwordChanged }
61-
),
62-
)
63-
64-
def displayForm(): Action[AnyContent] =
65-
csrfAddToken {
66-
fullAuthAction.async { implicit request =>
67-
val form = passwordForm.bindFromFlash.getOrElse(passwordForm)
68-
69-
val idRequest = idRequestParser(request)
70-
api.passwordExists(request.user.auth, idRequest.trackingData) map { result =>
71-
val pwdExists = result.right.toOption contains true
72-
NoCache(
73-
Ok(
74-
IdentityHtmlPage.html(
75-
views.html.password.changePassword(
76-
page = page,
77-
idRequest = idRequest,
78-
idUrlBuilder = idUrlBuilder,
79-
passwordForm = form,
80-
passwordExists = pwdExists,
81-
),
82-
)(page, request, context),
83-
),
84-
)
85-
}
86-
}
87-
}
16+
with SafeLogging {
8817

89-
def renderPasswordConfirmation(returnUrl: Option[String]): Action[AnyContent] =
18+
def redirectToResetPassword: Action[AnyContent] =
9019
Action { implicit request =>
91-
// TODO: returnUrl doesn't appear to be used by this route.
92-
// Leaving to be fixed by consolidating the whole route with *reset* confirmation
93-
val returnJourney = ReturnJourney(returnUrl)
94-
val idRequest = idRequestParser(request)
95-
val userIsLoggedIn = authenticationService.userIsFullyAuthenticated(request)
96-
NoCache(
97-
Ok(
98-
IdentityHtmlPage.html(
99-
views.html.password
100-
.passwordResetConfirmation(page, idRequest, idUrlBuilder, userIsLoggedIn, returnUrl, returnJourney),
101-
)(page, request, context),
102-
),
103-
)
20+
Redirect(url = s"${Configuration.id.url}/reset", MOVED_PERMANENTLY)
10421
}
105-
106-
def submitForm(): Action[AnyContent] =
107-
csrfCheck {
108-
fullAuthAction.async { implicit request =>
109-
val idRequest = idRequestParser(request)
110-
val boundForm = passwordFormWithConstraints.bindFromRequest()
111-
112-
def onError(formWithErrors: Form[PasswordFormData]): Future[Result] = {
113-
logger.info("form errors in change password attempt")
114-
Future.successful(
115-
NoCache(
116-
SeeOther(routes.ChangePasswordController.displayForm.url)
117-
.flashing(clearPasswords(formWithErrors).toFlash),
118-
),
119-
)
120-
}
121-
122-
def onSuccess(form: PasswordFormData): Future[Result] = {
123-
val update = PasswordUpdate(form.oldPassword, form.newPassword1)
124-
val authResponse = api.updatePassword(update, request.user.auth, idRequest.trackingData)
125-
126-
signInService.getCookies(authResponse, rememberMe = true) map {
127-
case Left(errors) =>
128-
val formWithErrors = errors.foldLeft(boundForm) { (form, error) =>
129-
form.withError(error.context.getOrElse(""), error.description)
130-
}
131-
NoCache(
132-
SeeOther(routes.ChangePasswordController.displayForm.url)
133-
.flashing(clearPasswords(formWithErrors).toFlash),
134-
)
135-
case Right(cookies) =>
136-
NoCache(SeeOther(routes.ChangePasswordController.renderPasswordConfirmation(None).url))
137-
.withCookies(cookies: _*)
138-
}
139-
}
140-
141-
boundForm.fold[Future[Result]](onError, onSuccess)
142-
}
143-
}
144-
145-
private def clearPasswords(formWithPasswords: Form[PasswordFormData]) = formWithPasswords.copy(data = Map.empty)
146-
147-
}
148-
149-
case class PasswordFormData(oldPassword: Option[String], newPassword1: String, newPassword2: String) {
150-
lazy val passwordsMatch = newPassword1 == newPassword2
151-
lazy val passwordChanged = oldPassword map { _ != newPassword1 } getOrElse true
15222
}

identity/app/controllers/editprofile/tabs/AccountTab.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ trait AccountTab extends EditProfileControllerComponents {
1212
}
1313

1414
/** GET /account/edit */
15-
def redirectToAccountSettings: Action[AnyContent] = redirectToManage("account-settings")
15+
def redirectToManageAccountSettings: Action[AnyContent] = redirectToManage("account-settings")
1616

1717
}

identity/app/controllers/editprofile/tabs/EmailsTab.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@ trait EmailsTab extends EditProfileControllerComponents {
1616
}
1717

1818
/** GET /email-prefs */
19-
def redirectToEmailPrefs: Action[AnyContent] = redirectToManage("email-prefs")
20-
21-
/** GET /privacy/edit */
22-
def displayPrivacyFormRedirect: Action[AnyContent] = redirectToManage("email-prefs")
19+
def redirectToManageEmailPrefs: Action[AnyContent] = redirectToManage("email-prefs")
2320
}

identity/app/controllers/editprofile/tabs/PublicTab.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ trait PublicTab extends EditProfileControllerComponents {
1212
}
1313

1414
/** GET /public/edit */
15-
def redirectToPublicSettings: Action[AnyContent] = redirectToManage("public-settings")
15+
def redirectToManagePublicSettings: Action[AnyContent] = redirectToManage("public-settings")
1616

1717
}

identity/app/idapiclient/IdApiClient.scala

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import net.liftweb.json.compactRender
1111
import net.liftweb.json.JsonAST.JObject
1212
import net.liftweb.json.Serialization.write
1313
import utils.SafeLogging
14-
import idapiclient.requests.{AutoSignInToken, DeletionBody, PasswordUpdate, TokenPassword}
14+
import idapiclient.requests.{AutoSignInToken, DeletionBody}
1515
import org.slf4j.LoggerFactory
1616
import play.api.libs.ws.WSClient
1717

@@ -58,7 +58,6 @@ class IdApiClient(idJsonBodyParser: IdApiJsonBodyParser, conf: IdConfig, httpCli
5858
}
5959

6060
// USERS
61-
6261
def user(userId: String, auth: Auth = Anonymous): Future[Response[User]] = {
6362
val apiPath = urlJoin("user", userId)
6463
val params = buildParams(Some(auth))
@@ -85,48 +84,14 @@ class IdApiClient(idJsonBodyParser: IdApiJsonBodyParser, conf: IdConfig, httpCli
8584
response map extractUser
8685
}
8786

88-
// PASSWORD RESET/UPDATE
89-
90-
def passwordExists(auth: Auth, trackingData: TrackingData): Future[Response[Boolean]] = {
91-
val apiPath = urlJoin("user", "password-exists")
92-
val headers = buildHeaders(Some(auth), extra = xForwardedForHeader(trackingData))
93-
val response = httpClient.GET(apiUrl(apiPath), None, buildParams(Some(auth)), headers)
94-
response map extract[Boolean](jsonField("passwordExists"))
95-
}
96-
97-
def updatePassword(
98-
pwdUpdate: PasswordUpdate,
99-
auth: Auth,
100-
trackingData: TrackingData,
101-
): Future[Response[CookiesResponse]] = {
102-
val apiPath = urlJoin("user", "password")
103-
val body = write(pwdUpdate)
104-
val headers = buildHeaders(Some(auth), extra = xForwardedForHeader(trackingData))
105-
val response = httpClient.POST(apiUrl(apiPath), Some(body), clientAuth.parameters, headers)
106-
response map extract[CookiesResponse](jsonField("cookies"))
107-
}
108-
10987
def userForToken(token: String): Future[Response[User]] = {
11088
val apiPath = urlJoin("pwd-reset", "user-for-token")
11189
val params = buildParams(extra = Iterable("token" -> token))
11290
val response = httpClient.GET(apiUrl(apiPath), None, params, buildHeaders())
11391
response map extractUser
11492
}
11593

116-
def resetPassword(
117-
token: String,
118-
newPassword: String,
119-
trackingData: TrackingData,
120-
): Future[Response[CookiesResponse]] = {
121-
val apiPath = urlJoin("pwd-reset", "reset-pwd-for-user")
122-
val postBody = write(TokenPassword(token, newPassword))
123-
val headers = clientAuth.headers ++ buildHeaders(extra = xForwardedForHeader(trackingData))
124-
val response = httpClient.POST(apiUrl(apiPath), Some(postBody), clientAuth.parameters, headers)
125-
response map extract(jsonField("cookies"))
126-
}
127-
12894
// EMAILS
129-
13095
def userEmails(userId: String, trackingParameters: TrackingData): Future[Response[Subscriber]] = {
13196
val apiPath = urlJoin("useremails", userId)
13297
val params = buildParams(tracking = Some(trackingParameters))
@@ -165,6 +130,7 @@ class IdApiClient(idJsonBodyParser: IdApiJsonBodyParser, conf: IdConfig, httpCli
165130
) map extractUnit
166131
}
167132

133+
// Passwords
168134
def setPasswordGuest(password: String, token: String): Future[Response[CookiesResponse]] = {
169135
val body: JObject = "password" -> password
170136
put(
@@ -181,10 +147,7 @@ class IdApiClient(idJsonBodyParser: IdApiJsonBodyParser, conf: IdConfig, httpCli
181147
).map(extract(jsonField("cookies")))
182148
}
183149

184-
def deleteTelephone(auth: Auth): Future[Response[Unit]] =
185-
delete("user/me/telephoneNumber", Some(auth)) map extractUnit
186-
187-
// THIRD PARTY SIGN-IN
150+
// ACCOUNT DELETION
188151
def executeAccountDeletionStepFunction(
189152
userId: String,
190153
email: String,

identity/app/idapiclient/requests/PasswordUpdate.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

identity/app/idapiclient/requests/TokenPassword.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

identity/app/services/AuthenticationService.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class AuthenticationService(
5757
.unsafeRunSync()
5858
}
5959

60-
def userIsFullyAuthenticated(request: RequestHeader): Boolean =
61-
fullyAuthenticatedUser(request).isDefined
62-
6360
def consentCookieAuthenticatedUser(request: RequestHeader): Option[AuthenticatedUser] =
6461
for {
6562
scGuRp <- request.cookies.get("SC_GU_RP")

identity/app/views/completeConsents.scala.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<section class="identity-forms-message">
2626
<h1 class="identity-title">Thank you! We've got your preferences</h1>
2727
<div class="identity-forms-message__body">
28-
<p>You can change these anytime by going to My account > <a class="u-underline" data-link-name="complete-consents : to-email-prefs" href="@idUrlBuilder.buildUrl(controllers.editprofile.routes.EditProfileController.redirectToEmailPrefs.url, idRequest)">
28+
<p>You can change these anytime by going to My account > <a class="u-underline" data-link-name="complete-consents : to-email-prefs" href="@idUrlBuilder.buildUrl(controllers.editprofile.routes.EditProfileController.redirectToManageEmailPrefs.url, idRequest)">
2929
Email Preferences
3030
</a>.</p>
3131
<br/>

identity/app/views/password/changePassword.scala.html

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)