From: Roland Häder Date: Fri, 13 May 2016 14:16:28 +0000 (+0200) Subject: Continued with resending confirmation links: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=11b1ad1f133c2eb9275ca77f2daf1037aff609ca;p=jfinancials-war.git Continued with resending confirmation links: - added form for resending confirmation link, surely the user only knows the registered email address - added controller (object and interface) for it - added missing i18n strings Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkWebSessionBean.java new file mode 100644 index 00000000..665dd59b --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkWebSessionBean.java @@ -0,0 +1,91 @@ +/* + * 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 . + */ +package org.mxchange.addressbook.beans.resendlink; + +import javax.enterprise.context.SessionScoped; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.addressbook.beans.BaseAddressbookController; + +/** + * A web session bean for resending confirmation link + *

+ * @author Roland Haeder + */ +@Named ("resendController") +@SessionScoped +public class AddressbookResendLinkWebSessionBean extends BaseAddressbookController implements AddressbookResendLinkWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 186_078_724_659_153L; + + /** + * Email address 1 (changing) + */ + private String emailAddress; + + /** + * EJB for resending confirmation link + */ + private ResendLinkSessionBeanRemote emailBean; + + /** + * Default constructor + */ + public AddressbookResendLinkWebSessionBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.emailBean = (ResendLinkSessionBeanRemote) context.lookup(""); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public String doResendLink () { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getEmailAddress () { + return this.emailAddress; + } + + @Override + public void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + /** + * Clears email address fields so the user has to re-enter them + */ + private void clear () { + // Clear fields + this.setEmailAddress(null); + } + +} diff --git a/src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkWebSessionController.java b/src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkWebSessionController.java new file mode 100644 index 00000000..15d17dfd --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkWebSessionController.java @@ -0,0 +1,50 @@ +/* + * 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 . + */ +package org.mxchange.addressbook.beans.resendlink; + +import java.io.Serializable; + +/** + * An interface for an email change controller + *

+ * @author Roland Haeder + */ +public interface AddressbookResendLinkWebSessionController extends Serializable { + + /** + * Getter for email address 1 (changing) + *

+ * @return Email address + */ + String getEmailAddress (); + + /** + * Setter for email address 1 (changing) + *

+ * @param emailAddress Email address 1 + */ + void setEmailAddress (final String emailAddress); + + /** + * Resends (new) confirmation link to given email address, if found. + * Otherwise an exception is thrown. On success a redirect takes place. + *

+ * @return Redirection target + */ + String doResendLink (); + +} diff --git a/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java new file mode 100644 index 00000000..bc5574dd --- /dev/null +++ b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java @@ -0,0 +1,108 @@ +/* + * 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 . + */ +package org.mxchange.addressbook.validator.emailaddress; + +import java.text.MessageFormat; +import java.util.regex.Pattern; +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.faces.view.facelets.FaceletException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jcoreee.validator.string.BaseStringValidator; + +/** + * A validator for email address validation + *

+ * @author Roland Haeder + */ +@FacesValidator ("EmailAddressValidator") +public class AddressbookEmailAddressValidator extends BaseStringValidator implements Validator { + + /** + * Serial number + */ + private static final long serialVersionUID = 187_536_745_607_192L; + + /** + * Contact session bean + */ + private final ContactSessionBeanRemote contactBean; + + /** + * Default constructor + */ + public AddressbookEmailAddressValidator () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // Trace message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N + + // The required field + String[] requiredFields = {"emailAddress", "emailAddressRepeat"}; //NOI18N + + // Pre-validation (example: not null, not a string, empty string ...) + super.preValidate(context, component, value, requiredFields, false); + + // Get string from object ... ;-) + String emailAddress = String.valueOf(value); + + // Checks if the email address matches a regex ("low-level" check, should also be done by ) + boolean matches = Pattern.matches("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$", emailAddress); //NOI18N + + // Is the email address valid? + if (!matches) { + // Generate message + String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N + + // Not matching + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message)); + } + + // Is the email address already registered? + if (this.contactBean.isEmailAddressRegistered(emailAddress)) { + // Generate message + String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N + + // No, then abort here + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); + } + + // Trace message + //* NOISY-DEBUG: */ System.out.println("validate: EXIT!"); //NOI18N + } + +} diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index 12b2f50e..598a36b4 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -539,3 +539,9 @@ ERROR_GUEST_USER_RESEND_CONFIRMATION_DEACTIVATED=Fehler: Erneutes Aussenden des ERROR_GUEST_USER_PROFILE_DEACTIVATED=Fehler: \u00d6ffentliche Benutzerprofile sind administrativ deaktiviert. EMAIL_ADDRESS_NOT_ENTERED=Bitte geben Sie Ihre Email-Adresse ein. EMAIL_ADDRESS_REPEAT_NOT_ENTERED=Bitte wiederholen Sie Ihre Email-Adresse. +BUTTON_RESEND_CONFIRMATION_LINK=Best\u00e4tigungslink erneut aussenden +GUEST_RESEND_LINK_TITLE=Best\u00e4tigungslink erneut aussenden +GUEST_RESEND_LINK_ENTER_EMAIL_ADDRESS=Bitte bei der Anmeldung verwendete Email-Adresse eingeben: +GUEST_RESEND_CONFIRMATION_LINK_NOTICE=Der alte Best\u00e4tigungslink wird hiernach verfallen, bitte dann den aus der neueren Mail verwenden. +RESEND_CONFIRMATION_LINK_LEGEND=Email-Adresse eingeben: +RESEND_CONFIRMATION_LINK_LEGEND_TITLE=Bitte geben Sie Ihre Email-Adresse ein, die Sie bei der Anmeldung verwendet haben. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 4fa312b6..903c6ba2 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -503,3 +503,9 @@ ERROR_GUEST_USER_RESEND_CONFIRMATION_DEACTIVATED=Error: Resending confirmation l ERROR_GUEST_USER_PROFILE_DEACTIVATED=Error: Public user profiles are deactivated by administrators. EMAIL_ADDRESS_NOT_ENTERED=Please enter your email address. EMAIL_ADDRESS_REPEAT_NOT_ENTERED=Please repeat your email address. +BUTTON_RESEND_CONFIRMATION_LINK=Resend confirmation link +GUEST_RESEND_LINK_TITLE=Resend confirmation link +GUEST_RESEND_LINK_ENTER_EMAIL_ADDRESS=Please enter email address you have used on registration: +GUEST_RESEND_CONFIRMATION_LINK_NOTICE=The old confirmation link won't work after this. Please always use the one from newer email. +RESEND_CONFIRMATION_LINK_LEGEND=Enter email address: +RESEND_CONFIRMATION_LINK_LEGEND_TITLE=Please enter your email address you have used on registration. diff --git a/src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java b/src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java deleted file mode 100644 index 3d0c9c34..00000000 --- a/src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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 . - */ -package org.mxchange.pizzaapplication.validator.emailaddress; - -import java.text.MessageFormat; -import java.util.regex.Pattern; -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.faces.view.facelets.FaceletException; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; -import org.mxchange.jcoreee.validator.string.BaseStringValidator; - -/** - * A validator for email address validation - *

- * @author Roland Haeder - */ -@FacesValidator ("EmailAddressValidator") -public class PizzaEmailAddressValidator extends BaseStringValidator implements Validator { - - /** - * Serial number - */ - private static final long serialVersionUID = 187_536_745_607_192L; - - /** - * Contact session bean - */ - private final ContactSessionBeanRemote contactBean; - - /** - * Default constructor - */ - public PizzaEmailAddressValidator () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - } - - @Override - public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N - - // The required field - String[] requiredFields = {"emailAddress", "emailAddressRepeat"}; //NOI18N - - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, false); - - // Get string from object ... ;-) - String emailAddress = String.valueOf(value); - - // Checks if the email address matches a regex ("low-level" check, should also be done by ) - boolean matches = Pattern.matches("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$", emailAddress); //NOI18N - - // Is the email address valid? - if (!matches) { - // Generate message - String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N - - // Not matching - throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message)); - } - - // Is the email address already registered? - if (this.contactBean.isEmailAddressRegistered(emailAddress)) { - // Generate message - String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N - - // No, then abort here - throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); - } - - // Trace message - //* NOISY-DEBUG: */ System.out.println("validate: EXIT!"); //NOI18N - } - -} diff --git a/web/guest/user/resend_link.xhtml b/web/guest/user/resend_link.xhtml index 4c619697..3b872258 100644 --- a/web/guest/user/resend_link.xhtml +++ b/web/guest/user/resend_link.xhtml @@ -17,7 +17,38 @@ - Here goes your content. + +

+
+ +
+ +
+ #{msg.RESEND_CONFIRMATION_LINK_LEGEND} + +
+
+ +
+ +
+ + + +
+
+ +
+ +
+
+ + +
+