2 * Copyright (C) 2016 Roland Haeder
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.jjobs.beans.resendlink;
19 import java.text.MessageFormat;
20 import java.util.Locale;
21 import javax.enterprise.context.SessionScoped;
22 import javax.faces.context.FacesContext;
23 import javax.faces.view.facelets.FaceletException;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.jcoreee.utils.FacesUtils;
30 import org.mxchange.jjobs.beans.BaseJobsController;
31 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
32 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
33 import org.mxchange.jusercore.model.user.User;
36 * A web session bean for resending confirmation link
38 * @author Roland Haeder<roland@mxchange.org>
40 @Named ("resendController")
42 public class JobsResendLinkWebSessionBean extends BaseJobsController implements JobsResendLinkWebSessionController {
47 private static final long serialVersionUID = 186_078_724_659_153L;
50 * Email address 1 (changing)
52 private String emailAddress;
55 * EJB for resending confirmation link
57 private ResendLinkSessionBeanRemote emailBean;
63 private JobsUserWebSessionController userController;
68 public JobsResendLinkWebSessionBean () {
71 // Get initial context
72 Context context = new InitialContext();
75 this.emailBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/jjobs-ejb/resendLink!org.mxchange.jjobs.beans.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
76 } catch (final NamingException e) {
78 throw new FaceletException(e);
83 public String doResendLink () {
84 // The email address should not be empty as the JSF validates this
85 if (this.getEmailAddress() == null) {
87 throw new NullPointerException("this.emailAddress is null"); //NOI18N
94 // Is the email address really not used?
95 user = this.userController.lookupUserByEmailAddress(this.getEmailAddress());
96 } catch (final UserEmailAddressNotFoundException ex) {
97 // Not found, should not happen as the registeredvalidator should find it
98 throw new FaceletException(MessageFormat.format("this.emailAddress={0} should be resolveable into User instance.", this.getEmailAddress()), ex); //NOI18N
101 // Get locale from faces context
102 Locale locale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
105 String baseUrl = FacesUtils.generateBaseUrl();
107 // Call EJB and return redirect target
108 String redirectTarget = this.emailBean.resendConfirmationLink(user, locale, baseUrl);
110 // Return redirect target
111 return redirectTarget;
115 public String getEmailAddress () {
116 return this.emailAddress;
120 public void setEmailAddress (final String emailAddress) {
121 this.emailAddress = emailAddress;
125 * Clears email address fields so the user has to re-enter them
127 private void clear () {
129 this.setEmailAddress(null);