Author: hoang_to
Date: 2009-11-17 05:13:06 -0500 (Tue, 17 Nov 2009)
New Revision: 626
Added:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/portlet/exoadmin/RegisterPortlet/
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/portlet/exoadmin/RegisterPortlet/webui/
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/portlet/exoadmin/RegisterPortlet/webui/configuration.xml
portal/trunk/portlet/exoadmin/src/main/webapp/skin/register/
portal/trunk/portlet/exoadmin/src/main/webapp/skin/register/webui/
portal/trunk/portlet/exoadmin/src/main/webapp/skin/register/webui/component/
portal/trunk/portlet/exoadmin/src/main/webapp/skin/register/webui/component/DefaultStylesheet.css
Modified:
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
Log:
GTNPORTAL-244: Create a simple register account portlet
Added:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
(rev 0)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java 2009-11-17
10:13:06 UTC (rev 626)
@@ -0,0 +1,135 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.account.webui.component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.UserHandler;
+import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.config.annotation.EventConfig;
+import org.exoplatform.webui.core.UIApplication;
+import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
+import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.EventListener;
+import org.exoplatform.webui.event.Event.Phase;
+import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.webui.form.UIFormInputWithActions;
+import org.exoplatform.webui.form.UIFormInputWithActions.ActionData;
+
+/**
+ *
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * @version $Id$
+ *
+ */
+
+@ComponentConfig(
+ lifecycle = UIFormLifecycle.class,
+ template = "system:/groovy/webui/form/UIForm.gtmpl",
+ events = {
+ @EventConfig( listeners = UIRegisterForm.SubscribeActionListener.class),
+ @EventConfig( listeners = UIRegisterForm.ResetActionListener.class, phase =
Phase.DECODE),
+ @EventConfig( name = UIRegisterForm.CheckUsernameAvailability.LISTENER_NAME,
+ listeners = UIRegisterForm.CheckUsernameAvailability.class,
+ phase = Phase.DECODE)
+ }
+)
+public class UIRegisterForm extends UIForm {
+
+ private final static String[] ACTIONS = {"Subscribe", "Reset"};
+
+ public UIRegisterForm() throws Exception{
+ UIFormInputWithActions registerInput = new
UIRegisterInputSet("RegisterInputSet");
+ //Set actions on registerInput 's User Name field
+ List<ActionData> fieldActions = new ArrayList<ActionData>();
+ ActionData checkAvailable = new ActionData();
+ checkAvailable.setActionListener(CheckUsernameAvailability.LISTENER_NAME);
+ checkAvailable.setActionName(CheckUsernameAvailability.LISTENER_NAME);
+ checkAvailable.setActionType(ActionData.TYPE_ICON);
+ checkAvailable.setCssIconClass("SearchIcon");
+ fieldActions.add(checkAvailable);
+ registerInput.setActionField(UIRegisterInputSet.USER_NAME, fieldActions);
+
+ addUIFormInput(registerInput);
+ setActions(ACTIONS);
+ }
+
+ static public class SubscribeActionListener extends
EventListener<UIRegisterForm>{
+ @Override
+ public void execute(Event<UIRegisterForm> event) throws Exception {
+ UIRegisterForm registerForm = event.getSource();
+ OrganizationService orgService =
registerForm.getApplicationComponent(OrganizationService.class);
+ UserHandler userHandler = orgService.getUserHandler();
+ WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
+ UIRegisterInputSet registerInput =
registerForm.getChild(UIRegisterInputSet.class);
+
+ if(registerInput.save(userHandler, context)){
+ //TODO: Send email and add Account Activating feature
+ }
+ }
+ }
+
+ static public class CheckUsernameAvailability extends
EventListener<UIRegisterForm>{
+
+ final static String LISTENER_NAME = "CheckUsernameAvailability";
+
+ @Override
+ public void execute(Event<UIRegisterForm> event) throws Exception
+ {
+ UIRegisterForm registerForm = event.getSource();
+ OrganizationService orgService =
registerForm.getApplicationComponent(OrganizationService.class);
+ UIRegisterInputSet registerInput =
registerForm.getChild(UIRegisterInputSet.class);
+ String typedUsername =
registerInput.getUIStringInput(UIRegisterInputSet.USER_NAME).getValue();
+
+ if(usernameIsUsed(typedUsername, orgService)){
+ WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
+ UIApplication uiApp = context.getUIApplication();
+
+ uiApp.addMessage(new
ApplicationMessage("UIAccountInputSet.msg.user-exist", new String[]{
typedUsername}));
+ }
+ }
+
+ private boolean usernameIsUsed(String username, OrganizationService orgService){
+ UserHandler userHandler = orgService.getUserHandler();
+ try{
+ if( userHandler.findUserByName(username) != null){
+ return true;
+ }
+ }catch(Exception ex){
+ ex.printStackTrace();
+ }
+ return false;
+ }
+ }
+
+ static public class ResetActionListener extends EventListener<UIRegisterForm>{
+ @Override
+ public void execute(Event<UIRegisterForm> event) throws Exception
+ {
+ // TODO Auto-generated method stub
+ UIRegisterForm registerForm = event.getSource();
+ registerForm.reset();
+ }
+ }
+}
Added:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
(rev 0)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java 2009-11-17
10:13:06 UTC (rev 626)
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.account.webui.component;
+
+import org.exoplatform.services.organization.Query;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.UserHandler;
+import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.core.UIApplication;
+import org.exoplatform.webui.form.UIFormInputWithActions;
+import org.exoplatform.webui.form.UIFormStringInput;
+import org.exoplatform.webui.form.validator.EmailAddressValidator;
+import org.exoplatform.webui.form.validator.ExpressionValidator;
+import org.exoplatform.webui.form.validator.MandatoryValidator;
+import org.exoplatform.webui.form.validator.PasswordStringLengthValidator;
+import org.exoplatform.webui.form.validator.ResourceValidator;
+import org.exoplatform.webui.form.validator.StringLengthValidator;
+
+/**
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * @version $Id$
+ *
+ */
+public class UIRegisterInputSet extends UIFormInputWithActions
+{
+ protected static final String USER_NAME = "User Name:";
+
+ protected static final String PASSWORD = "Password:";
+
+ protected static final String CONFIRM_PASSWORD = "Confirm Password:";
+
+ protected static final String FIRST_NAME = "First Name:";
+
+ protected static final String LAST_NAME = "Last Name:";
+
+ protected static final String EMAIL_ADDRESS = "Email Address:";
+
+ public UIRegisterInputSet(String name) throws Exception{
+ super(name);
+
+ addUIFormInput(new UIFormStringInput(USER_NAME, USER_NAME,
null).addValidator(MandatoryValidator.class)
+ .addValidator(StringLengthValidator.class, 3,
30).addValidator(ResourceValidator.class).addValidator(
+ ExpressionValidator.class, "^[\\p{L}][\\p{L}._\\-\\d]+$",
"ResourceValidator.msg.Invalid-char"));
+
+ addUIFormInput(new UIFormStringInput(PASSWORD, PASSWORD,
null).setType(UIFormStringInput.PASSWORD_TYPE)
+
.addValidator(MandatoryValidator.class).addValidator(PasswordStringLengthValidator.class,
6, 30));
+
+ addUIFormInput(new UIFormStringInput(CONFIRM_PASSWORD, CONFIRM_PASSWORD,
null).setType(UIFormStringInput.PASSWORD_TYPE)
+
.addValidator(MandatoryValidator.class).addValidator(PasswordStringLengthValidator.class,
6, 30));
+
+ addUIFormInput(new UIFormStringInput(FIRST_NAME, FIRST_NAME,
null).addValidator(StringLengthValidator.class, 3,
+
45).addValidator(MandatoryValidator.class).addValidator(ExpressionValidator.class,
"^[\\p{L}][\\p{ASCII}]+$",
+
"FirstCharacterNameValidator.msg").addValidator(ExpressionValidator.class,
"^[\\p{L}][\\p{L}._\\- \\d]+$",
+ "ResourceValidator.msg.Invalid-char"));
+
+ addUIFormInput(new UIFormStringInput(LAST_NAME, LAST_NAME,
null).addValidator(StringLengthValidator.class, 3,
+
45).addValidator(MandatoryValidator.class).addValidator(ExpressionValidator.class,
"^[\\p{L}][\\p{ASCII}]+$",
+
"FirstCharacterNameValidator.msg").addValidator(ExpressionValidator.class,
"^[\\p{L}][\\p{L}._\\- \\d]+$",
+ "ResourceValidator.msg.Invalid-char"));
+
+ addUIFormInput(new UIFormStringInput(EMAIL_ADDRESS, EMAIL_ADDRESS,
null).addValidator(MandatoryValidator.class).addValidator(
+ EmailAddressValidator.class));
+ }
+
+ private String getUserName(){
+ return getUIStringInput(USER_NAME).getValue();
+ }
+
+ private String getEmail(){
+ return getUIStringInput(EMAIL_ADDRESS).getValue();
+ }
+
+ private String getPassword(){
+ return getUIStringInput(PASSWORD).getValue();
+ }
+
+ private String getFirstName(){
+ return getUIStringInput(FIRST_NAME).getValue();
+ }
+
+ private String getLastName(){
+ return getUIStringInput(LAST_NAME).getValue();
+ }
+
+ /**
+ * Use this method instead of invokeSetBinding, to avoid abusing reflection
+ * @param user
+ */
+ private void bindingFields(User user){
+ user.setPassword(getPassword());
+ user.setFirstName(getFirstName());
+ user.setLastName(getLastName());
+ user.setEmail(getEmail());
+ }
+
+ public boolean save(UserHandler userHandler, WebuiRequestContext context) throws
Exception
+ {
+ UIApplication uiApp = context.getUIApplication();
+ String pass = getPassword();
+ String confirm_pass = getUIStringInput(CONFIRM_PASSWORD).getValue();
+
+ if (!pass.equals(confirm_pass))
+ {
+ uiApp.addMessage(new
ApplicationMessage("UIAccountForm.msg.password-is-not-match", null));
+ return false;
+ }
+
+ String username = getUserName();
+
+ //Check if user name already existed
+ if (userHandler.findUserByName(username) != null)
+ {
+ Object[] args = {username};
+ uiApp.addMessage(new
ApplicationMessage("UIAccountInputSet.msg.user-exist", args));
+ return false;
+ }
+
+ //Check if mail address is already used
+ Query query = new Query();
+ query.setEmail(getEmail());
+ if (userHandler.findUsers(query).getAll().size() > 0)
+ {
+ Object[] args = {username};
+ uiApp.addMessage(new
ApplicationMessage("UIAccountInputSet.msg.email-exist", args));
+ return false;
+ }
+
+ User user = userHandler.createUserInstance(username);
+ bindingFields(user);
+
+ userHandler.createUser(user, true);//Broadcast user creaton event
+ reset();//Reset the input form
+ return true;
+ }
+}
Added:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java
(rev 0)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java 2009-11-17
10:13:06 UTC (rev 626)
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.account.webui.component;
+
+import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.core.UIPortletApplication;
+import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
+
+/**
+ *
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * @version $Id$
+ *
+ */
+
+@ComponentConfig(lifecycle = UIApplicationLifecycle.class)
+public class UIRegisterPortlet extends UIPortletApplication {
+
+ public UIRegisterPortlet() throws Exception{
+ addChild(UIRegisterForm.class, null, null);
+ }
+}
Added:
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/portlet/exoadmin/RegisterPortlet/webui/configuration.xml
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/portlet/exoadmin/RegisterPortlet/webui/configuration.xml
(rev 0)
+++
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/portlet/exoadmin/RegisterPortlet/webui/configuration.xml 2009-11-17
10:13:06 UTC (rev 626)
@@ -0,0 +1,30 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+
+<webui-configuration>
+ <application>
+
<ui-component-root>org.exoplatform.account.webui.component.UIRegisterPortlet</ui-component-root>
+
<state-manager>org.exoplatform.webui.application.portlet.ParentAppStateManager</state-manager>
+ <application-lifecycle-listeners>
+
<listener>org.exoplatform.portal.application.PortletStatisticLifecycle</listener>
+ </application-lifecycle-listeners>
+ </application>
+</webui-configuration>
Modified: portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml 2009-11-17
09:47:57 UTC (rev 625)
+++ portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml 2009-11-17
10:13:06 UTC (rev 626)
@@ -74,6 +74,15 @@
<skin-name>Default</skin-name>
<css-path>/skin/navigation/webui/component/DefaultStylesheet.css</css-path>
</portlet-skin>
+
+ <!-- Register Portlet skins -->
+
+ <portlet-skin>
+ <application-name>exoadmin</application-name>
+ <portlet-name>RegisterPortlet</portlet-name>
+ <skin-name>Default</skin-name>
+ <css-path>/skin/register/webui/component/DefaultStylesheet.css</css-path>
+ </portlet-skin>
</gatein-resources>
Modified: portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml 2009-11-17 09:47:57
UTC (rev 625)
+++ portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml 2009-11-17 10:13:06
UTC (rev 626)
@@ -79,7 +79,6 @@
</portlet-info>
</portlet>
- <!--
<portlet>
<description xml:lang="EN">Register Portlet</description>
<portlet-name>RegisterPortlet</portlet-name>
@@ -98,14 +97,13 @@
</supports>
<supported-locale>en</supported-locale>
-
<resource-bundle>locale.portlet.exoadmin.RegisterPortlet</resource-bundle>
+
<!--<resource-bundle>locale.portlet.exoadmin.RegisterPortlet</resource-bundle>-->
<portlet-info>
<title>Register Portlet</title>
<short-title>Register Portlet</short-title>
<keywords>Administration</keywords>
</portlet-info>
</portlet>
- -->
<portlet>
<description xml:lang="EN">Group Navigation
Portlet</description>
Added:
portal/trunk/portlet/exoadmin/src/main/webapp/skin/register/webui/component/DefaultStylesheet.css
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/webapp/skin/register/webui/component/DefaultStylesheet.css
(rev 0)
+++
portal/trunk/portlet/exoadmin/src/main/webapp/skin/register/webui/component/DefaultStylesheet.css 2009-11-17
10:13:06 UTC (rev 626)
@@ -0,0 +1,18 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */