+++ /dev/null
-/*
- * 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.resendlink;
-
-import java.text.MessageFormat;
-import java.util.Locale;
-import javax.ejb.EJB;
-import javax.ejb.EJBException;
-import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
-import org.mxchange.jusercore.model.resendlink.ResendLinkSessionBeanRemote;
-import org.mxchange.jusercore.model.user.LoginUser;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-
-/**
- * A session-based EJB for resending confirmation links
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "resendLink", description = "A bean resending confirmation links")
-public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBean implements ResendLinkSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 71_546_726_857_195_360L;
-
- /**
- * Registration bean
- */
- @EJB
- private UserRegistrationSessionBeanRemote registerBean;
-
- /**
- * Regular user bean
- */
- @EJB
- private UserSessionBeanRemote userBean;
-
- /**
- * Default constructor
- */
- public AddressbookResendLinkSessionBean () {
- // Call super constructor
- super();
- }
-
- @Override
- public void resendConfirmationLink (final User user, final Locale locale, final String baseUrl) throws UserNotFoundException, UserStatusConfirmedException, UserStatusLockedException {
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: user={1},locale={2},baseUrl={3} - CALLED!", this.getClass().getSimpleName(), user, locale, baseUrl)); //NOI18N
-
- // The user instance should be valid
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
- } else if (!this.userBean.ifUserExists(user)) {
- // User not found
- throw new UserNotFoundException(user);
- } else if (user.getUserConfirmKey() == null) {
- // Throw NPE again
- throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
- } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
- // User account status is not UNCONFIRMED
- throw new UserStatusConfirmedException(user);
- } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
- // User account status is not UNCONFIRMED
- throw new UserStatusLockedException(user);
- } else if (null == locale) {
- // Locale should be set
- throw new NullPointerException("locale is null"); //NOI18N
- }
-
- // Get new registration key
- String confirmationKey = this.registerBean.generateConfirmationKey(user);
-
- // Get managed instance
- User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
-
- // Set it in user
- managedUser.setUserConfirmKey(confirmationKey);
-
- // Init variable
- Address emailAddress;
-
- try {
- // Create email address and set
- emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress());
- } catch (final AddressException ex) {
- // Throw again
- throw new EJBException(ex);
- }
-
- // Send email
- // @TODO: Internationlize the subject line somehow
- this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user, baseUrl); //NOI18N
-
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: EXIT!", this.getClass().getSimpleName())); //NOI18N
- }
-
-}
import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jcontacts.contact.utils.ContactUtils;
import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
/**
+++ /dev/null
-/*
- * 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.jusercore.model.email_address;
-
-import java.text.MessageFormat;
-import java.util.GregorianCalendar;
-import java.util.List;
-import javax.ejb.EJB;
-import javax.ejb.EJBException;
-import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.UserUtils;
-
-/**
- * A session-scoped bean for changing email addresses
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "userEmailChange", description = "A bean handling user email changes")
-public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookDatabaseBean implements UserEmailChangeSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 182_698_165_971_548L;
-
- /**
- * User bean
- */
- @EJB
- private UserSessionBeanRemote userBean;
-
- /**
- * Default constructor
- */
- public AddressbookUserEmailChangeSessionBean () {
- // Call super constructor
- super();
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<String> allQueuedAddresses () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get named query
- Query query = this.getEntityManager().createNamedQuery("AllEmailAddressChanges", String.class); //NOI18N
-
- // Get all entries
- List<String> emailAddresses = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N
-
- // Return it
- return emailAddresses;
- }
-
- @Override
- public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailChange, final String baseUrl) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange: emailChange={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), emailChange, baseUrl)); //NOI18N
-
- // Email address change should be valid
- if (null == emailChange) {
- // Abort here
- throw new NullPointerException("emailChange is null"); //NOI18N
- } else if (emailChange.getEmailChangeUser() == null) {
- // Throw NPE again
- throw new NullPointerException("emailChange.emailChangeUser is null"); //NOI18N
- } else if (emailChange.getEmailChangeUser().getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("emailChange.emailChangeUser.userId is null"); //NOI18N
- } else if (emailChange.getEmailChangeUser().getUserId() < 1) {
- // Not valid id
- throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userId={0} is invalid.", emailChange.getEmailChangeUser().getUserId())); //NOI18N
- } else if (!this.userBean.ifUserExists(emailChange.getEmailChangeUser())) {
- // User does not exist
- throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailChange.getEmailChangeId())); //NOI18N
- } else if (emailChange.getEmailAddress().trim().isEmpty()) {
- // Email address is empty
- throw new IllegalArgumentException("emailChange.emaiLAddress is empty."); //NOI18N
- } else if (this.isEmailAddressEnqueued(emailChange.getEmailAddress())) {
- // Email address is already enqueued
- throw new EJBException(MessageFormat.format("Email address {0} is already enqueued.", emailChange.getEmailAddress())); //NOI18N
- }
-
- // The email change is not (yet) there, add secure hash and "created" timestamp
- emailChange.setEmailChangeCreated(new GregorianCalendar());
- this.generateSecureHash(emailChange);
-
- // Make user managed
- emailChange.setEmailChangeUser(this.getManagedUser(emailChange.getEmailChangeUser()));
-
- // Persist it
- //@TODO Fix email delivery then allow this: this.getEntityManager().persist(emailChange);
- // Init variable
- Address emailAddress;
-
- try {
- // Create email address and set
- emailAddress = new InternetAddress(emailChange.getEmailAddress());
- } catch (final AddressException ex) {
- // Throw again
- throw new EJBException(ex);
- }
-
- // Send email
- this.sendEmail("Email change", "email_change", emailAddress, emailChange.getEmailChangeUser(), baseUrl); //NOI18N
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange - EXIT!", this.getClass().getSimpleName())); //NOI18N
- }
-
- @Override
- public boolean isEmailAddressEnqueued (final String emailAddress) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N
-
- // Create query instance
- Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByEmail"); //NOI18N
-
- // Add email address as parameter
- query.setParameter("email", emailAddress); //NOI18N
-
- // Initialize variable
- boolean isFound = false;
-
- // Try it
- try {
- // Try to get single result
- ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult();
-
- // Found it
- isFound = true;
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logException(ex);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N
-
- // Return it
- return isFound;
- }
-
- @Override
- public void updateEmailAddress (final ChangeableEmailAddress emailAddress) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N
-
- // Email address change should be valid
- if (null == emailAddress) {
- // Abort here
- throw new NullPointerException("emailAddress is null"); //NOI18N
- } else if (emailAddress.getEmailChangeId() == null) {
- // Throw NPE again
- throw new NullPointerException("emailAddress.emailChangeId is null"); //NOI18N
- } else if (emailAddress.getEmailChangeId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("emailAddress.emailChangeId={0} is not valid.", emailAddress.getEmailChangeId())); //NOI18N
- } else if (emailAddress.getEmailAddress().trim().isEmpty()) {
- // Email address is empty
- throw new IllegalArgumentException("emailAddress.emaiLAddress is empty."); //NOI18N
- } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
- // User does not exist
- throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
- } else if (!this.isEmailAddressEnqueued(emailAddress.getEmailAddress())) {
- // Email address is not enqueued
- throw new EJBException(MessageFormat.format("Email address {0} is not enqueued.", emailAddress.getEmailAddress())); //NOI18N
- }
-
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- /**
- * Generates a secure, unique hash for given email address change. This
- * requires to check if the hash is really not there.
- * <p>
- * @param emailAddressChange Email address change
- */
- private void generateSecureHash (final ChangeableEmailAddress emailAddressChange) {
- // Email address change should be valid
- if (null == emailAddressChange) {
- // Abort here
- throw new NullPointerException("emailAddressChange is null"); //NOI18N
- } else if (emailAddressChange.getEmailAddress().trim().isEmpty()) {
- // Email address is empty
- throw new IllegalArgumentException("emailAddressChange.emaiLAddress is empty."); //NOI18N
- }
-
- // Initialize loop with null
- String hash = null;
-
- // Default is not used
- boolean isUsed = true;
-
- // Search for free hash
- while (isUsed) {
- // Generate hash, there is already in UserUtils a nice method that can be used for this purpose.
- hash = UserUtils.encryptPassword(String.format("%s:%s", emailAddressChange.getEmailAddress(), emailAddressChange.toString())); //NOI18N
-
- // The hash *may* be unique, better test it
- Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByHash", EmailAddressChange.class); //NOI18N
-
- // Set hash as parameter
- query.setParameter("hash", hash); //NOI18N
-
- // Try to get single result
- try {
- // Get single result
- ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult();
- } catch (final NoResultException ex) {
- // Not found
- isUsed = false;
- }
- }
-
- // hash should not be null and set
- assert (hash != null) : "hash is null"; //NOI18N
- assert (!hash.isEmpty()) : "hash is empty"; //NOI18N
-
- // Set it in email change
- emailAddressChange.setEmailChangeHash(hash);
- }
-
-}
import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
import org.mxchange.jusercore.model.user.UserUtils;
+++ /dev/null
-/*
- * 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.jusercore.model.register;
-
-import java.text.MessageFormat;
-import javax.ejb.EJB;
-import javax.ejb.EJBException;
-import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
-import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
-import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.LoginUser;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.UserUtils;
-
-/**
- * A session-scoped bean for user registration
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "register", description = "A bean handling the user registration")
-public class AddressbookUserRegistrationSessionBean extends BaseAddressbookDatabaseBean implements UserRegistrationSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 12_348_958_986_818_627L;
-
- /**
- * Administrative user bean
- */
- @EJB
- private AdminUserSessionBeanRemote adminUserBean;
-
- /**
- * Regular user EJB
- */
- @EJB
- private UserSessionBeanRemote userBean;
-
- /**
- * Default constructor
- */
- public AddressbookUserRegistrationSessionBean () {
- // Call super constructor
- super();
- }
-
- @Override
- public String generateConfirmationKey (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
-
- // user should not be null
- if (null == user) {
- // Abort here
- throw new NullPointerException("user is null"); //NOI18N
- }
-
- // Create named instance
- Query query = this.getEntityManager().createNamedQuery("SearchUserByConfirmKey", LoginUser.class); //NOI18N
-
- // Init confirmation key
- String confirmationKey = null;
-
- // Find a free one
- while (confirmationKey == null) {
- // Create new one
- String key = UserUtils.generatedConfirmationKey(user);
-
- // Set key as parameter
- query.setParameter("confirmKey", key); //NOI18N
-
- // Try it
- try {
- // Get contact instance
- Contact contact = (Contact) query.getSingleResult();
-
- // Warning message
- this.getLoggerBeanLocal().logWarning(MessageFormat.format("{0}.generateConfirmationKey: key {1} already found: contact.contactId={2}", this.getClass().getSimpleName(), key, contact.getContactId())); //NOI18N
- } catch (final NoResultException ex) {
- // Not found, normal case
- confirmationKey = key;
- break;
- }
- }
-
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: confirmationKey={1} - EXIT!", this.getClass().getSimpleName(), confirmationKey)); //NOI18N
-
- // Return it
- return confirmationKey;
- }
-
- @Override
- public boolean isEmailAddressRegistered (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
-
- // Check bean
- assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
-
- // user should not be null
- if (null == user) {
- // Abort here
- throw new NullPointerException("user is null"); //NOI18N
- }
-
- // Call other bean
- return this.userBean.isEmailAddressRegistered(user);
- }
-
- @Override
- public boolean isUserNameRegistered (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
-
- // Check bean
- assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
-
- // user should not be null
- if (null == user) {
- // Abort here
- throw new NullPointerException("user is null"); //NOI18N
- }
-
- // Call other bean
- return this.userBean.isUserNameRegistered(user);
- }
-
- @Override
- public User registerUser (final User user, final String baseUrl) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
-
- // user should not be null
- if (null == user) {
- // Abort here
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserContact() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userContact is null"); //NOI18N
- } else if (user.getUserContact().getContactEmailAddress() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userContact.contactEmailAddress is null"); //NOI18N
- } else if (user.getUserContact().getContactEmailAddress().isEmpty()) {
- // Is empty
- throw new IllegalArgumentException("user.userContact.contactEmailAddress is empty"); //NOI18N
- }
-
- // Check if user is registered
- if (this.isUserNameRegistered(user)) {
- // Abort here
- throw new UserNameAlreadyRegisteredException(user);
- } else if (this.isEmailAddressRegistered(user)) {
- // Abort here
- throw new EmailAddressAlreadyRegisteredException(user);
- }
-
- // Call other EJB
- User addedUser = this.adminUserBean.addUser(user);
-
- // Init variable
- Address emailAddress;
-
- try {
- // Create email address and set
- emailAddress = new InternetAddress(addedUser.getUserContact().getContactEmailAddress());
- } catch (final AddressException ex) {
- // Throw again
- throw new EJBException(ex);
- }
-
- // Send email
- // @TODO: Internationlize the subject line somehow
- this.sendEmail("Registration", "registration", emailAddress, addedUser, baseUrl); //NOI18N
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: addedUser={1},addedUser.userId={2} - EXIT!", this.getClass().getSimpleName(), addedUser, addedUser.getUserId())); //NOI18N
-
- // Return it
- return addedUser;
- }
-
-}
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
/**
// Send out email
// @TODO externalize subject line
- this.sendEmail("Account locked", "account_locked", emailAddress, managedUser, baseUrl); //NOI18N
+ this.sendEmail("User account locked", "user_account_locked", emailAddress, managedUser, baseUrl, null); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
// Send out email
// @TODO externalize subject line
- this.sendEmail("Account unlocked", "account_unlocked", emailAddress, managedUser, baseUrl); //NOI18N
+ this.sendEmail("User account unlocked", "user_account_unlocked", emailAddress, managedUser, baseUrl, null); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
import javax.persistence.Query;
import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.ContactUtils;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
/**
}
// Send out email
- this.sendEmail("Account confirmed", "account_confirmed", emailAddress, updatedUser, baseUrl); //NOI18N
+ this.sendEmail("User account confirmed", "user_account_confirmed", emailAddress, updatedUser, baseUrl, null); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
// Copy all data
- managedUser.copyAll(user);
+ UserUtils.copyAll(user, managedUser);
// Set as updated
managedUser.setUserUpdated(new GregorianCalendar());
}
// Send email to user
- this.sendEmail("User password change", "user_password_change", emailAddress, user, baseUrl); //NOI18N
+ this.sendEmail("User password change", "user_password_change", emailAddress, user, baseUrl, null); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
// Copy all data
- managedUser.copyAll(user);
+ UserUtils.copyAll(user, managedUser);
// Set as updated
managedUser.setUserUpdated(new GregorianCalendar());
this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: managedContact.contactId={0}", managedContact.getContactId())); //NOI18N
// Copy all
- managedContact.copyAll(user.getUserContact());
+ ContactUtils.copyAll(user.getUserContact(), managedContact);
// Set it back in user
user.setUserContact(managedContact);
--- /dev/null
+/*
+ * 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.jusercore.model.user.email_address;
+
+import java.text.MessageFormat;
+import java.util.GregorianCalendar;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
+import org.mxchange.jusercore.model.email_address.EmailAddressChange;
+import org.mxchange.jusercore.model.email_address.UserEmailChangeSessionBeanRemote;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.UserUtils;
+
+/**
+ * A session-scoped bean for changing email addresses
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "userEmailChange", description = "A bean handling user email changes")
+public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookDatabaseBean implements UserEmailChangeSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 182_698_165_971_548L;
+
+ /**
+ * User bean
+ */
+ @EJB
+ private UserSessionBeanRemote userBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookUserEmailChangeSessionBean () {
+ // Call super constructor
+ super();
+ }
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<String> allQueuedAddresses () {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+ // Get named query
+ Query query = this.getEntityManager().createNamedQuery("AllEmailAddressChanges", String.class); //NOI18N
+
+ // Get all entries
+ List<String> emailAddresses = query.getResultList();
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N
+
+ // Return it
+ return emailAddresses;
+ }
+
+ @Override
+ public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailChange, final String baseUrl) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange: emailChange={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), emailChange, baseUrl)); //NOI18N
+
+ // Email address change should be valid
+ if (null == emailChange) {
+ // Abort here
+ throw new NullPointerException("emailChange is null"); //NOI18N
+ } else if (emailChange.getEmailChangeUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailChange.emailChangeUser is null"); //NOI18N
+ } else if (emailChange.getEmailChangeUser().getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailChange.emailChangeUser.userId is null"); //NOI18N
+ } else if (emailChange.getEmailChangeUser().getUserId() < 1) {
+ // Not valid id
+ throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userId={0} is invalid.", emailChange.getEmailChangeUser().getUserId())); //NOI18N
+ } else if (!this.userBean.ifUserExists(emailChange.getEmailChangeUser())) {
+ // User does not exist
+ throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailChange.getEmailChangeId())); //NOI18N
+ } else if (emailChange.getEmailAddress().trim().isEmpty()) {
+ // Email address is empty
+ throw new IllegalArgumentException("emailChange.emaiLAddress is empty."); //NOI18N
+ } else if (this.isEmailAddressEnqueued(emailChange.getEmailAddress())) {
+ // Email address is already enqueued
+ throw new EJBException(MessageFormat.format("Email address {0} is already enqueued.", emailChange.getEmailAddress())); //NOI18N
+ }
+
+ // The email change is not (yet) there, add secure hash and "created" timestamp
+ emailChange.setEmailChangeCreated(new GregorianCalendar());
+ this.generateSecureHash(emailChange);
+
+ // Persist it
+ //@TODO Fix email delivery then allow this: this.getEntityManager().persist(emailChange);
+ // Init variable
+ Address emailAddress;
+
+ try {
+ // Create email address and set
+ emailAddress = new InternetAddress(emailChange.getEmailAddress());
+ } catch (final AddressException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+
+ // Send email
+ this.sendEmail("User email change", "user_email_change", emailAddress, emailChange.getEmailChangeUser(), baseUrl, null); //NOI18N
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange - EXIT!", this.getClass().getSimpleName())); //NOI18N
+ }
+
+ @Override
+ public boolean isEmailAddressEnqueued (final String emailAddress) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N
+
+ // Create query instance
+ Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByEmail"); //NOI18N
+
+ // Add email address as parameter
+ query.setParameter("email", emailAddress); //NOI18N
+
+ // Initialize variable
+ boolean isFound = false;
+
+ // Try it
+ try {
+ // Try to get single result
+ ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult();
+
+ // Found it
+ isFound = true;
+ } catch (final NoResultException ex) {
+ // Log it
+ this.getLoggerBeanLocal().logException(ex);
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N
+
+ // Return it
+ return isFound;
+ }
+
+ @Override
+ public void updateEmailAddress (final ChangeableEmailAddress emailAddress) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N
+
+ // Email address change should be valid
+ if (null == emailAddress) {
+ // Abort here
+ throw new NullPointerException("emailAddress is null"); //NOI18N
+ } else if (emailAddress.getEmailChangeId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailAddress.emailChangeId is null"); //NOI18N
+ } else if (emailAddress.getEmailChangeId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("emailAddress.emailChangeId={0} is not valid.", emailAddress.getEmailChangeId())); //NOI18N
+ } else if (emailAddress.getEmailAddress().trim().isEmpty()) {
+ // Email address is empty
+ throw new IllegalArgumentException("emailAddress.emaiLAddress is empty."); //NOI18N
+ } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
+ // User does not exist
+ throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
+ } else if (!this.isEmailAddressEnqueued(emailAddress.getEmailAddress())) {
+ // Email address is not enqueued
+ throw new EJBException(MessageFormat.format("Email address {0} is not enqueued.", emailAddress.getEmailAddress())); //NOI18N
+ }
+
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ /**
+ * Generates a secure, unique hash for given email address change. This
+ * requires to check if the hash is really not there.
+ * <p>
+ * @param emailAddress Email address change
+ */
+ private void generateSecureHash (final ChangeableEmailAddress emailAddress) {
+ // Email address change should be valid
+ if (null == emailAddress) {
+ // Abort here
+ throw new NullPointerException("emailAddress is null"); //NOI18N
+ } else if (emailAddress.getEmailAddress().trim().isEmpty()) {
+ // Email address is empty
+ throw new IllegalArgumentException("emailAddress.emaiLAddress is empty."); //NOI18N
+ }
+
+ // Initialize loop with null
+ String hash = null;
+
+ // Default is not used
+ boolean isUsed = true;
+
+ // Search for free hash
+ while (isUsed) {
+ // Generate hash, there is already in UserUtils a nice method that can be used for this purpose.
+ hash = UserUtils.encryptPassword(String.format("%s:%s", emailAddress.getEmailAddress(), emailAddress.toString())); //NOI18N
+
+ // The hash *may* be unique, better test it
+ Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByHash", EmailAddressChange.class); //NOI18N
+
+ // Set hash as parameter
+ query.setParameter("hash", hash); //NOI18N
+
+ // Try to get single result
+ try {
+ // Get single result
+ ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult();
+ } catch (final NoResultException ex) {
+ // Not found
+ isUsed = false;
+ }
+ }
+
+ // hash should not be null and set
+ assert (hash != null) : "hash is null"; //NOI18N
+ assert (!hash.isEmpty()) : "hash is empty"; //NOI18N
+
+ // Set it in email change
+ emailAddress.setEmailChangeHash(hash);
+ }
+
+}
--- /dev/null
+/*
+ * 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.jusercore.model.user.register;
+
+import java.text.MessageFormat;
+import java.util.Objects;
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jcontacts.contact.Contact;
+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.AdminUserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.LoginUser;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.UserUtils;
+
+/**
+ * A session-scoped bean for user registration
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "register", description = "A bean handling the user registration")
+public class AddressbookUserRegistrationSessionBean extends BaseAddressbookDatabaseBean implements UserRegistrationSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 12_348_958_986_818_627L;
+
+ /**
+ * Administrative user bean
+ */
+ @EJB
+ private AdminUserSessionBeanRemote adminUserBean;
+
+ /**
+ * Regular user EJB
+ */
+ @EJB
+ private UserSessionBeanRemote userBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookUserRegistrationSessionBean () {
+ // Call super constructor
+ super();
+ }
+
+ @Override
+ public String generateConfirmationKey (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
+
+ // user should not be null
+ if (null == user) {
+ // Abort here
+ throw new NullPointerException("user is null"); //NOI18N
+ }
+
+ // Create named instance
+ Query query = this.getEntityManager().createNamedQuery("SearchUserByConfirmKey", LoginUser.class); //NOI18N
+
+ // Init confirmation key
+ String confirmationKey = null;
+
+ // Find a free one
+ while (confirmationKey == null) {
+ // Create new one
+ String key = UserUtils.generatedConfirmationKey(user);
+
+ // Set key as parameter
+ query.setParameter("confirmKey", key); //NOI18N
+
+ // Try it
+ try {
+ // Get contact instance
+ Contact contact = (Contact) query.getSingleResult();
+
+ // Warning message
+ this.getLoggerBeanLocal().logWarning(MessageFormat.format("{0}.generateConfirmationKey: key {1} already found: contact.contactId={2}", this.getClass().getSimpleName(), key, contact.getContactId())); //NOI18N
+ } catch (final NoResultException ex) {
+ // Not found, normal case
+ confirmationKey = key;
+ break;
+ }
+ }
+
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: confirmationKey={1} - EXIT!", this.getClass().getSimpleName(), confirmationKey)); //NOI18N
+
+ // Return it
+ return confirmationKey;
+ }
+
+ @Override
+ public boolean isEmailAddressRegistered (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
+
+ // Check bean
+ assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
+
+ // user should not be null
+ if (null == user) {
+ // Abort here
+ throw new NullPointerException("user is null"); //NOI18N
+ }
+
+ // Call other bean
+ return this.userBean.isEmailAddressRegistered(user);
+ }
+
+ @Override
+ public boolean isUserNameRegistered (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
+
+ // Check bean
+ assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
+
+ // user should not be null
+ if (null == user) {
+ // Abort here
+ throw new NullPointerException("user is null"); //NOI18N
+ }
+
+ // Call other bean
+ return this.userBean.isUserNameRegistered(user);
+ }
+
+ @Override
+ public User registerUser (final User user, final String baseUrl, final String randomPassword) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: user={1},baseUrl={2},randomPassword[]={3} - CALLED!", this.getClass().getSimpleName(), user, baseUrl, Objects.toString(randomPassword))); //NOI18N
+
+ // user should not be null
+ if (null == user) {
+ // Abort here
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userContact is null"); //NOI18N
+ } else if (user.getUserContact().getContactEmailAddress() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userContact.contactEmailAddress is null"); //NOI18N
+ } else if (user.getUserContact().getContactEmailAddress().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("user.userContact.contactEmailAddress is empty"); //NOI18N
+ }
+
+ // Check if user is registered
+ if (this.isUserNameRegistered(user)) {
+ // Abort here
+ throw new UserNameAlreadyRegisteredException(user);
+ } else if (this.isEmailAddressRegistered(user)) {
+ // Abort here
+ throw new EmailAddressAlreadyRegisteredException(user);
+ }
+
+ // Call other EJB
+ User addedUser = this.adminUserBean.addUser(user);
+
+ // Init variable
+ Address emailAddress;
+
+ try {
+ // Create email address and set
+ emailAddress = new InternetAddress(addedUser.getUserContact().getContactEmailAddress());
+ } catch (final AddressException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+
+ // Default template is with no random password
+ String templateName = "user_registration"; //NOI18N
+
+ // Is password set?
+ if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
+ // Switch to other template
+ templateName = "user_registration_random"; //NOI18N
+ }
+
+ // Send email
+ // @TODO: Internationlize the subject line somehow
+ this.sendEmail("Registration", templateName, emailAddress, addedUser, baseUrl, randomPassword); //NOI18N
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: addedUser={1},addedUser.userId={2} - EXIT!", this.getClass().getSimpleName(), addedUser, addedUser.getUserId())); //NOI18N
+
+ // Return it
+ return addedUser;
+ }
+
+}
--- /dev/null
+/*
+ * 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.jusercore.model.user.resendlink;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
+import org.mxchange.jusercore.exceptions.UserStatusLockedException;
+import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.resendlink.ResendLinkSessionBeanRemote;
+import org.mxchange.jusercore.model.user.LoginUser;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+
+/**
+ * A session-based EJB for resending confirmation links
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "resendLink", description = "A bean resending confirmation links")
+public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBean implements ResendLinkSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 71_546_726_857_195_360L;
+
+ /**
+ * Registration bean
+ */
+ @EJB
+ private UserRegistrationSessionBeanRemote registerBean;
+
+ /**
+ * Regular user bean
+ */
+ @EJB
+ private UserSessionBeanRemote userBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookResendLinkSessionBean () {
+ // Call super constructor
+ super();
+ }
+
+ @Override
+ public void resendConfirmationLink (final User user, final Locale locale, final String baseUrl) throws UserNotFoundException, UserStatusConfirmedException, UserStatusLockedException {
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: user={1},locale={2},baseUrl={3} - CALLED!", this.getClass().getSimpleName(), user, locale, baseUrl)); //NOI18N
+
+ // The user instance should be valid
+ if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+ } else if (!this.userBean.ifUserExists(user)) {
+ // User not found
+ throw new UserNotFoundException(user);
+ } else if (user.getUserConfirmKey() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
+ } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
+ // User account status is not UNCONFIRMED
+ throw new UserStatusConfirmedException(user);
+ } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
+ // User account status is not UNCONFIRMED
+ throw new UserStatusLockedException(user);
+ } else if (null == locale) {
+ // Locale should be set
+ throw new NullPointerException("locale is null"); //NOI18N
+ }
+
+ // Get new registration key
+ String confirmationKey = this.registerBean.generateConfirmationKey(user);
+
+ // Get managed instance
+ User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
+
+ // Set it in user
+ managedUser.setUserConfirmKey(confirmationKey);
+
+ // Init variable
+ Address emailAddress;
+
+ try {
+ // Create email address and set
+ emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress());
+ } catch (final AddressException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+
+ // Send email
+ // @TODO: Internationlize the subject line somehow
+ this.sendEmail("Resend user confirmation link", "user_resend_confirmation_link", emailAddress, user, baseUrl, null); //NOI18N
+
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: EXIT!", this.getClass().getSimpleName())); //NOI18N
+ }
+
+}