You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@esme.apache.org by vd...@apache.org on 2010/02/11 10:38:01 UTC

svn commit: r908896 - in /incubator/esme/trunk/server/src/main: scala/org/apache/esme/lib/ProfileMgr.scala webapp/profile_view/edit.html

Author: vdichev
Date: Thu Feb 11 09:37:47 2010
New Revision: 908896

URL: http://svn.apache.org/viewvc?rev=908896&view=rev
Log:
Edit email address in profile page

Modified:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ProfileMgr.scala
    incubator/esme/trunk/server/src/main/webapp/profile_view/edit.html

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ProfileMgr.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ProfileMgr.scala?rev=908896&r1=908895&r2=908896&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ProfileMgr.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ProfileMgr.scala Thu Feb 11 09:37:47 2010
@@ -58,22 +58,26 @@
   Nil
 
   def editProfile(in: NodeSeq): NodeSeq = {
-    import OpenIDAuthModule.moduleName
-
     (for (user <- User.currentUser) yield {
       
       val openID = UserAuth.find(By(UserAuth.user, user),
-                                 By(UserAuth.authType, moduleName))
+                                 By(UserAuth.authType, OpenIDAuthModule.moduleName))
                                  
       val openIdUrl = openID.map(_.authKey.is) getOrElse ""
       val from = "/profile_view/edit"
 
       var pwd = ""
+      val userPwdModule =
+        UserAuth.find(By(UserAuth.user, user),
+                      By(UserAuth.authType, UserPwdAuthModule.moduleName))
+      
+      var email = userPwdModule.map(_.authKey.is).getOrElse("")
+
       
       def saveOpenID(openid: Box[Identifier], fo: Box[VerificationResult], exp: Box[Exception]): LiftResponse = {
         (openid, exp) match {
           case (Full(id), _) =>
-            UserAuth.create.authType(moduleName).user(user).authKey(id.getIdentifier()).save
+            UserAuth.create.authType(OpenIDAuthModule.moduleName).user(user).authKey(id.getIdentifier()).save
         
           case (_, Full(exp)) =>
             S.error(S.?("base_error_exception", exp.getMessage))
@@ -88,7 +92,7 @@
         if (openIdUrl != url) {
           if (url != "") {
             val other = UserAuth.find(NotBy(UserAuth.user, user),
-                                      By(UserAuth.authType, moduleName),
+                                      By(UserAuth.authType, OpenIDAuthModule.moduleName),
                                       By(UserAuth.authKey, url))
             other match {
               case Empty =>
@@ -103,22 +107,25 @@
       }
       
       // TODO: unify with duplicate validation code in UserAuth
-      def checkPassword(confirm: String) {
-        import UserPwdAuthModule.moduleName
-        
-        if (pwd != "") {
-          if (pwd != confirm) {
-            S.error(S.?("base_user_err_mismatch_password"))
-          } else if (pwd.length < 6) {
-            S.error(S.?("base_user_err_password_too_short"))
+      def checkEmailPassword(confirm: String) {
+        for (userPwd <- userPwdModule) {
+          if (!MappedEmail.validEmailAddr_?(email)) {
+            S.error(S.?("base_user_err_bad_email"))
           } else {
-            for (userPwd <- UserAuth.find(By(UserAuth.user, user),
-                                          By(UserAuth.authType, moduleName))) {
+            userPwd.authKey(email)
+          }
+          if (pwd != "") {
+            if (pwd != confirm) {
+              S.error(S.?("base_user_err_mismatch_password"))
+            } else if (pwd.length < 6) {
+              S.error(S.?("base_user_err_password_too_short"))
+            }  else {
               val salt = randomString(10)
               val md5 = Helpers.md5(salt + pwd)
-              userPwd.authData(salt+";"+md5).save
+              userPwd.authData(salt+";"+md5)
             }
           }
+          userPwd.save
         }
       }
       
@@ -128,9 +135,10 @@
                        "firstName" -> user.firstName.toForm,
                        "timezone" -> user.timezone.toForm,
                        "locale" -> user.locale.toForm,
-                       "openid" -> text(openIdUrl, registerOpenID(_)),
+                       "email" -> text(email, e => email = e.trim.toLowerCase),
                        "password" -> password(pwd, p => pwd = p.trim),
-                       "confirm" -> password(pwd, p => checkPassword(p.trim)),
+                       "confirm" -> password(pwd, p => checkEmailPassword(p.trim)),
+                       "openid" -> text(openIdUrl, registerOpenID(_)),
                        "save" -> submit("Save", user.save))
     }).getOrElse(NodeSeq.Empty)
 

Modified: incubator/esme/trunk/server/src/main/webapp/profile_view/edit.html
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/profile_view/edit.html?rev=908896&r1=908895&r2=908896&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/profile_view/edit.html (original)
+++ incubator/esme/trunk/server/src/main/webapp/profile_view/edit.html Thu Feb 11 09:37:47 2010
@@ -26,9 +26,10 @@
         <tr> <td><lift:loc>ui_sign_up_image_url</lift:loc></td> <td><user:imageURL/></td> </tr>
         <tr> <td><lift:loc>ui_sign_up_timezone</lift:loc></td> <td><user:timezone/></td> </tr>
         <tr> <td><lift:loc>ui_sign_up_locale</lift:loc></td> <td><user:locale/></td> </tr>
-        <tr> <td><lift:loc>ui_sign_up_openid</lift:loc></td> <td><user:openid/></td> </tr>
+        <tr> <td><lift:loc>ui_login_email</lift:loc></td> <td><user:email/></td> </tr>
         <tr> <td><lift:loc>ui_login_password</lift:loc></td> <td><user:password/></td> </tr>
         <tr> <td><lift:loc>ui_login_password_repeat</lift:loc></td> <td><user:confirm/></td> </tr>
+        <tr> <td><lift:loc>ui_sign_up_openid</lift:loc></td> <td><user:openid/></td> </tr>
         <user:save/>
       </tbody>
     </table>