Author: dpp
Date: Thu Aug 27 21:36:04 2009
New Revision: 808640
URL: http://svn.apache.org/viewvc?rev=808640&view=rev
Log:
COmpleted the signup stuff and also login/logout
Modified:
incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/User.scala
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserAuth.scala
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserCryptoSig.scala
incubator/esme/trunk/server/src/main/webapp/templates-hidden/default.html
incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html
incubator/esme/trunk/server/src/main/webapp/templates-hidden/upw_signup_form.html
Modified:
incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala?rev=808640&r1=808639&r2=808640&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
(original)
+++ incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala Thu
Aug 27 21:36:04 2009
@@ -120,6 +120,9 @@
Menu(Loc("sign_up", List("signup"), "Sign Up",
Snippet("signup", User.signupForm),
Unless(User.loggedIn_? _, "Can't sign up when logged in"))) ::
+ Menu(Loc("logout", List("logout"), "Log Out",
+ EarlyResponse(() => {User.logUserOut; S.redirectTo(S.referer
openOr "/")}),
+ If(User.loggedIn_? _, "You must be logged in to log out"))) ::
// User.sitemap :::
TrackMgr.menuItems :::
ActionMgr.menuItems :::
Modified:
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/User.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/User.scala?rev=808640&r1=808639&r2=808640&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/User.scala
(original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/User.scala
Thu Aug 27 21:36:04 2009
@@ -48,6 +48,8 @@
object User extends User with KeyedMetaMapper[Long, User] {
override def afterSave = profileChanged _ :: notifyActors _ ::
super.afterSave
+ override def afterCreate = createCryptoRecord _ :: super.afterCreate
+
private def notifyActors(in: User) {
Distributor ! Distributor.UserUpdated(in.id)
}
@@ -65,6 +67,10 @@
}
}
+ private def createCryptoRecord(user: User) {
+ UserCryptoSig.create.user(user).save
+ }
+
def findFromWeb(uid: String): Box[User] =
User.find(By(User.nickname, uid)) or User.find(uid)
@@ -107,112 +113,10 @@
genForm(xhtml)
}
- /*
- def screenWrap = S.request.flatMap(_.location) match {
- case Full(l) if l.name == "Login" => Full(<lift:surround with="login"
at="content">
- <lift:bind /></lift:surround>)
- case _ => Full(<lift:surround with="default" at="content">
- <lift:bind /></lift:surround>)
- }
-
- /**
- * The menu item for editing the user (make this "Empty" to disable)
- */
- def editUserMenuLoc: Box[Menu] =
- Full(Menu(Loc("EditUser", editPath, "Profile",
- Template(() => wrapIt(editFunc.map(_()) openOr edit)),
- testLogginIn)))
-
-
- def signupFields: List[BaseOwnedMappedField[User]] = nickname ::
- firstName :: lastName :: imageUrl :: timezone :: locale :: Nil
-
- override def fieldOrder: List[BaseOwnedMappedField[User]] = nickname ::
- firstName :: lastName :: imageUrl :: timezone :: locale :: Nil
-
- def loginXhtml = TemplateFinder.findAnyTemplate(List("user_template",
"login")) openOr NodeSeq.Empty
-
- /*
- <form id="openid_submit" class="clear" method="POST"
action={loginPath.mkString("/", "/", "")} >
- <div class="b-open-l">
- <p class="input"><label>Open ID</label><user:openid /></p>
- <p class="button">
- <img onclick="document.getElementById('openid_submit').submit()"
src="/images/sign-on.png" alt="Sign On" />
- </p>
- </div>
- {
- if (openIdError.is)
- <div class="b-open-r">
- <h3>Oops!</h3>
- <p>We are not able validate your ID. Please try again.</p>
- </div>
- else Text("")
- }
- </form>
- */
- object openIdError extends RequestVar(false)
-
- def login = {
- if (S.post_?) {
- S.param("username").
- foreach(username =>
- ESMEOpenIDVendor.loginAndRedirect(username, logUserIn)
- )
- }
-
- def logUserIn(openid: Box[Identifier], fo: Box[VerificationResult], exp:
Box[Exception]): LiftResponse = {
- (openid, exp) match {
- case (Full(id), _) =>
- val user = User.findOrCreate(id.getIdentifier)
- User.logUserIn(user)
- S.notice("Welcome "+user.niceName)
-
- Message.create.author(user.id).
- when(Helpers.timeNow.getTime).
- source("login").
- setTextAndTags("User " + user.nickname + " logged in.", Nil, Empty).
- foreach{ msg =>
- if (msg.save) {
- Distributor ! Distributor.AddMessageToMailbox(user.id, msg,
LoginReason(user.id))
- }
- }
-
- RedirectResponse("/", S responseCookies :_*)
-
- case (_, Full(exp)) =>
- openIdError(true)
- S.error("Got an exception: "+exp.getMessage)
- RedirectResponse(S.uri, S responseCookies :_*)
-
- case _ =>
- openIdError(true)
- S.error("Unable to log you in: "+fo.map(_.getStatusMsg))
- RedirectResponse(S.uri, S responseCookies :_*)
- }
-
-
- }
-
- loginForm
- }
-
- def loginForm =
- bind("user", loginXhtml,
- "openid" -> (FocusOnLoad(<input type="text" name="username"/>)))
-
- def openIDVendor = ESMEOpenIDVendor
-
- def logout = {
- logoutCurrentUser
- S.redirectTo("/static/about")
- }
- */
def followerIdsForUserId(userId: Long): List[Long] =
Relationship.findAll(By(Relationship.target, userId)).map(_.owner.is)
-
-
/**
* Create and populate a new user
*/
@@ -227,193 +131,9 @@
user
}
-
- /*
- // no need for these menu items with OpenID
- /**
- * The menu item for creating the user/sign up (make this "Empty" to
disable)
- */
- def createUserMenuLoc: Box[Menu] = Empty
-
- /**
- * The menu item for lost password (make this "Empty" to disable)
- */
- def lostPasswordMenuLoc: Box[Menu] = Empty
-
- /**
- * The menu item for resetting the password (make this "Empty" to disable)
- */
- def resetPasswordMenuLoc: Box[Menu] = Empty
-
- /**
- * The menu item for changing password (make this "Empty" to disable)
- */
- def changePasswordMenuLoc: Box[Menu] = Empty
-
- /**
- * The menu item for validating a user (make this "Empty" to disable)
- */
- def validateUserMenuLoc: Box[Menu] = Empty
-
- */
def findByNickname(str: String): List[User] =
findAll(By(nickname, str))
- /*
-
- val basePath: List[String] = "user_mgt" :: Nil
- def signUpSuffix = "sign_up"
- lazy val signUpPath = thePath(signUpSuffix)
- def loginSuffix = "login"
- lazy val loginPath = thePath(loginSuffix)
- def lostPasswordSuffix = "lost_password"
- lazy val lostPasswordPath = thePath(lostPasswordSuffix)
- def passwordResetSuffix = "reset_password"
- lazy val passwordResetPath = thePath(passwordResetSuffix)
- def changePasswordSuffix = "change_password"
- lazy val changePasswordPath = thePath(changePasswordSuffix)
- def logoutSuffix = "logout"
- lazy val logoutPath = thePath(logoutSuffix)
- def editSuffix = "edit"
- lazy val editPath = thePath(editSuffix)
- def validateUserSuffix = "validate_user"
- lazy val validateUserPath = thePath(validateUserSuffix)
-
- def homePage = "/"
-
-
-
- case class MenuItem(name: String, path: List[String],
- loggedIn: Boolean) {
- lazy val endOfPath = path.last
- lazy val pathStr: String = path.mkString("/", "/", "")
- lazy val display = name match {
- case null | "" => false
- case _ => true
- }
- }
-
- def thePath(end: String): List[String] = basePath ::: List(end)
-
- /**
- * Return the URL of the "login" page
- */
- def loginPageURL = loginPath.mkString("/","/", "")
-
- def notLoggedIn_? = !loggedIn_?
-
- lazy val testLogginIn = If(loggedIn_? _, S.??("must.be.logged.in")) ;
-
- lazy val testSuperUser = If(superUser_? _, S.??("must.be.super.user"))
-
- def superUser_? : Boolean = currentUser.map(_.superUser.is) openOr false
-
- /**
- * The menu item for login (make this "Empty" to disable)
- */
- def loginMenuLoc: Box[Menu] = {
- Full(Menu(Loc("Login", loginPath, S.??("login"),
- If(notLoggedIn_? _, S.??("already.logged.in")),
- Template(() => wrapIt(login)))))
- }
-
- /**
- * The menu item for logout (make this "Empty" to disable)
- */
- def logoutMenuLoc: Box[Menu] =
- Full(Menu(Loc("Logout", logoutPath, S.??("logout"),
- Template(() => wrapIt(logout)),
- testLogginIn)))
-
- /*
- /**
- * The menu item for creating the user/sign up (make this "Empty" to
disable)
- */
- def createUserMenuLoc: Box[Menu] =
- Full(Menu(Loc("CreateUser", signUpPath,
- S.??("sign.up"),
- Template(() => wrapIt(signupFunc.map(_()) openOr signup)),
- If(notLoggedIn_? _, S.??("logout.first")))))
-
- /**
- * The menu item for lost password (make this "Empty" to disable)
- */
- def lostPasswordMenuLoc: Box[Menu] =
- Full(Menu(Loc("LostPassword", lostPasswordPath,
- S.??("lost.password"),
- Template(() => wrapIt(lostPassword)),
- If(notLoggedIn_? _, S.??("logout.first"))))) // not logged in
-
- /**
- * The menu item for resetting the password (make this "Empty" to disable)
- */
- def resetPasswordMenuLoc: Box[Menu] =
- Full(Menu(Loc("ResetPassword", (passwordResetPath, true),
- S.??("reset.password"), Hidden,
- Template(() => wrapIt(passwordReset(snarfLastItem))),
- If(notLoggedIn_? _,
- S.??("logout.first"))))) //not Logged in
-
- /**
- * The menu item for editing the user (make this "Empty" to disable)
- */
- def editUserMenuLoc: Box[Menu] =
- Full(Menu(Loc("EditUser", editPath, S.??("edit.user"),
- Template(() => wrapIt(editFunc.map(_()) openOr edit)),
- testLogginIn)))
- */
-
- /*
- /**
- * The menu item for changing password (make this "Empty" to disable)
- */
- def changePasswordMenuLoc: Box[Menu] =
- Full(Menu(Loc("ChangePassword", changePasswordPath,
- S.??("change.password"),
- Template(() => wrapIt(changePassword)),
- testLogginIn)))
- */
-
- /*
- /**
- * The menu item for validating a user (make this "Empty" to disable)
- */
- def validateUserMenuLoc: Box[Menu] =
- Full(Menu(Loc("ValidateUser", (validateUserPath, true),
- S.??("validate.user"), Hidden,
- Template(() => wrapIt(validateUser(snarfLastItem))),
- If(notLoggedIn_? _, S.??("logout.first")))))
- */
- lazy val sitemap: List[Menu] =
- List(loginMenuLoc, logoutMenuLoc, createUserMenuLoc,
- lostPasswordMenuLoc, resetPasswordMenuLoc,
- editUserMenuLoc, changePasswordMenuLoc,
- validateUserMenuLoc).flatten(a => a)
-
-
- def skipEmailValidation = false
-
- def userMenu: List[Node] = {
- val li = loggedIn_?
- ItemList.
- filter(i => i.display && i.loggedIn == li).
- map(i => (<a href={i.pathStr}>{i.name}</a>))
- }
-
- protected def snarfLastItem: String =
- (for (r <- S.request) yield r.path.wholePath.last) openOr ""
-
- lazy val ItemList: List[MenuItem] =
- List(MenuItem(S.??("sign.up"), signUpPath, false),
- MenuItem(S.??("log.in"), loginPath, false),
- MenuItem(S.??("lost.password"), lostPasswordPath, false),
- MenuItem("", passwordResetPath, false),
- MenuItem(S.??("change.password"), changePasswordPath, true),
- MenuItem(S.??("log.out"), logoutPath, true),
- MenuItem(S.??("edit.profile"), editPath, true),
- MenuItem("", validateUserPath, false))
- // def requestLoans: List[LoanWrapper] = Nil // List(curUser)
- */
var onLogIn: List[User => Unit] = List(ExtSession.userDidLogin _)
var onLogOut: List[Box[User] => Unit] = List(ExtSession.userDidLogout _)
@@ -447,372 +167,8 @@
def currentUser: Box[User] = curUser.is
-
- /*
- /*
- def signupXhtml(user: User) = {
- (<form method="post" action={S.uri}><table><tr><td
- colspan="2">Sign Up</td></tr>
- {localForm(user, false)}
- <tr><td> </td><td><user:submit/></td></tr>
- </table></form>)
- }
-
-
- def signupMailBody(user: User, validationLink: String) = {
- (<html>
- <head>
- <title>Sign Up Confirmation</title>
- </head>
- <body>
- <p>Dear {user.firstName},
- <br/>
- <br/>
- Click on this link to complete signup
- <br/><a href={validationLink}>{validationLink}</a>
- <br/>
- <br/>
- Thanks
- </p>
- </body>
- </html>)
- }
-
- def signupMailSubject = S.??("sign.up.confirmation")
-
- def sendValidationEmail(user: User) {
- val resetLink = S.hostAndPath+"/"+validateUserPath.mkString("/")+
- "/"+user.uniqueId
-
- val email: String = user.email
-
- val msgXml = signupMailBody(user, resetLink)
-
- import net.liftweb.util._
- import Mailer._
-
- Mailer.sendMail(From(emailFrom),Subject(signupMailSubject),
- (To(user.email) :: xmlToMailBodyType(msgXml) ::
- (bccEmail.toList.map(BCC(_)))) :_* )
- }
-
- protected object signupFunc extends RequestVar[Box[() => NodeSeq]](Empty)
-
- def signup = {
- val theUser: User = create
- val theName = signUpPath.mkString("")
-
- def testSignup() {
- theUser.validate match {
- case Nil =>
- theUser.validated(skipEmailValidation).uniqueId.reset()
- theUser.save
- if (!skipEmailValidation) {
- sendValidationEmail(theUser)
- S.notice(S.??("sign.up.message"))
- } else {
- S.notice(S.??("welcome"))
- logUserIn(theUser)
- }
-
- S.redirectTo(homePage)
-
- case xs => S.error(xs) ; signupFunc(Full(innerSignup _))
- }
- }
-
- def innerSignup = bind("user",
- signupXhtml(theUser),
- "submit" -> SHtml.submit(S.??("sign.up"), testSignup _))
-
- innerSignup
- }
- */
-
- def emailFrom = "noreply@"+S.hostName
-
- def bccEmail: Box[String] = Empty
-
- def testLoggedIn(page: String): Boolean =
- ItemList.filter(_.endOfPath == page) match {
- case x :: xs if x.loggedIn == loggedIn_? => true
- case _ => false
- }
-
-
- def validateUser(id: String): NodeSeq = getSingleton.find(By(uniqueId, id))
match {
- case Full(user) if !user.validated =>
- user.validated(true).uniqueId.reset().save
- S.notice(S.??("account.validated"))
- logUserIn(user)
- S.redirectTo(homePage)
-
- case _ => S.error(S.??("invalid.validation.link")); S.redirectTo(homePage)
- }
-
- /*
- def login = {
- if (S.post_?) {
- S.param("username").
- flatMap(username => getSingleton.find(By(email, username))) match {
- case Full(user) if user.validated &&
- user.password.match_?(S.param("password").openOr("*")) =>
- S.notice(S.??("logged.in"))
- logUserIn(user)
- S.redirectTo(homePage)
-
- case Full(user) if !user.validated =>
- S.error(S.??("account.validation.error"))
-
- case _ => S.error(S.??("invalid.credentials"))
- }
- }
-
- bind("user", loginXhtml,
- "email" -> (FocusOnLoad(<input type="text" name="username"/>)),
- "password" -> (<input type="password" name="password"/>),
- "submit" -> (<input type="submit" value={S.??("log.in")}/>))
- }
- */
-
- /*
- def lostPasswordXhtml = {
- (<form method="post" action={S.uri}>
- <table><tr><td
- colspan="2">{S.??("enter.email")}</td></tr>
- <tr><td>{S.??("email.address")}</td><td><user:email /></td></tr>
- <tr><td> </td><td><user:submit /></td></tr>
- </table>
- </form>)
- }
-
- def passwordResetMailBody(user: User, resetLink: String) = {
- (<html>
- <head>
- <title>{S.??("reset.password.confirmation")}</title>
- </head>
- <body>
- <p>{S.??("dear")} {user.firstName},
- <br/>
- <br/>
- {S.??("click.reset.link")}
- <br/><a href={resetLink}>{resetLink}</a>
- <br/>
- <br/>
- {S.??("thank.you")}
- </p>
- </body>
- </html>)
- }
-
- def passwordResetEmailSubject = S.??("reset.password.request")
-
- def sendPasswordReset(email: String) {
- getSingleton.find(By(this.email, email)) match {
- case Full(user) if user.validated =>
- user.uniqueId.reset().save
- val resetLink = S.hostAndPath+
- passwordResetPath.mkString("/", "/", "/")+user.uniqueId
-
- val email: String = user.email
-
- import Mailer._
-
- val msgXml = passwordResetMailBody(user, resetLink)
- Mailer.sendMail(From(emailFrom),Subject(passwordResetEmailSubject),
- (To(user.email) :: xmlToMailBodyType(msgXml) ::
- (bccEmail.toList.map(BCC(_)))) :_*)
-
- S.notice(S.??("password.reset.email.sent"))
- S.redirectTo(homePage)
-
- case Full(user) =>
- sendValidationEmail(user)
- S.notice(S.??("account.validation.resent"))
- S.redirectTo(homePage)
-
- case _ => S.error(S.??("email.address.not.found"))
- }
- }
-
- def lostPassword = {
- bind("user", lostPasswordXhtml,
- "email" -> SHtml.text("", sendPasswordReset _),
- "submit" -> <input type="Submit" value={S.??("send.it")} />)
- }
-
- def passwordResetXhtml = {
- (<form method="post" action={S.uri}>
- <table><tr><td colspan="2">{S.??("reset.your.password")}</td></tr>
- <tr><td>{S.??("enter.your.new.password")}</td><td><user:pwd/></td></tr>
- <tr><td>{S.??("repeat.your.new.password")}</td><td><user:pwd/></td></tr>
- <tr><td> </td><td><user:submit/></td></tr>
- </table>
- </form>)
- }
-
- def passwordReset(id: String) =
- getSingleton.find(By(uniqueId, id)) match {
- case Full(user) =>
- def finishSet() {
- user.validate match {
- case Nil => S.notice(S.??("password.changed"))
- user.save
- logUserIn(user); S.redirectTo(homePage)
-
- case xs => S.error(xs)
- }
- }
- user.uniqueId.reset().save
-
- bind("user", passwordResetXhtml,
- "pwd" -> SHtml.password_*("",S.LFuncHolder((p: List[String]) =>
- user.password.setList(p))),
- "submit" -> SHtml.submit(S.??("set.password"), finishSet _))
- case _ => S.error(S.??("pasword.link.invalid")); S.redirectTo(homePage)
- }
-
- def changePasswordXhtml = {
- (<form method="post" action={S.uri}>
- <table><tr><td colspan="2">{S.??("change.password")}</td></tr>
- <tr><td>{S.??("old.password")}</td><td><user:old_pwd /></td></tr>
- <tr><td>{S.??("new.password")}</td><td><user:new_pwd /></td></tr>
- <tr><td>{S.??("repeat.password")}</td><td><user:new_pwd /></td></tr>
- <tr><td> </td><td><user:submit /></td></tr>
- </table>
- </form>)
- }
-
- def changePassword = {
- val user = currentUser.open_! // we can do this because the logged in test
has happened
- var oldPassword = ""
- var newPassword: List[String] = Nil
-
- def testAndSet() {
- if (!user.password.match_?(oldPassword))
S.error(S.??("wrong.old.password"))
- else {
- user.password.setFromAny(newPassword)
- user.validate match {
- case Nil => user.save; S.notice(S.??("pasword.changed"));
S.redirectTo(homePage)
- case xs => S.error(xs)
- }
- }
- }
-
- bind("user", changePasswordXhtml,
- "old_pwd" -> SHtml.password("", oldPassword = _),
- "new_pwd" -> SHtml.password_*("", S.LFuncHolder(newPassword = _)),
- "submit" -> SHtml.submit(S.??("change"), testAndSet _))
- }
- */
-
- /*def editXhtml(user: User) = {
- (<form method="post" action={S.uri}>
- <table><tr><td colspan="2">{S.??("edit")}</td></tr>
- {localForm(user, true)}
- <tr><td> </td><td><user:submit/></td></tr>
- </table>
- </form>)
- }*/
-
-
- def editXhtml = <form method="post" action={S.uri}>{
- TemplateFinder.findAnyTemplate(List("user_template", "edit")) openOr
NodeSeq.Empty
- }</form>
-
- object editFunc extends RequestVar[Box[() => NodeSeq]](Empty)
-
- def edit = {
- val theUser: User = currentUser.open_! // we know we're logged in
- val theName = editPath.mkString("")
-
- def testEdit() {
- theUser.validate match {
- case Nil =>
- theUser.save
- S.notice(S.??("profle.updated"))
- S.redirectTo(homePage)
-
- case xs => S.error(xs) ; editFunc(Full(innerEdit _))
- }
- }
-
- def innerEdit = bind("user", editXhtml,
- "user_info" -> localForm(theUser, true),
- "submit" -> SHtml.submit(S.??("edit"), testEdit _))
-
- innerEdit
- }
-
- private def localForm(user: User, ignorePassword: Boolean): NodeSeq = {
- signupFields.
- map(fi => getSingleton.getActualBaseField(user, fi)).
- filter(f => !ignorePassword || (f match {
- case f: MappedPassword[User] => false
- case _ => true
- })).
- flatMap(f =>
- f.toForm.toList.map(form =>
- (<tr><td>{f.displayName}</td><td>{form}</td></tr>) ) )
- }
-
- import scala.xml.transform.{RuleTransformer, RewriteRule}
- protected def wrapIt(in: NodeSeq): NodeSeq =
- screenWrap.map(new RuleTransformer(new RewriteRule {
- override def transform(n: Node) = n match {
- case e: Elem if "bind" == e.label && "lift" == e.prefix => in
- case _ => n
- }
- })) openOr in
- */
-
}
-/*
- object ESMEOpenIDVendor extends OpenIdVendor {
- type UserType = User
- type ConsumerType = ESMEOpenIDConsumer
-
- def logUserOut(): Unit = User.logUserOut()
-
- def currentUser = User.currentUser
-
- def postLogin(id: Box[Identifier],res: VerificationResult): Unit = {
- id match {
- case Full(id) =>
- val user = User.findOrCreate(id.getIdentifier())
- User.logUserIn(user)
- S.notice("Welcome "+user.niceName)
-
- case _ =>
- logUserOut()
- S.error("Failed to authenticate")
- }
- }
-
- def displayUser(in: User): NodeSeq = Text("Welcome "+in.niceName)
-
- def createAConsumer = new ESMEOpenIDConsumer
- }
-
- class ESMEOpenIDConsumer extends OpenIdConsumer[User]
- {
- override val manager = {
-
- Log.info("Proxy settings: " + Props.get("http.proxyHost", "[no host]")
- + ":" + Props.get("http.proxyPort", "[no port]"))
-
- for (host <- Props.get("http.proxyHost")){
- val proxyProps = new ProxyProperties()
- proxyProps.setProxyHostName(host)
- proxyProps.setProxyPort(Props.getInt("http.proxyPort", 80))
- HttpClientFactory.setProxyProperties(proxyProps)
- }
- new ConsumerManager
- }
- }
- */
-
/**
* An O-R mapped "User" class that includes first name, last name, password
*/
@@ -837,18 +193,19 @@
Relationship.find(By(Relationship.owner, this),
By(Relationship.target, who)) match {
case Full(x) => true
- case Empty => { if (Relationship.create.owner(this).target(who).save)
- Message.create.author(who.id).
- when(Helpers.timeNow.getTime).
- source("followed").
- setTextAndTags("User " + this.nickname + " followed " +
who.nickname + ".", Nil, Empty).
- foreach { msg =>
- if (msg.save) {
- Distributor ! Distributor.AddMessageToMailbox(who.id, msg,
FollowedReason(this.id))
- }
+ case Empty =>
+ if (Relationship.create.owner(this).target(who).save)
+ Message.create.author(who.id).
+ when(Helpers.timeNow.getTime).
+ source("followed").
+ setTextAndTags("User " + this.nickname + " followed " + who.nickname +
".", Nil, Empty).
+ foreach { msg =>
+ if (msg.save) {
+ Distributor ! Distributor.AddMessageToMailbox(who.id, msg,
FollowedReason(this.id))
}
- true
}
+ true
+
case _ => false
}
}
@@ -927,15 +284,6 @@
def lastNameDisplayName = ??("Last Name")
- // Email
- /*
- object email extends MappedEmail(this, 48) {
- override def dbIndexed_? = true
- override def validations = valUnique(S.??("unique.email.address")) _ ::
super.validations
- override def displayName = fieldOwner.emailDisplayName
- override val fieldId = Some(Text("txtEmail"))
- }*/
-
// def emailDisplayName = ??("Email")
// Password
Modified:
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserAuth.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserAuth.scala?rev=808640&r1=808639&r2=808640&view=diff
==============================================================================
---
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserAuth.scala
(original)
+++
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserAuth.scala
Thu Aug 27 21:36:04 2009
@@ -110,7 +110,10 @@
(for {
name <- S.param("username").map(_.trim.toLowerCase)
pwd <- S.param("password").map(_.trim)
- user <- /*User.find(By(User.email, name)) or */
User.find(By(User.nickname, name))
+ user <- UserAuth.find(By(UserAuth.authKey, name),
+ By(UserAuth.authType,
moduleName)).flatMap(_.user.obj) or
+ User.find(By(User.nickname, name))
+
userAuth <- UserAuth.find(By(UserAuth.user, user),
By(UserAuth.authType, moduleName))
if authenticatePassword(userAuth.authData.is, pwd)
} yield user) match {
@@ -137,26 +140,34 @@
def createHolder(): FieldSet = new FieldSet {
private var pwd1 = ""
private var pwd2 = ""
+ private var email = ""
def toForm: NodeSeq =
TemplateFinder.findAnyTemplate("templates-hidden" :: "upw_signup_form" ::
Nil).map(
xhtml =>
bind("signup", xhtml,
+ "email" -> SHtml.text(email, s => email = s.trim.toLowerCase),
"pwd1" -> SHtml.password(pwd1, s => pwd1 = s.trim),
"pwd2" -> SHtml.password(pwd2, s => pwd2 = s.trim))
) openOr NodeSeq.Empty
- def validate: List[FieldError] = if (pwd1 != pwd2) List(FieldError(new
FieldIdentifier {
+ def validate: List[FieldError] =
+ (if (MappedEmail.validEmailAddr_?(email)) Nil else
+ List(FieldError(new FieldIdentifier {
+ override def uniqueFieldId: Box[String] = Full("email")
+ },Text(S.?("Bad email address"))))) :::
+ (if (pwd1 != pwd2) List(FieldError(new FieldIdentifier {
override def uniqueFieldId: Box[String] = Full("pwd1")
},Text(S.?("Passwords do not match"))))
else if (pwd1.length < 6) List(FieldError(new FieldIdentifier {
override def uniqueFieldId: Box[String] = Full("pwd1")
},Text(S.?("Passwords must be 6 characters or longer"))))
- else Nil
+ else Nil)
+
def save(user: User): Unit = {
val salt = randomString(10)
val md5 = Helpers.md5(salt + pwd1)
- UserAuth.create.user(user).authData(salt+";"+md5).save
+
UserAuth.create.user(user).authType(moduleName).authKey(email).authData(salt+";"+md5).save
}
}
}
Modified:
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserCryptoSig.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserCryptoSig.scala?rev=808640&r1=808639&r2=808640&view=diff
==============================================================================
---
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserCryptoSig.scala
(original)
+++
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/UserCryptoSig.scala
Thu Aug 27 21:36:04 2009
@@ -35,18 +35,18 @@
def getSingleton = UserCryptoSig
object user extends MappedLongForeignKey(this, User)
- private object createdOn extends MappedLong(this) {
+ object createdOn extends MappedLong(this) {
override def defaultValue = millis
}
- private object valid extends MappedBoolean(this) {
+ object valid extends MappedBoolean(this) {
override def defaultValue = true
}
- private object publicKey extends MappedString(this, 1024) {
+ object publicKey extends MappedString(this, 1024) {
override def dbIndexed_? = true
override def defaultValue =
base64Encode(defaultKeyPair.getPublic.getEncoded)
}
- private object privateKey extends MappedText(this) {
+ object privateKey extends MappedText(this) {
override def defaultValue =
base64Encode(defaultKeyPair.getPrivate.getEncoded)
}
Modified:
incubator/esme/trunk/server/src/main/webapp/templates-hidden/default.html
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/templates-hidden/default.html?rev=808640&r1=808639&r2=808640&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/templates-hidden/default.html
(original)
+++ incubator/esme/trunk/server/src/main/webapp/templates-hidden/default.html
Thu Aug 27 21:36:04 2009
@@ -18,6 +18,7 @@
<a class="logo" href="/"><img src="/images/esme.png" alt="ESME" /></a>
<ul class="b-primary">
+ <li><lift:Menu.item name="sign_up"/></li>
<li><lift:Menu.item name="EditUser"/></li>
<li><lift:Menu.item name="about"/></li>
<li><lift:Menu.item name="list_users"/></li>
@@ -26,7 +27,7 @@
<li><lift:Menu.item name="authToken"/></li>
<li><lift:Menu.item name="accessPools"/></li>
<li><lift:Menu.item name="streams"/></li>
- <li><lift:Menu.item name="Logout"/></li>
+ <li><lift:Menu.item name="logout"/></li>
</ul>
</div>
Modified:
incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html?rev=808640&r1=808639&r2=808640&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html
(original)
+++ incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html
Thu Aug 27 21:36:04 2009
@@ -118,6 +118,7 @@
<img src="/images/esme.png" alt="ESME" />
<img src="/images/ajax-loader.gif" style="display: none"
id="ajax-loader"/>
<ul class="b-primary">
+ <li><lift:Menu.item name="sign_up"/></li>
<li><lift:Menu.item name="EditUser"/></li>
<li><lift:Menu.item name="about"/></li>
<li><lift:Menu.item name="list_users"/></li>
@@ -126,7 +127,7 @@
<li><lift:Menu.item name="authToken"/></li>
<li><lift:Menu.item name="accessPools"/></li>
<li><lift:Menu.item name="streams"/></li>
- <li><lift:Menu.item name="Logout"/></li>
+ <li><lift:Menu.item name="logout"/></li>
</ul>
</div>
Modified:
incubator/esme/trunk/server/src/main/webapp/templates-hidden/upw_signup_form.html
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/templates-hidden/upw_signup_form.html?rev=808640&r1=808639&r2=808640&view=diff
==============================================================================
---
incubator/esme/trunk/server/src/main/webapp/templates-hidden/upw_signup_form.html
(original)
+++
incubator/esme/trunk/server/src/main/webapp/templates-hidden/upw_signup_form.html
Thu Aug 27 21:36:04 2009
@@ -1,4 +1,9 @@
<lift:xml_group>
+ <label for="email">
+ Email: <signup:email/>
+ </label>
+ <br/>
+
<label for="pwd1">
Password: <signup:pwd1/>
</label>