framework
framework copied to clipboard
ProtoUser passwordReset doesn't show message
Reference discussion: https://groups.google.com/forum/?fromgroups#!topic/liftweb/BtlbZr7SXsY
After receiving email with link to password change and filling in new password, Lift redirects to home page with notice. The notice doesn't show up.
This behavior also shows in ProtoUser.validateUser, i.e. the notice "account.validated" will never show.
This seems rather easy to fix. When I replace
def validateUser(id: String): NodeSeq = findUserByUniqueId(id) match {
case Full(user) if !user.validated_? =>
user.setValidated(true).resetUniqueId().save
logUserIn(user, () => {
S.notice(S.??("account.validated"))
S.redirectTo(homePage)
})
case _ => S.error(S.??("invalid.validation.link")); S.redirectTo(homePage)
}
by
override def validateUser(id: String) = findUserByUniqueId(id) match {
case Full(user) if !user.validated_? =>
user.setValidated(true).resetUniqueId().save
logUserIn(user)
S.notice(S.??("account.validated"))
S.redirectTo(homePage)
case _ => S.error(S.??("invalid.validation.link")); S.redirectTo(homePage)
}
then the message is in fact displayed on the page that the user is redirected to.
Cool, thanks - that really works. Although I'm curious why it didn't work in the first place and if this workaround has any disadvantages.
Hmm… The first solution probably doesn't work for the same reason—the URI is probably constructed for the redirect before the session is destroyed, so when the page is redirected the function mapping is lost. I'll see if I can find some time to see if it's possible to move the function mapping into the next session somehow.
You may be able to use RedirectWithState
like in here https://github.com/lift/framework/blob/8ccaa277ae37324ea6573b714621c14cf33690b8/persistence/proto/src/main/scala/net/liftweb/proto/ProtoUser.scala#L343
That's the thing to do, but you need to redirect with state in the next session; right now the code that's in there does a redirect with some state, but in the session that's about to be destroyed, so the function mappings are lost. What exactly happens to the rest of the request processing in those cases is a bit unclear, but it looks like LiftSession
's destroySessionAndContinueInNewSession
might be the way to go.