framework icon indicating copy to clipboard operation
framework copied to clipboard

ProtoUser passwordReset doesn't show message

Open jczuchnowski opened this issue 12 years ago • 6 comments

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.

jczuchnowski avatar Mar 16 '12 15:03 jczuchnowski

This behavior also shows in ProtoUser.validateUser, i.e. the notice "account.validated" will never show.

tgpfeiffer avatar Jun 30 '12 22:06 tgpfeiffer

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.

tgpfeiffer avatar Jun 30 '12 23:06 tgpfeiffer

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.

jczuchnowski avatar Jul 21 '12 23:07 jczuchnowski

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.

Shadowfiend avatar May 13 '14 03:05 Shadowfiend

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

fmpwizard avatar May 20 '14 11:05 fmpwizard

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.

Shadowfiend avatar May 20 '14 15:05 Shadowfiend