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));
/*
- * 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
/*
- * 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
--- /dev/null
+/*
+ * 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)));
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
--- /dev/null
+/*
+ * 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
+ }
+}