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.exceptions.UserNotFoundException;
29 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
30 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
31 import org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote;
32 import org.mxchange.jusercore.model.user.User;
33 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
36 * A web bean for user registration
38 * @author Roland Haeder
40 @Named ("loginController")
42 public class UserLoginWebBean implements UserLoginWebController {
47 private static final long serialVersionUID = 47_828_986_719_691_592L;
50 * Logged-in user instance
52 private User loggedInUser;
55 * Reemote register session bean
57 private UserLoginSessionBeanRemote loginBean;
63 private UserWebController userController;
68 public UserLoginWebBean () {
70 // Get initial context
71 Context context = new InitialContext();
74 this.loginBean = (UserLoginSessionBeanRemote) context.lookup("ejb/stateless-login"); //NOI18N
75 } catch (final NamingException ex) {
77 throw new FaceletException(ex);
82 public String doLogin () {
84 User user = this.userController.createUserInstance();
88 User confirmedUser = this.loginBean.validateUserAccountStatus(user);
90 // All fine here so set it here
91 this.setLoggedInUser(confirmedUser);
92 } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) {
94 throw new FaceletException(ex);
98 return "login"; //NOI18N
102 public User getLoggedInUser () {
103 return this.loggedInUser;
107 public void setLoggedInUser (final User loggedInUser) {
108 this.loggedInUser = loggedInUser;
112 public boolean isUserLoggedIn () {
114 return ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));