]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java
Continued:
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / login / UserLoginWebBean.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.beans.login;
18
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.addressbook.beans.user.UserWebController;
27 import org.mxchange.jusercore.exceptions.UserNotFoundException;
28 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
29 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
30 import org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote;
31 import org.mxchange.jusercore.model.user.User;
32
33 /**
34  * A web bean for user registration
35  * <p>
36  * @author Roland Haeder
37  */
38 @Named ("loginController")
39 @SessionScoped
40 public class UserLoginWebBean implements UserLoginWebController {
41
42         /**
43          * Reemote register session bean
44          */
45         private UserLoginSessionBeanRemote login;
46
47         /**
48          * User controller
49          */
50         @Inject
51         private UserWebController userController;
52
53         /**
54          * Serial number
55          */
56         private static final long serialVersionUID = 47_828_986_719_691_592L;
57
58         /**
59          * Default constructor
60          */
61         public UserLoginWebBean () {
62                 try {
63                         // Get initial context
64                         Context context = new InitialContext();
65
66                         // Try to lookup
67                         this.login = (UserLoginSessionBeanRemote) context.lookup("ejb/stateless-login"); //NOI18N
68                 } catch (final NamingException ex) {
69                         // Continue to throw
70                         throw new FaceletException(ex);
71                 }
72         }
73
74         @Override
75         public void doLogin () {
76                 // Get user instance
77                 User user = this.userController.createUserInstance();
78
79                 try {
80                         // Call bean
81                         this.login.loginUser(user);
82                 } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) {
83                         // Throw again
84                         throw new FaceletException(ex);
85                 }
86         }
87 }