]> git.mxchange.org Git - addressbook-war.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 22 Jun 2017 19:59:50 +0000 (21:59 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 22 Jun 2017 19:59:50 +0000 (21:59 +0200)
- moved bean to proper package as it is user-specific registration

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java [deleted file]
src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionController.java [deleted file]
src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionController.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java
deleted file mode 100644 (file)
index 017d267..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.register;
-
-import java.text.MessageFormat;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.addressbook.beans.BaseAddressbookController;
-import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
-import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
-import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.UserContact;
-import org.mxchange.jcoreee.utils.FacesUtils;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
-import org.mxchange.jusercore.exceptions.DataRepeatMismatchException;
-import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
-import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-
-/**
- * A web bean for user registration
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("registerController")
-@SessionScoped
-public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookController implements AddressbookUserRegisterWebSessionController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 47_828_986_719_691_592L;
-
-       /**
-        * Administrative user controller
-        */
-       @Inject
-       private AddressbookAdminUserWebRequestController adminUserController;
-
-       /**
-        * Contact controller
-        */
-       @Inject
-       private AddressbookContactWebSessionController contactController;
-
-       /**
-        * Features controller
-        */
-       @Inject
-       private AddressbookFeaturesWebApplicationController featureController;
-
-       /**
-        * Remote register session-scoped bean
-        */
-       private UserRegistrationSessionBeanRemote registerBean;
-
-       /**
-        * User controller
-        */
-       @Inject
-       private AddressbookUserWebSessionController userController;
-
-       /**
-        * An en event fireable when a new user has registered
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserRegisteredEvent> userRegisteredEvent;
-
-       /**
-        * Default constructor
-        */
-       public AddressbookUserRegisterWebSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public String doFinishRegistration () {
-               // Is registration enabled?
-               if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
-                       // Is not enabled
-                       throw new FaceletException("Registration is disabled."); //NOI18N
-               }
-
-               // Get user instance
-               User user = this.userController.createUserInstance(true);
-
-               // Is the user already used?
-               if (null == user) {
-                       // user must be set
-                       throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
-               } else if (!this.userController.isRequiredPersonalDataSet()) {
-                       // Not all required fields are set
-                       throw new FaceletException("Not all required fields are set."); //NOI18N
-               } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
-                       // User name is already used
-                       throw new FaceletException(new UserNameAlreadyRegisteredException(user));
-               } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
-                       // Email address has already been taken
-                       throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
-               } else if (!this.contactController.isSameEmailAddressEntered()) {
-                       // Not same email address entered
-                       throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
-               } else if (!this.userController.isSamePasswordEntered()) {
-                       // Not same password entered
-                       throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N
-               }
-
-               // Encrypt password
-               String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword());
-
-               // Set it here
-               user.setUserEncryptedPassword(encryptedPassword);
-
-               // Is developer mode?
-               if (this.isDebugModeEnabled("register")) { //NOI18N
-                       // For debugging/programming only:
-                       user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
-               } else {
-                       // No debugging of this part
-                       user.setUserAccountStatus(UserAccountStatus.UNCONFIRMED);
-
-                       // Ask EJB for generating a not-existing confirmation key
-                       String confirmKey = this.registerBean.generateConfirmationKey(user);
-
-                       // Set it in user
-                       user.setUserConfirmKey(confirmKey);
-               }
-
-               try {
-                       // Get base URL
-                       String baseUrl = FacesUtils.generateBaseUrl();
-
-                       // Call bean
-                       User registeredUser = this.registerBean.registerUser(user, baseUrl);
-
-                       // The id number should be set
-                       assert (registeredUser.getUserId() instanceof Long) : "registeredUser.userId is null after registerUser() was called."; //NOI18N
-
-                       // Fire event
-                       this.userRegisteredEvent.fire(new UserRegisteredEvent(registeredUser));
-
-                       // All fine, redirect to proper page
-                       return "register_done"; //NOI18N
-               } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
-                       // Continue to throw
-                       throw new FaceletException(ex);
-               }
-       }
-
-       @Override
-       public String doRegisterMultiPage1 () {
-               // Is registration enabled?
-               if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
-                       // Is not enabled
-                       throw new FaceletException("Registration is disabled."); //NOI18N
-               }
-
-               // Get user instance
-               User user = this.userController.createUserInstance(false);
-
-               // First check if user is not null and user name is not used + if same email address is entered
-               if (null == user) {
-                       // user must be set
-                       throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
-               } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
-                       // User name is already used
-                       throw new FaceletException(new UserNameAlreadyRegisteredException(user));
-               } else if (!this.contactController.isSameEmailAddressEntered()) {
-                       // Not same email address entered
-                       throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
-               }
-
-               // Create half contact instance with email address
-               Contact contact = new UserContact();
-               contact.setContactEmailAddress(this.contactController.getEmailAddress());
-
-               // Set contact in user
-               user.setUserContact(contact);
-
-               // Check if email address is registered
-               if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
-                       // Email address has already been taken
-                       throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
-               }
-
-               // Now only redirect to next page as the JSF does it
-               return "user_register_page2"; //NOI18N
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/addressbook-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new FaceletException(ex);
-               }
-       }
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionController.java b/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionController.java
deleted file mode 100644 (file)
index 82b4026..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.register;
-
-import java.io.Serializable;
-
-/**
- * An interface for registration web controllers
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookUserRegisterWebSessionController extends Serializable {
-
-       /**
-        * Registers the user, if not found. Otherwise this method should throw an
-        * exception.
-        * <p>
-        * @return Redirection target
-        */
-       String doFinishRegistration ();
-
-       /**
-        * Handles registration request send from first page. The (maybe) entered
-        * user name and email address is not used and that privacy and T&C are
-        * accepted.
-        * <p>
-        * @return Redirect
-        */
-       String doRegisterMultiPage1 ();
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java
new file mode 100644 (file)
index 0000000..07ff07a
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.user.register;
+
+import java.text.MessageFormat;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.BaseAddressbookController;
+import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
+import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
+import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController;
+import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.UserContact;
+import org.mxchange.jcoreee.utils.FacesUtils;
+import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
+import org.mxchange.jusercore.exceptions.DataRepeatMismatchException;
+import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
+import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+
+/**
+ * A web bean for user registration
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("registerController")
+@SessionScoped
+public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookController implements AddressbookUserRegisterWebSessionController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 47_828_986_719_691_592L;
+
+       /**
+        * Administrative user controller
+        */
+       @Inject
+       private AddressbookAdminUserWebRequestController adminUserController;
+
+       /**
+        * Contact controller
+        */
+       @Inject
+       private AddressbookContactWebSessionController contactController;
+
+       /**
+        * Features controller
+        */
+       @Inject
+       private AddressbookFeaturesWebApplicationController featureController;
+
+       /**
+        * Remote register session-scoped bean
+        */
+       private UserRegistrationSessionBeanRemote registerBean;
+
+       /**
+        * User controller
+        */
+       @Inject
+       private AddressbookUserWebSessionController userController;
+
+       /**
+        * An en event fireable when a new user has registered
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserRegisteredEvent> userRegisteredEvent;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookUserRegisterWebSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public String doFinishRegistration () {
+               // Is registration enabled?
+               if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
+                       // Is not enabled
+                       throw new FaceletException("Registration is disabled."); //NOI18N
+               }
+
+               // Get user instance
+               User user = this.userController.createUserInstance(true);
+
+               // Is the user already used?
+               if (null == user) {
+                       // user must be set
+                       throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
+               } else if (!this.userController.isRequiredPersonalDataSet()) {
+                       // Not all required fields are set
+                       throw new FaceletException("Not all required fields are set."); //NOI18N
+               } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
+                       // User name is already used
+                       throw new FaceletException(new UserNameAlreadyRegisteredException(user));
+               } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
+                       // Email address has already been taken
+                       throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+               } else if (!this.contactController.isSameEmailAddressEntered()) {
+                       // Not same email address entered
+                       throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
+               } else if (!this.userController.isSamePasswordEntered()) {
+                       // Not same password entered
+                       throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N
+               }
+
+               // Encrypt password
+               String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword());
+
+               // Set it here
+               user.setUserEncryptedPassword(encryptedPassword);
+
+               // Is developer mode?
+               if (this.isDebugModeEnabled("register")) { //NOI18N
+                       // For debugging/programming only:
+                       user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
+               } else {
+                       // No debugging of this part
+                       user.setUserAccountStatus(UserAccountStatus.UNCONFIRMED);
+
+                       // Ask EJB for generating a not-existing confirmation key
+                       String confirmKey = this.registerBean.generateConfirmationKey(user);
+
+                       // Set it in user
+                       user.setUserConfirmKey(confirmKey);
+               }
+
+               try {
+                       // Get base URL
+                       String baseUrl = FacesUtils.generateBaseUrl();
+
+                       // Call bean
+                       User registeredUser = this.registerBean.registerUser(user, baseUrl);
+
+                       // The id number should be set
+                       assert (registeredUser.getUserId() instanceof Long) : "registeredUser.userId is null after registerUser() was called."; //NOI18N
+
+                       // Fire event
+                       this.userRegisteredEvent.fire(new UserRegisteredEvent(registeredUser));
+
+                       // All fine, redirect to proper page
+                       return "register_done"; //NOI18N
+               } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
+                       // Continue to throw
+                       throw new FaceletException(ex);
+               }
+       }
+
+       @Override
+       public String doRegisterMultiPage1 () {
+               // Is registration enabled?
+               if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
+                       // Is not enabled
+                       throw new FaceletException("Registration is disabled."); //NOI18N
+               }
+
+               // Get user instance
+               User user = this.userController.createUserInstance(false);
+
+               // First check if user is not null and user name is not used + if same email address is entered
+               if (null == user) {
+                       // user must be set
+                       throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
+               } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
+                       // User name is already used
+                       throw new FaceletException(new UserNameAlreadyRegisteredException(user));
+               } else if (!this.contactController.isSameEmailAddressEntered()) {
+                       // Not same email address entered
+                       throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
+               }
+
+               // Create half contact instance with email address
+               Contact contact = new UserContact();
+               contact.setContactEmailAddress(this.contactController.getEmailAddress());
+
+               // Set contact in user
+               user.setUserContact(contact);
+
+               // Check if email address is registered
+               if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
+                       // Email address has already been taken
+                       throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+               }
+
+               // Now only redirect to next page as the JSF does it
+               return "user_register_page2"; //NOI18N
+       }
+
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/addressbook-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new FaceletException(ex);
+               }
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionController.java
new file mode 100644 (file)
index 0000000..6fc8087
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.user.register;
+
+import java.io.Serializable;
+
+/**
+ * An interface for registration web controllers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookUserRegisterWebSessionController extends Serializable {
+
+       /**
+        * Registers the user, if not found. Otherwise this method should throw an
+        * exception.
+        * <p>
+        * @return Redirection target
+        */
+       String doFinishRegistration ();
+
+       /**
+        * Handles registration request send from first page. The (maybe) entered
+        * user name and email address is not used and that privacy and T&C are
+        * accepted.
+        * <p>
+        * @return Redirect
+        */
+       String doRegisterMultiPage1 ();
+
+}