[Yanel-commits] rev 50215 - public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/yaneluser

michi at wyona.com michi at wyona.com
Mon Jun 7 13:27:45 CEST 2010


Author: michi
Date: 2010-06-07 13:27:44 +0200 (Mon, 07 Jun 2010)
New Revision: 50215

Modified:
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/yaneluser/EditYanelUserProfileResource.java
Log:
profile data implemented

Modified: public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/yaneluser/EditYanelUserProfileResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/yaneluser/EditYanelUserProfileResource.java	2010-06-07 11:13:36 UTC (rev 50214)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/yaneluser/EditYanelUserProfileResource.java	2010-06-07 11:27:44 UTC (rev 50215)
@@ -10,6 +10,8 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.log4j.Logger;
 
@@ -36,6 +38,11 @@
             updatePassword(oldPassword);
         }
 
+        String email = getEnvironment().getRequest().getParameter("email");
+        if (email != null) {
+            updateProfile(email);
+        }
+
         try {
             return getXMLAsStream();
         } catch(Exception e) {
@@ -129,8 +136,34 @@
     }
 
     /**
+     * Updates the user profile
      *
+     * @param email E-Mail address of user
      */
+    private void updateProfile(String email) {
+        if (email == null || ("").equals(email)) {
+            setTransformerParameter("error", "emailNotSet");
+        } else if (!validateEmail(email)) {
+            setTransformerParameter("error", "emailNotValid");
+        } else {
+            try {
+                String userId = getUserId();
+                User user = realm.getIdentityManager().getUserManager().getUser(userId);
+                user.setEmail(getEnvironment().getRequest().getParameter("email"));
+                user.setName(getEnvironment().getRequest().getParameter("userName"));
+                user.setLanguage(getEnvironment().getRequest().getParameter("user-profile-language"));
+                user.save();
+                setTransformerParameter("success", "Profile updated successfully");
+            } catch (Exception e) {
+                log.error(e, e);
+                setTransformerParameter("error", e.getMessage());
+            }
+        }
+    }
+
+    /**
+     *
+     */
     private void setTransformerParameter(String name, String value) {
         transformerParameterName = name;
         transformerParameterValue = value;
@@ -151,4 +184,18 @@
             log.error(e, e);
         }
     }
+
+    /**
+     * This method checks if the specified email is valid against a regex
+     *
+     * @param email
+     * @return true if email is valid
+     */
+    private boolean validateEmail(String email) {
+        String emailRegEx = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
+        Pattern pattern = Pattern.compile(emailRegEx);
+        Matcher matcher = pattern.matcher(email);
+
+        return matcher.find();
+    }
 }



More information about the Yanel-commits mailing list