scala - How to update securesocial username after user is created -
i'm trying write edituser page secure social plugin implemented in play framework app. i'm having trouble staying logged in after username changed. issue occurs when press submit edituser form after changing username. goes login page , says "you need log in access page." desired behavior redirect edituser page without needing relogin. in database updated. works, no longer logged in.
below controller method "user" controller post of user update.
if me out appreciated. thanks.
// form uses following case class case class accountinfo(username: string, firstname: string, lastname: string, email: option[string]) def update(username: string) = securedaction { implicit request => this.editaccountform.bindfromrequest.fold ( haserrors = { info => redirect(routes.users.edit()).flashing(flash(editaccountform.data) + ("error" -> messages("validation.errors"))) }, success = { info => db.withsession { implicit s: session => val uid = user.currentuser(request.user.id.id,providerid).get.uid user.update(uid, info, providerid) } val message = messages("user.update.success") redirect(routes.users.edit()).flashing("success" -> message) .withcookies(request.cookies.get("id").get) } ) }
by changing username changing values used identify user (username + provider id). happening on next request securesocial looking old username , since can't find in database kicks out.
what should besides updating database update authenticator stored current session. like:
securesocial.authenticatorfromrequest(request).map { authenticator => val newid = request.user.id.copy( id = username ) authenticator.save(authenticator.copy( userid = newid)) } that should make work. also, don't need add id cookie redirect. securesocial you.
Comments
Post a Comment