Skip to content

Instantly share code, notes, and snippets.

@urcadox
Created October 19, 2011 15:56
Show Gist options
  • Save urcadox/1298735 to your computer and use it in GitHub Desktop.
Save urcadox/1298735 to your computer and use it in GitHub Desktop.
package code {
package snippet {
import net.liftweb.common._
import net.liftweb.util._
import net.liftweb.http._
import model._
object Preferences extends LiftScreen {
object user extends ScreenVar[code.model.User](User.currentUser.open_!)
override def screenTop = Full(<h2>{S.?("preferences")}</h2>)
val currentPassword = password(S.?("current-password"), "")
addFields(() => user.is.firstName)
addFields(() => user.is.lastName)
addFields(() => user.is.email)
val newPassword1 = password(S.?("new-password"), "")
val newPassword2 = password(S.?("new-password-confirmation"), "")
addFields(() => user.is.timezone)
addFields(() => user.is.optIn)
override def validations =
(() =>
if(!user.is.password.isMatch(currentPassword))
List(FieldError(currentPassword, S.?("incorrect-password")))
else Nil
) ::
(() =>
if(newPassword1.is != newPassword2.is)
List(FieldError(newPassword1, S.?("passwords-do-not-match")))
else if(newPassword1.is.length > 0 && newPassword1.is.length < 6)
List(FieldError(newPassword1, S.?("password-too-short").format("6")))
else
Nil
) ::
(() =>
user.is.optIn.notEmpty(S.?("mandatory-choice"))(user.is.optIn.is)
) :: Nil
override def finishButton = <button>
{S.?("save")}
</button>
def finish() {
if(newPassword1.is.length > 0)
user.is.password.setPassword(newPassword1.is)
user.is.save
S.notice(S.?("preferences-saved"))
S.redirectTo("/preferences")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment