2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (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 General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.beans.login;
19 import java.util.Objects;
20 import javax.enterprise.context.SessionScoped;
21 import javax.faces.view.facelets.FaceletException;
22 import javax.inject.Inject;
23 import javax.inject.Named;
24 import javax.naming.Context;
25 import javax.naming.InitialContext;
26 import javax.naming.NamingException;
27 import org.mxchange.addressbook.beans.user.UserWebController;
28 import org.mxchange.jusercore.container.login.LoginContainer;
29 import org.mxchange.jusercore.container.login.UserLoginContainer;
30 import org.mxchange.jusercore.exceptions.UserNotFoundException;
31 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
32 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
33 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
34 import org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote;
35 import org.mxchange.jusercore.model.user.User;
36 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
39 * A web bean for user registration
41 * @author Roland Haeder
43 @Named ("loginController")
45 public class UserLoginWebBean implements UserLoginWebController {
50 private static final long serialVersionUID = 47_828_986_719_691_592L;
53 * Logged-in user instance
55 private User loggedInUser;
58 * Reemote register session bean
60 private UserLoginSessionBeanRemote loginBean;
66 private UserWebController userController;
71 public UserLoginWebBean () {
73 // Get initial context
74 Context context = new InitialContext();
77 this.loginBean = (UserLoginSessionBeanRemote) context.lookup("ejb/stateless-login"); //NOI18N
78 } catch (final NamingException ex) {
80 throw new FaceletException(ex);
85 public String doLogin () {
87 User user = this.userController.createUserInstance();
89 // Create login container
90 LoginContainer container = new UserLoginContainer(user, this.userController.getUserPassword());
94 User confirmedUser = this.loginBean.validateUserAccountStatus(container);
96 // All fine here so set it here
97 this.setLoggedInUser(confirmedUser);
100 return "login"; //NOI18N
101 } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException | UserPasswordMismatchException ex) {
103 throw new FaceletException(ex);
108 public User getLoggedInUser () {
109 return this.loggedInUser;
113 public void setLoggedInUser (final User loggedInUser) {
114 this.loggedInUser = loggedInUser;
118 public boolean isUserLoggedIn () {
120 return ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));