/*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016 Roland Häder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
*/
package org.mxchange.jjobs.beans.resendlink;
-import java.text.MessageFormat;
import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jjobs.beans.BaseJobsController;
import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
+import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent;
import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.jusercore.events.resendlink.ObservableUserResendLinkAccountEvent;
/**
* A web session bean for resending confirmation link
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
*/
@Named ("resendController")
@SessionScoped
@Inject
private JobsUserWebSessionController userController;
+ /**
+ * Event being fired after confirmation link is being sent
+ */
+ @Inject
+ @Any
+ private Event<ObservableUserResendLinkAccountEvent> userResendLinkEvent;
+
/**
* Default constructor
*/
this.clear();
// Not found, should not happen as the registered validator should find it
- throw new FaceletException(MessageFormat.format("this.emailAddress={0} should be resolveable into User instance.", this.getEmailAddress()), ex); //NOI18N
+ this.showFacesMessage("form_resend_link:", "ERROR_USER_EMAIL_ADDRESS_NOT_FOUND"); //NOI18N
+ return ""; //NOI18N
}
// Is the user account already confirmed?
this.clear();
// Then abort here
- this.showFacesMessage("form_resend_link:resendEmailAddress", new UserStatusConfirmedException(user)); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED"); //NOI18N
return ""; //NOI18N
} else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
// Always clear bean
this.clear();
// User account is locked
- this.showFacesMessage("form_resend_link:resendEmailAddress", new UserStatusLockedException(user)); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED"); //NOI18N
return ""; //NOI18N
} else if (user.getUserConfirmKey() == null) {
// Status is UNCONFIRMED but confirmation key is NULL
throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
}
- // Get base URL
- String baseUrl = FacesUtils.generateBaseUrl();
+ try {
+ // Get base URL
+ String baseUrl = FacesUtils.generateBaseUrl();
+
+ // Call EJB and return redirect target
+ this.emailBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
+ } catch (final UserNotFoundException ex) {
+ // User not found
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND"); //NOI18N
+ return ""; //NOI18N
+ } catch (final UserStatusLockedException | UserStatusConfirmedException ex) {
+ // Output message, this should not happen as the confirmation key is being removed
+ this.showFacesMessage("form_resend_link:resendEmailAddress", ex); //NOI18N
+ return ""; //NOI18N
+ }
- // Call EJB and return redirect target
- this.emailBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
+ // Fire event
+ this.userResendLinkEvent.fire(new UserResendLinkAccountEvent(user));
// Clear this bean
this.clear();
// Return redirect target
- return "resend_done"; //NOI18N
+ return "user_resend_done"; //NOI18N
}
@Override