2 * Copyright (C) 2016 - 2020 Free Software Foundation
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.user.resendlink;
20 import javax.enterprise.context.RequestScoped;
21 import javax.enterprise.event.Event;
22 import javax.enterprise.inject.Any;
23 import javax.faces.application.FacesMessage;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import org.mxchange.jcoreee.utils.FacesUtils;
27 import org.mxchange.jjobs.beans.BaseJobsBean;
28 import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
29 import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController;
30 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
31 import org.mxchange.jusercore.exceptions.UserNotFoundException;
32 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
33 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
34 import org.mxchange.jusercore.model.user.User;
35 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
36 import org.mxchange.juserlogincore.events.resendlink.ObservableUserResendLinkAccountEvent;
37 import org.mxchange.juserlogincore.events.resendlink.UserResendLinkAccountEvent;
38 import org.mxchange.juserlogincore.model.user.resendlink.ResendLinkSessionBeanRemote;
41 * A web session-scoped bean for resending confirmation link
43 * @author Roland Häder<roland@mxchange.org>
45 @Named ("userResendConfirmationController")
47 public class JobsResendLinkWebRequestBean extends BaseJobsBean implements JobsResendLinkWebRequestController {
52 private static final long serialVersionUID = 186_078_724_659_153L;
57 private String emailAddress;
60 * Localization controller
63 private JobsLocalizationSessionController localizationController;
66 * EJB for resending confirmation link
68 @EJB (lookup = "java:global/jjobs-ejb/userResendConfirmationLink!org.mxchange.juserlogincore.model.user.resendlink.ResendLinkSessionBeanRemote")
69 private ResendLinkSessionBeanRemote resendLinkBean;
72 * Regular user controller
75 private JobsUserListWebViewController userListController;
78 * Event being fired after confirmation link is being sent
82 private Event<ObservableUserResendLinkAccountEvent> userResendLinkEvent;
87 public JobsResendLinkWebRequestBean () {
88 // Call super constructor
93 * Resends (new) confirmation link to given email address, if found.
94 * Otherwise an exception is thrown. On success a redirect takes place.
96 * @return Redirect outcome
98 public String doResendLink () {
99 // The email address should not be empty as the JSF validates this
100 if (this.getEmailAddress() == null) {
102 throw new NullPointerException("this.emailAddress is null"); //NOI18N
105 // Init user instance
109 // Is the email address really not used?
110 user = this.userListController.lookupUserByEmailAddress(this.getEmailAddress());
111 } catch (final UserEmailAddressNotFoundException ex) {
115 // Not found, should not happen as the registered validator should find it
116 this.showFacesMessage("form_resend_link:", "ERROR_USER_EMAIL_ADDRESS_NOT_FOUND", FacesMessage.SEVERITY_ERROR); //NOI18N
120 // Is the user account already confirmed?
121 if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
126 this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED", FacesMessage.SEVERITY_WARN); //NOI18N
128 } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
132 // User account is locked
133 this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED", FacesMessage.SEVERITY_WARN); //NOI18N
135 } else if (user.getUserConfirmKey() == null) {
136 // Status is UNCONFIRMED but confirmation key is NULL
137 throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
140 // Init managed user instance
141 final User managedUser;
145 final String baseUrl = FacesUtils.generateBaseUrl();
147 // Call EJB and return redirect target
148 managedUser = this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
149 } catch (final UserNotFoundException ex) {
151 this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND", FacesMessage.SEVERITY_ERROR); //NOI18N
153 } catch (final UserStatusLockedException | UserStatusConfirmedException ex) {
154 // Output message, this should not happen as the confirmation key is being removed
155 this.showFacesMessage("form_resend_link:resendEmailAddress", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
163 this.userResendLinkEvent.fire(new UserResendLinkAccountEvent(managedUser));
165 // Return redirect target
166 return "user_resend_done"; //NOI18N
170 * Getter for email address 1 (changing)
172 * @return Email address
174 public String getEmailAddress () {
175 return this.emailAddress;
179 * Setter for email address 1 (changing)
181 * @param emailAddress Email address 1
183 public void setEmailAddress (final String emailAddress) {
184 this.emailAddress = emailAddress;
188 * Clears email address fields so the user has to re-enter them
190 private void clear () {
192 this.setEmailAddress(null);