import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
// As the form cannot validate the data (required="true"), check it here
if (this.getUserName() == null) {
// Throw NPE
// As the form cannot validate the data (required="true"), check it here
if (this.getUserName() == null) {
// Throw NPE
// Set user name, CONFIRMED and INVISIBLE
newUser.setUserName(this.getUserName());
// Set user name, CONFIRMED and INVISIBLE
newUser.setUserName(this.getUserName());
return ""; //NOI18N
} else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
// Empty password entered, then generate one
return ""; //NOI18N
} else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
// Empty password entered, then generate one
} else if (!this.isSamePasswordEntered()) {
// Both passwords don't match
throw new FaceletException(new UserPasswordRepeatMismatchException(newUser));
} else if (!this.isSamePasswordEntered()) {
// Both passwords don't match
throw new FaceletException(new UserPasswordRepeatMismatchException(newUser));
// The password should not be null and at least 5 characters long
assert (password != null) : "password is null"; //NOI18N
// The password should not be null and at least 5 characters long
assert (password != null) : "password is null"; //NOI18N
// Encrypt password and set it
newUser.setUserEncryptedPassword(UserLoginUtils.encryptPassword(password));
// Encrypt password and set it
newUser.setUserEncryptedPassword(UserLoginUtils.encryptPassword(password));
// Now, that all is set, call EJB
if (this.getContact() instanceof Contact) {
// Link contact with this user
// Now, that all is set, call EJB
if (this.getContact() instanceof Contact) {
// Link contact with this user
// Call EJB to lock account
updatedUser = this.adminUserBean.lockUserAccount(this.getUser(), this.getUserLockReason(), baseUrl);
// Call EJB to lock account
updatedUser = this.adminUserBean.lockUserAccount(this.getUser(), this.getUserLockReason(), baseUrl);
// Call EJB to unlock account
updatedUser = this.adminUserBean.unlockUserAccount(this.getUser(), baseUrl);
// Call EJB to unlock account
updatedUser = this.adminUserBean.unlockUserAccount(this.getUser(), baseUrl);