@SessionScoped
public class UserLoginWebBean implements UserLoginWebController {
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 47_828_986_719_691_592L;
+
/**
* Reemote register session bean
*/
private UserWebController userController;
/**
- * Serial number
+ * Logged-in user instance
*/
- private static final long serialVersionUID = 47_828_986_719_691_592L;
+ private User loggedInUser;
/**
* Default constructor
try {
// Call bean
- this.loginBean.loginUser(user);
+ User confirmedUser = this.loginBean.validateUserAccountStatus(user);
+
+ // All fine here so set it here
+ this.setLoggedInUser(confirmedUser);
} catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) {
// Throw again
throw new FaceletException(ex);
}
}
+
+ @Override
+ public User getLoggedInUser () {
+ return this.loggedInUser;
+ }
+
+ @Override
+ public void setLoggedInUser (final User loggedInUser) {
+ this.loggedInUser = loggedInUser;
+ }
}
package org.mxchange.addressbook.beans.login;
import java.io.Serializable;
+import org.mxchange.jusercore.model.user.User;
/**
* An interface for registration web controllers
* Logins the user, if the account is found, confirmed and unlocked.
*/
public void doLogin ();
+
+ /**
+ * Getter for logged-in user instance
+ * <p>
+ * @return Logged-in user instance
+ */
+ public User getLoggedInUser ();
+
+ /**
+ * Setter for logged-in user instance
+ * <p>
+ * @param loggedInUser Logged-in user instance
+ */
+ public void setLoggedInUser (final User loggedInUser);
}
*/
package org.mxchange.addressbook.beans.register;
+import java.text.MessageFormat;
import javax.enterprise.context.SessionScoped;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.addressbook.beans.user.UserWebController;
+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;
/**
User user = this.userController.createUserInstance();
// Is the user already used?
- if (this.userController.isUserNameRegistered(user.getUserName())) {
+ if (!this.userController.isRequiredPersonalDataSet()) {
+ // Not all required fields are set
+ throw new FaceletException("Not all required fields are set.");
+ } else if (this.userController.isUserNameRegistered(user.getUserName())) {
// User name is already used
throw new FaceletException(new UserNameAlreadyRegisteredException(user));
} else if (this.userController.isEmailAddressRegistered(user.getUserContact().getEmailAddress())) {
// Email address has already been taken
throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+ } else if (!this.userController.isSameEmailAddressEntered()) {
+ // Not same email address entered
+ throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.userController.getEmailAddress(), this.userController.getEmailAddressRepeat())));
+ } else if (!this.userController.isSamePasswordEntered()) {
+ // Not same password entered
+ throw new FaceletException(new DataRepeatMismatchException("Passwords not matching."));
}
+ // Encrypt password
+ String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword());
+
+ // Set it here
+ user.setUserEncryptedPassword(encryptedPassword);
+
// For debugging/programming only:
user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
// Copy all data from registered->user
this.userController.copyUser(registeredUser);
+ // Add user name and email address
+ this.userController.addUserNameEmailAddress(registeredUser);
+
+ // Clear all data
+ this.userController.clearData();
+
// All fine, redirect to proper page
return "register_done"; //NOI18N
} catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
*/
package org.mxchange.addressbook.beans.user;
+import java.text.MessageFormat;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.List;
+import java.util.Objects;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.view.facelets.FaceletException;
*/
private String emailAddress;
+ /**
+ * Email address list
+ */
+ private List<String> emailAddressList;
+
+ /**
+ * Email address repeated
+ */
+ private String emailAddressRepeat;
+
/**
* Family name
*/
*/
private Short houseNumber;
- /**
- * User id
- */
- private Long userId;
-
/**
* Phone number
*/
*/
private final UserSessionBeanRemote userBean;
+ /**
+ * User id
+ */
+ private Long userId;
+
/**
* User name
*/
private String userName;
/**
- * User password (unencrypted from web form)
+ * User name list
*/
- private String userPassword;
+ private List<String> userNameList;
/**
- * ZIP code
+ * User password (unencrypted from web form)
*/
- private Integer zipCode;
+ private String userPassword;
/**
- * Email address list
+ * User password repeated (unencrypted from web form)
*/
- private List<String> emailAddressList;
+ private String userPasswordRepeat;
/**
- * User name list
+ * ZIP code
*/
- private List<String> userNameList;
+ private Integer zipCode;
/**
* Default constructor
Context context = new InitialContext();
// Try to lookup
- this.userBean = (UserSessionBeanRemote) context.lookup("ejb/stateless-user");
+ this.userBean = (UserSessionBeanRemote) context.lookup("ejb/stateless-user"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
}
@Override
- public boolean isEmailAddressRegistered (String emailAddress) {
- return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(emailAddress)));
+ public void addUserNameEmailAddress (final User user) {
+ // Make sure the entry is not added yet
+ if (this.userNameList.contains(user.getUserName())) {
+ // Abort here
+ throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName()));
+ } else if (this.emailAddressList.contains(user.getUserContact().getEmailAddress())) {
+ // Already added
+ throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getEmailAddress()));
+ }
+
+ // Add user name
+ this.userNameList.add(user.getUserName());
+
+ // Add email addres
+ this.emailAddressList.add(user.getUserContact().getEmailAddress());
}
@Override
- public boolean isUserNameRegistered (final String userName) {
- return ((this.userNameList instanceof List) && (this.userNameList.contains(userName)));
- }
+ public void clearData () {
+ // Clear all data
+ // - personal data
+ this.setUserId(null);
+ this.setGender(Gender.UNKNOWN);
+ this.setFirstName(null);
+ this.setFamilyName(null);
+ this.setStreet(null);
+ this.setHouseNumber(null);
+ this.setZipCode(null);
+ this.setCity(null);
+ this.setCountryCode(null);
- @PostConstruct
- public void init () {
- // Get full user name list for reducing EJB calls
- this.userNameList = this.userBean.getUserNameList();
+ // - contact data
+ this.setEmailAddress(null);
+ this.setEmailAddressRepeat(null);
+ this.setPhoneNumber(null);
+ this.setCellphoneNumber(null);
+ this.setFaxNumber(null);
- // Get full email address list for reducing EJB calls
- this.emailAddressList = this.userBean.getEmailAddressList();
+ // - other data
+ this.setBirthday(null);
+ this.setComment(null);
+ this.setUserPassword(null);
+ this.setUserPasswordRepeat(null);
}
@Override
contact.setHouseNumber(this.getHouseNumber());
contact.setZipCode(this.getZipCode());
contact.setCity(this.getCity());
+ contact.setCountryCode(this.getCountryCode());
+ contact.setEmailAddress(this.getEmailAddress());
contact.setPhoneNumber(this.getPhoneNumber());
contact.setFaxNumber(this.getFaxNumber());
contact.setCellphoneNumber(this.getCellphoneNumber());
contact.setBirthday(this.getBirthday());
contact.setComment(this.getComment());
+ // Created timestamp and ownContact
+ contact.setCreated(new GregorianCalendar());
+ contact.setOwnContact(Boolean.TRUE);
+
// Set contact in user
user.setUserContact(contact);
+ user.setUserCreated(new GregorianCalendar());
// Trace message
//this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
this.emailAddress = emailAddress;
}
+ @Override
+ public String getEmailAddressRepeat () {
+ return this.emailAddressRepeat;
+ }
+
+ @Override
+ public void setEmailAddressRepeat (final String emailAddressRepeat) {
+ this.emailAddressRepeat = emailAddressRepeat;
+ }
+
@Override
public String getFamilyName () {
return this.familyName;
this.userPassword = userPassword;
}
+ @Override
+ public String getUserPasswordRepeat () {
+ return this.userPasswordRepeat;
+ }
+
+ @Override
+ public void setUserPasswordRepeat (final String userPasswordRepeat) {
+ this.userPasswordRepeat = userPasswordRepeat;
+ }
+
@Override
public Integer getZipCode () {
return this.zipCode;
this.zipCode = zipCode;
}
+ @PostConstruct
+ public void init () {
+ // Get full user name list for reducing EJB calls
+ this.userNameList = this.userBean.getUserNameList();
+
+ // Get full email address list for reducing EJB calls
+ this.emailAddressList = this.userBean.getEmailAddressList();
+ }
+
+ @Override
+ public boolean isEmailAddressRegistered (final String emailAddress) {
+ return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(emailAddress)));
+ }
+
@Override
public boolean isRequiredPersonalDataSet () {
- return ((this.getUserName() != null) && (this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));
+ return ((this.getUserName() != null)
+ && (this.getGender() != null)
+ && (this.getFirstName() != null)
+ && (this.getFamilyName() != null)
+ && (this.getStreet() != null)
+ && (this.getHouseNumber() != null)
+ && (this.getZipCode() != null)
+ && (this.getCity() != null)
+ && (this.getEmailAddress() != null)
+ && (this.getEmailAddressRepeat() != null)
+ && (this.getUserPassword() != null)
+ && (this.getUserPasswordRepeat() != null));
+ }
+
+ @Override
+ public boolean isSameEmailAddressEntered () {
+ return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
+ }
+
+ @Override
+ public boolean isSamePasswordEntered () {
+ return (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat()));
+ }
+
+ @Override
+ public boolean isUserNameRegistered (final String userName) {
+ return ((this.userNameList instanceof List) && (this.userNameList.contains(userName)));
}
}
public interface UserWebController extends Serializable {
/**
- * Copies given user into the controller
+ * Adds user's name and email address to bean's internal list
* <p>
* @param user User instance
*/
- public void copyUser (final User user);
+ public void addUserNameEmailAddress (final User user);
/**
- * Creates an instance from all properties
- * <p>
- * @return A user instance
+ * Clears all data in this bean
*/
- public User createUserInstance ();
+ public void clearData ();
/**
- * Checks whether given user name is used
+ * Copies given user into the controller
* <p>
- * @param userName User name to check
- * @return Whether it is already used
+ * @param user User instance
*/
- public boolean isUserNameRegistered (final String userName);
+ public void copyUser (final User user);
/**
- * Checks whether given email address is used
+ * Creates an instance from all properties
* <p>
- * @param emailAddress Email address to check
- * @return Whether it is already used
+ * @return A user instance
*/
- public boolean isEmailAddressRegistered (final String emailAddress);
+ public User createUserInstance ();
/**
* Getter for birth day
*/
public void setComment (final String comment);
- /**
- * Getter for user id
- * <p>
- * @return User id
- */
- public Long getUserId ();
-
- /**
- * Setter for user id
- * <p>
- * @param userId User id
- */
- public void setUserId (final Long userId);
-
- /**
- * Getter for user name
- * <p>
- * @return User name
- */
- public String getUserName ();
-
- /**
- * Setter for user name
- * <p>
- * @param userName User name
- */
- public void setUserName (final String userName);
-
- /**
- * Getter for unencrypted user password
- * <p>
- * @return Unencrypted user password
- */
- public String getUserPassword ();
-
- /**
- * Setter for unencrypted user password
- * <p>
- * @param userPassword Unencrypted user password
- */
- public void setUserPassword (final String userPassword);
-
/**
* Country code
* <p>
public void setCountryCode (final String countryCode);
/**
- * Email address
+ * Getter for email address
* <p>
- * @return the emailAddress
+ * @return Email address
*/
public String getEmailAddress ();
/**
- * Email address
+ * Setter for email address
* <p>
- * @param emailAddress the emailAddress to set
+ * @param emailAddress Email address
*/
public void setEmailAddress (final String emailAddress);
+ /**
+ * Getter for email address, repeated
+ * <p>
+ * @return the emailAddress, repeated
+ */
+ public String getEmailAddressRepeat ();
+
+ /**
+ * Setter for email address repeated
+ * <p>
+ * @param emailAddressRepeat the emailAddress to set
+ */
+ public void setEmailAddressRepeat (final String emailAddressRepeat);
+
/**
* Family name
* <p>
*/
public void setStreet (final String street);
+ /**
+ * Getter for user id
+ * <p>
+ * @return User id
+ */
+ public Long getUserId ();
+
+ /**
+ * Setter for user id
+ * <p>
+ * @param userId User id
+ */
+ public void setUserId (final Long userId);
+
+ /**
+ * Getter for user name
+ * <p>
+ * @return User name
+ */
+ public String getUserName ();
+
+ /**
+ * Setter for user name
+ * <p>
+ * @param userName User name
+ */
+ public void setUserName (final String userName);
+
+ /**
+ * Getter for unencrypted user password
+ * <p>
+ * @return Unencrypted user password
+ */
+ public String getUserPassword ();
+
+ /**
+ * Setter for unencrypted user password
+ * <p>
+ * @param userPassword Unencrypted user password
+ */
+ public void setUserPassword (final String userPassword);
+
+ /**
+ * Getter for unencrypted user password repeated
+ * <p>
+ * @return Unencrypted user password repeated
+ */
+ public String getUserPasswordRepeat ();
+
+ /**
+ * Setter for unencrypted user password repeated
+ * <p>
+ * @param userPasswordRepeat Unencrypted user password repeated
+ */
+ public void setUserPasswordRepeat (final String userPasswordRepeat);
+
/**
* ZIP code
* <p>
*/
public void setZipCode (final Integer zipCode);
+ /**
+ * Checks whether given email address is used
+ * <p>
+ * @param emailAddress Email address to check
+ * @return Whether it is already used
+ */
+ public boolean isEmailAddressRegistered (final String emailAddress);
+
/**
* Checks whether all required personal data is set
* <p>
* @return Whether the required personal data is set
*/
public boolean isRequiredPersonalDataSet ();
+
+ /**
+ * Checks whether same email addresses have been entered
+ * <p>
+ * @return Whether same email addresses have been entered
+ */
+ public boolean isSameEmailAddressEntered ();
+
+ /**
+ * Checks whether same passwords has been entered
+ * <p>
+ * @return Whether same passwords has been entered
+ */
+ public boolean isSamePasswordEntered ();
+
+ /**
+ * Checks whether given user name is used
+ * <p>
+ * @param userName User name to check
+ * @return Whether it is already used
+ */
+ public boolean isUserNameRegistered (final String userName);
}
GUEST_REGISTRATION_ENTER_USER_NAME=Benutzernamen eingeben:
GUEST_REGISTRATION_USER_NAME_NOTICE=Der Benutzername darf nur einmal vorkommen.
LINK_GUEST_RESENT_CONFIRMATION_LINK=Nochmals den Best\u00e4tigungslink aussenden?
-GUEST_REGISTRATION_COMPLETED=Die Anmeldung ist abgeschlossen und Ihr Account wartet auf Freischaltung. Es ist eine Email mit einem entsprechenden Best\u00e4tigungslink zu Ihnen unterwegs. Diesen m\u00fcssen Sie einmal anklicken oder in die Adresszeile des Browsers kopieren und dann aufrufen lassen. Danach ist Ihr Account freigegeben.
+GUEST_USER_REGISTRATION_COMPLETED=Die Anmeldung ist abgeschlossen und Ihr Account wartet auf Freischaltung. Es ist eine Email mit einem entsprechenden Best\u00e4tigungslink zu Ihnen unterwegs. Diesen m\u00fcssen Sie einmal anklicken oder in die Adresszeile des Browsers kopieren und dann aufrufen lassen. Danach ist Ihr Account freigegeben.
+PERSONAL_DATA_COUNTRY_CODE=L\u00e4ndercode:
+PAGE_TITLE_USER_REGISTER_DONE=Anmeldung abgeschlossen
+SUB_TITLE_USER_REGISTER_DONE=Die Anmeldung ist abgeschlossen:
GUEST_REGISTRATION_ENTER_USER_NAME=Enter user name:
GUEST_REGISTRATION_USER_NAME_NOTICE=The user name must only exist once.
LINK_GUEST_RESENT_CONFIRMATION_LINK=Resend again the confirmation link?
-GUEST_REGISTRATION_COMPLETED=The registration is completed and your account is pending confirmation. An email has been sent to you. There you will find a confirmation link which you have to click once or copy it into your browser's address bar and call it.
+GUEST_USER_REGISTRATION_COMPLETED=The registration is completed and your account is pending confirmation. An email has been sent to you. There you will find a confirmation link which you have to click once or copy it into your browser's address bar and call it.
+PERSONAL_DATA_COUNTRY_CODE=Country code:
+PAGE_TITLE_USER_REGISTER_DONE=Registration completed
+SUB_TITLE_USER_REGISTER_DONE=Registration is completed:
<div class="clear"></div>
</div>
+ <div class="table_row">
+ <div class="table_left">
+ <h:outputLabel for="countryCode" value="#{msg.PERSONAL_DATA_COUNTRY_CODE}" />
+ </div>
+
+ <div class="table_right">
+ <h:inputText class="input" id="countryCode" size="2" maxlength="2" value="#{userController.countryCode}" required="true" />
+ </div>
+
+ <div class="clear"></div>
+ </div>
+
<div class="table_row">
<div class="table_left">
<h:outputLabel for="phoneNumber" value="#{msg.PERSONAL_DATA_PHONE_NUMBER}" />
</div>
<div class="table_right">
- <h:inputText class="input" id="emailAddress2" size="20" maxlength="255" value="#{userController.emailAddress}" required="true" />
+ <h:inputText class="input" id="emailAddress2" size="20" maxlength="255" value="#{userController.emailAddressRepeat}" required="true" />
</div>
<div class="clear"></div>
</div>
<div class="table_right">
- <h:inputSecret class="input" id="password1" size="10" maxlength="255" required="true" />
+ <h:inputSecret class="input" id="password1" size="10" maxlength="255" value="#{userController.userPassword}" required="true" />
</div>
<div class="clear"></div>
</div>
<div class="table_right">
- <h:inputSecret class="input" id="password2" size="10" maxlength="255" required="true" />
+ <h:inputSecret class="input" id="password2" size="10" maxlength="255" value="#{userController.userPasswordRepeat}" required="true" />
</div>
<div class="clear"></div>