2 * Copyright (C) 2016 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.beans.resendlink;
19 import java.text.MessageFormat;
20 import javax.annotation.PostConstruct;
21 import javax.enterprise.context.SessionScoped;
22 import javax.faces.view.facelets.FaceletException;
23 import javax.inject.Inject;
24 import javax.inject.Named;
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28 import org.mxchange.addressbook.beans.BaseAddressbookController;
29 import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
30 import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
31 import org.mxchange.jcoreee.utils.FacesUtils;
32 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
33 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
34 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
35 import org.mxchange.jusercore.model.user.User;
36 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
39 * A web session bean for resending confirmation link
41 * @author Roland Häder<roland@mxchange.org>
43 @Named ("resendController")
45 public class AddressbookResendLinkWebSessionBean extends BaseAddressbookController implements AddressbookResendLinkWebSessionController {
50 private static final long serialVersionUID = 186_078_724_659_153L;
55 private String emailAddress;
58 * EJB for resending confirmation link
60 private ResendLinkSessionBeanRemote resendLinkBean;
63 * Localization controller
66 private AddressbookLocalizationSessionController localizationController;
69 * Regular user controller
72 private AddressbookUserWebSessionController userController;
77 public AddressbookResendLinkWebSessionBean () {
81 public String doResendLink () {
82 // The email address should not be empty as the JSF validates this
83 if (this.getEmailAddress() == null) {
85 throw new NullPointerException("this.emailAddress is null"); //NOI18N
92 // Is the email address really not used?
93 user = this.userController.lookupUserByEmailAddress(this.getEmailAddress());
94 } catch (final UserEmailAddressNotFoundException ex) {
98 // Not found, should not happen as the registered validator should find it
99 throw new FaceletException(MessageFormat.format("this.emailAddress={0} should be resolveable into User instance.", this.getEmailAddress()), ex); //NOI18N
102 // Is the user account already confirmed?
103 if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
108 this.showFacesMessage("form_resend_link:resendEmailAddress", new UserStatusConfirmedException(user)); //NOI18N
110 } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
114 // User account is locked
115 this.showFacesMessage("form_resend_link:resendEmailAddress", new UserStatusLockedException(user)); //NOI18N
117 } else if (user.getUserConfirmKey() == null) {
118 // Status is UNCONFIRMED but confirmation key is NULL
119 throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
123 String baseUrl = FacesUtils.generateBaseUrl();
125 // Call EJB and return redirect target
126 this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
131 // Return redirect target
132 return "resend_done"; //NOI18N
136 public String getEmailAddress () {
137 return this.emailAddress;
141 public void setEmailAddress (final String emailAddress) {
142 this.emailAddress = emailAddress;
146 * Post-construction method
149 public void init () {
152 // Get initial context
153 Context context = new InitialContext();
156 this.resendLinkBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/addressbook-ejb/resendLink!org.mxchange.addressbook.beans.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
157 } catch (final NamingException e) {
159 throw new FaceletException(e);
164 * Clears email address fields so the user has to re-enter them
166 private void clear () {
168 this.setEmailAddress(null);