@@ -18,17 +18,17 @@ package securesocial.controllers
18
18
19
19
import javax .inject .Inject
20
20
21
- import securesocial .core ._
22
- import securesocial .core .SecureSocial ._
23
- import play .api .mvc .Result
24
- import play .api .{ Configuration , Play }
21
+ import play .api .Configuration
25
22
import play .api .data .Form
26
23
import play .api .data .Forms ._
24
+ import play .api .i18n .{ I18nSupport , Messages }
25
+ import play .api .mvc .{ ControllerComponents , Result }
26
+ import play .filters .csrf ._
27
+ import securesocial .core .SecureSocial ._
28
+ import securesocial .core ._
27
29
import securesocial .core .providers .utils .PasswordValidator
28
- import play .api .i18n .{ I18nSupport , Messages , MessagesApi }
29
30
30
31
import scala .concurrent .{ Await , Future }
31
- import play .filters .csrf ._
32
32
33
33
/**
34
34
* A default PasswordChange controller that uses the BasicProfile as the user type
@@ -38,8 +38,8 @@ import play.filters.csrf._
38
38
class PasswordChange @ Inject () (
39
39
override implicit val env : RuntimeEnvironment ,
40
40
val csrfAddToken : CSRFAddToken ,
41
- val csrfCheck : CSRFCheck
42
- ) extends BasePasswordChange
41
+ val csrfCheck : CSRFCheck ,
42
+ val controllerComponents : ControllerComponents ) extends BasePasswordChange
43
43
44
44
/**
45
45
* A trait that defines the password change functionality
@@ -58,17 +58,15 @@ trait BasePasswordChange extends SecureSocial with I18nSupport {
58
58
val csrfAddToken : CSRFAddToken
59
59
val csrfCheck : CSRFCheck
60
60
val configuration : Configuration = env.configuration
61
- implicit val messagesApi : MessagesApi = env.messagesApi
62
61
63
62
/**
64
63
* The property that specifies the page the user is redirected to after changing the password.
65
64
*/
66
65
val onPasswordChangeGoTo = " securesocial.onPasswordChangeGoTo"
67
66
68
67
/** The redirect target of the handlePasswordChange action. */
69
- def onHandlePasswordChangeGoTo = configuration.getString(onPasswordChangeGoTo).getOrElse(
70
- securesocial.controllers.routes.PasswordChange .page().url
71
- )
68
+ def onHandlePasswordChangeGoTo = configuration.get[Option [String ]](onPasswordChangeGoTo).getOrElse(
69
+ securesocial.controllers.routes.PasswordChange .page().url)
72
70
73
71
/**
74
72
* checks if the supplied password matches the stored one
@@ -98,11 +96,7 @@ trait BasePasswordChange extends SecureSocial with I18nSupport {
98
96
NewPassword ->
99
97
tuple(
100
98
Password1 -> nonEmptyText.verifying(PasswordValidator .constraint),
101
- Password2 -> nonEmptyText
102
- ).verifying(Messages (BaseRegistration .PasswordsDoNotMatch ), passwords => passwords._1 == passwords._2)
103
-
104
- )((currentPassword, newPassword) => ChangeInfo (currentPassword, newPassword._1))((changeInfo : ChangeInfo ) => Some ((" " , (" " , " " ))))
105
- )
99
+ Password2 -> nonEmptyText).verifying(Messages (BaseRegistration .PasswordsDoNotMatch ), passwords => passwords._1 == passwords._2))((currentPassword, newPassword) => ChangeInfo (currentPassword, newPassword._1))((changeInfo : ChangeInfo ) => Some ((" " , (" " , " " )))))
106
100
107
101
env.userService.passwordInfoFor(request.user).flatMap {
108
102
case Some (info) =>
@@ -139,17 +133,15 @@ trait BasePasswordChange extends SecureSocial with I18nSupport {
139
133
errors => Future .successful(BadRequest (env.viewTemplates.getPasswordChangePage(errors))),
140
134
info => {
141
135
val newPasswordInfo = env.currentHasher.hash(info.newPassword)
142
- val userLang = request2lang(request)
143
136
env.userService.updatePasswordInfo(request.user, newPasswordInfo).map {
144
137
case Some (u) =>
145
- env.mailer.sendPasswordChangedNotice(u)(request, userLang )
138
+ env.mailer.sendPasswordChangedNotice(u)(request, messagesApi.preferred(request) )
146
139
val result = Redirect (onHandlePasswordChangeGoTo).flashing(Success -> Messages (OkMessage ))
147
140
Events .fire(PasswordChangeEvent (request.user)).map(result.withSession).getOrElse(result)
148
141
case None =>
149
142
Redirect (onHandlePasswordChangeGoTo).flashing(Error -> Messages (" securesocial.password.error" ))
150
143
}
151
- }
152
- )
144
+ })
153
145
}
154
146
}
155
147
}
0 commit comments