]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
fixed my email address
authorRoland Häder <roland@mxchange.org>
Mon, 25 Apr 2016 11:42:26 +0000 (13:42 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 27 Apr 2016 19:54:21 +0000 (21:54 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java
src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/validators/password/PizzaUserPasswordValidator.java [new file with mode: 0644]

index 69b8c420e5ce4e9cb8ce85d175a9c02a5c67f993..71aa303bc08eb060154851d299cf23803530274c 100644 (file)
@@ -161,7 +161,7 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr
                contact.setContactCellphoneNumber(this.getCellphoneNumber());
 
                // Set contact in customer
-               customer.setContact(contact);
+               customer.setCustomerContact(contact);
 
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
index 32656b23234b11b1d692c737a32a0f4c16a59b33..9c77a095bf407420fc6d68d2e7c7ffb3d26105cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder<roland@mxchange.org>
+ * Copyright (C) 2016 Roland Haeder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
index ba780e5cf0f25976a5de432baa3a547863928e68..29fe878ace88feaaebb40e7288a3f027adc536d1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder<roland@mxchange.org>
+ * Copyright (C) 2016 Roland Haeder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
diff --git a/src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java
new file mode 100644 (file)
index 0000000..438f252
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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.pizzaapplication.beans.profile;
+
+import java.text.MessageFormat;
+import javax.enterprise.context.RequestScoped;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+
+/**
+ * A web request bean for user profiles
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named (value = "profileController")
+@RequestScoped
+public class PizzaUserProfileWebRequestBean implements PizzaUserProfileWebRequestController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 187_687_145_286_710L;
+
+       /**
+        * Login controller
+        */
+       @Inject
+       private PizzaUserLoginWebSessionController loginController;
+
+       /**
+        * User controller
+        */
+       @Inject
+       private PizzaUserWebSessionController userController;
+
+       @Override
+       public boolean isProfileLinkVisibleById (final Long userId) {
+               // Init user instance
+               User u = null;
+
+               try {
+                       // Try to get it
+                       u = this.userController.lookupUserById(userId);
+               } catch (final UserNotFoundException ex) {
+                       // Throw again
+                       throw new FaceletException(ex);
+               }
+
+               // Is it null?
+               if (null == u) {
+                       // Not found, not visible.
+                       return false;
+               }
+
+               // Ask other method
+               return this.isProfileLinkVisibleByUser(u);
+       }
+
+       @Override
+       public boolean isProfileLinkVisibleByUser (final User user) {
+               // Check on user
+               if (null == user) {
+                       /*
+                        * Not set, means wrong invocation of this method as the user
+                        * instance needs to be set first.
+                        */
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       /*
+                        * If the id number is not set it means that the user instance has
+                        * not been persisted and the JPA has not been flushed. Or a
+                        * "virgin" instance (e.g. from registration) has been used.
+                        */
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       /*
+                        * The id number is set invalid for an unknown reason.
+                        */
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               } else if (user.getUserProfileMode() == null) {
+                       /*
+                        * Possibly an out-dated user profile is being used. This should not
+                        * happen.
+                        */
+                       throw new NullPointerException("user.userProfileMode is null"); //NOI18N
+               }
+
+               // Get profile mode from user instance (safe now)
+               ProfileMode profileMode = user.getUserProfileMode();
+
+               // Check all conditions (except for admin)
+               // TODO: Add admin role somehow?
+               return ((profileMode.equals(ProfileMode.PUBLIC)) ||
+                               (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS)));
+       }
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/profilemode/PizzaProfileModeWebApplicationBean.java
new file mode 100644 (file)
index 0000000..e60ab41
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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.pizzaapplication.beans.profilemode;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+
+/**
+ * A profile mode bean
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("profileModeController")
+@ApplicationScoped
+public class PizzaProfileModeWebApplicationBean implements PizzaProfileModeWebApplicationController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 835_482_364_189L;
+
+       /**
+        * Default constructor
+        */
+       public PizzaProfileModeWebApplicationBean () {
+       }
+
+       @Override
+       public ProfileMode[] getAllProfileModes () {
+               // Return it
+               return ProfileMode.values();
+       }
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/validators/password/PizzaUserPasswordValidator.java b/src/java/org/mxchange/pizzaapplication/validators/password/PizzaUserPasswordValidator.java
new file mode 100644 (file)
index 0000000..7b86c4a
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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.pizzaapplication.validators.password;
+
+import java.text.MessageFormat;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+import org.mxchange.jusercore.container.login.LoginContainer;
+import org.mxchange.jusercore.container.login.UserLoginContainer;
+import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+
+/**
+ * A validator for validating passwords (if they match with stored)
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesValidator (value = "PizzaUserPasswordValidator")
+public class PizzaUserPasswordValidator extends BaseStringValidator implements Validator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 48_581_795_687_317L;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * User login controller
+        */
+       private PizzaUserLoginWebSessionController loginController;
+
+       /**
+        * Default constructor
+        */
+       public PizzaUserPasswordValidator () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+               }
+       }
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // The required field
+               String[] requiredFields = {"currentPassword"}; //NOI18N
+
+               // Pre-validation (example: not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFields, false);
+
+               // value is known to be an entered password, so instance login container
+               LoginContainer container = new UserLoginContainer(this.loginController.getLoggedInUser(), (String) value);
+
+               // Test it here
+               if (!UserUtils.ifPasswordMatches(container, this.loginController.getLoggedInUser())) {
+                       // Password mismatches
+                       throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Password mismatching.", "The password the user has entered does not match the stored password.")); //NOI18N
+               }
+
+               // Trace message
+               this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
+       }
+}