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 javax.enterprise.context.SessionScoped;
20 import javax.faces.view.facelets.FaceletException;
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.naming.Context;
24 import javax.naming.InitialContext;
25 import javax.naming.NamingException;
26 import org.mxchange.jcoreee.utils.FacesUtils;
27 import org.mxchange.jjobs.beans.BaseJobsController;
28 import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
29 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
30 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
31 import org.mxchange.jusercore.model.user.User;
32 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
35 * A web session bean for resending confirmation link
37 * @author Roland Haeder<roland@mxchange.org>
39 @Named ("resendController")
41 public class JobsResendLinkWebSessionBean extends BaseJobsController implements JobsResendLinkWebSessionController {
46 private static final long serialVersionUID = 186_078_724_659_153L;
51 private String emailAddress;
54 * EJB for resending confirmation link
56 private ResendLinkSessionBeanRemote emailBean;
59 * Localization controller
62 private JobsLocalizationSessionController localizationController;
65 * Regular user controller
68 private JobsUserWebSessionController userController;
73 public JobsResendLinkWebSessionBean () {
76 // Get initial context
77 Context context = new InitialContext();
80 this.emailBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/jjobs-ejb/resendLink!org.mxchange.jjobs.beans.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
81 } catch (final NamingException e) {
83 throw new FaceletException(e);
88 public String doResendLink () {
89 // The email address should not be empty as the JSF validates this
90 if (this.getEmailAddress() == null) {
92 throw new NullPointerException("this.emailAddress is null"); //NOI18N
99 // Is the email address really not used?
100 user = this.userController.lookupUserByEmailAddress(this.getEmailAddress());
101 } catch (final UserEmailAddressNotFoundException ex) {
105 // Not found, should not happen as the registered validator should find it
106 this.showFacesMessage("form_resend_link:", "ERROR_USER_EMAIL_ADDRESS_NOT_FOUND"); //NOI18N
110 // Is the user account already confirmed?
111 if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
116 this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED"); //NOI18N
118 } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
122 // User account is locked
123 this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED"); //NOI18N
125 } else if (user.getUserConfirmKey() == null) {
126 // Status is UNCONFIRMED but confirmation key is NULL
127 throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
131 String baseUrl = FacesUtils.generateBaseUrl();
133 // Call EJB and return redirect target
134 this.emailBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
139 // Return redirect target
140 return "resend_done"; //NOI18N
144 public String getEmailAddress () {
145 return this.emailAddress;
149 public void setEmailAddress (final String emailAddress) {
150 this.emailAddress = emailAddress;
154 * Clears email address fields so the user has to re-enter them
156 private void clear () {
158 this.setEmailAddress(null);