1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.mylutece.web.includes;
35
36 import fr.paris.lutece.plugins.mylutece.authentication.MultiLuteceAuthentication;
37 import fr.paris.lutece.plugins.mylutece.web.MyLuteceApp;
38 import fr.paris.lutece.portal.service.content.PageData;
39 import fr.paris.lutece.portal.service.content.XPageAppService;
40 import fr.paris.lutece.portal.service.includes.PageInclude;
41 import fr.paris.lutece.portal.service.security.LuteceAuthentication;
42 import fr.paris.lutece.portal.service.security.LuteceUser;
43 import fr.paris.lutece.portal.service.security.SecurityService;
44 import fr.paris.lutece.portal.service.security.SecurityTokenService;
45 import fr.paris.lutece.portal.service.template.AppTemplateService;
46 import fr.paris.lutece.util.html.HtmlTemplate;
47
48 import java.util.HashMap;
49 import java.util.Map;
50
51 import javax.servlet.http.HttpServletRequest;
52
53
54
55
56
57 public class UserLoginInclude implements PageInclude
58 {
59 private static final String TOKEN_ACTION_LOGIN = "dologin";
60 private static final String MARK_USERLOGIN = "pageinclude_userlogin";
61 private static final String MARK_USERLOGIN_TITLE = "pageinclude_userlogin_title";
62 private static final String MARK_LIST_AUTHENTICATIONS = "list_authentications";
63 private static final String MARK_URL_NEWACCOUNT = "url_new_account";
64 private static final String TEMPLATE_USER_LOGIN_TITLE = "/skin/plugins/mylutece/includes/user_login_title.html";
65 private static final String TEMPLATE_USER_LOGIN_TITLE_LOGGED = "/skin/plugins/mylutece/includes/user_login_title_logged.html";
66 private static final String TEMPLATE_USER_LOGIN_FORM = "/skin/plugins/mylutece/includes/user_login_include.html";
67 private static final String TEMPLATE_USER_LOGIN_MULTI_FORM = "/skin/plugins/mylutece/includes/user_login_multi_include.html";
68 private static final String MARK_USER = "user";
69 private static final String MARK_DO_LOGIN = "url_dologin";
70 private static final String MARK_DO_LOGOUT = "url_dologout";
71 private static final String MARK_URL_ACCOUNT = "url_account";
72 private static final String PARAMETER_XPAGE_MYLUTECE = "mylutece";
73
74
75
76
77
78
79
80
81
82
83
84
85
86 public void fillTemplate( Map<String, Object> rootModel, PageData data, int nMode, HttpServletRequest request )
87 {
88 String strUserLoginTitle = "<!-- no authenticated user -->";
89 String strUserLoginForm = "<!-- no authenticated user -->";
90
91 Map<String, Object> model = new HashMap<String, Object>( );
92
93 if ( SecurityService.isAuthenticationEnable( ) )
94 {
95 if ( request != null )
96 {
97 LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
98 model.put( MARK_DO_LOGIN, SecurityService.getInstance( ).getDoLoginUrl( ) );
99 model.put( MARK_DO_LOGOUT, SecurityService.getInstance( ).getDoLogoutUrl( ) );
100 model.put( MARK_URL_ACCOUNT, SecurityService.getInstance( ).getViewAccountPageUrl( ) );
101
102 model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, TOKEN_ACTION_LOGIN ) );
103
104 if ( user != null )
105 {
106 model.put( MARK_USER, user );
107
108 HtmlTemplate tTitle = AppTemplateService.getTemplate( TEMPLATE_USER_LOGIN_TITLE_LOGGED, request.getLocale( ), model );
109 strUserLoginTitle = tTitle.getHtml( );
110 }
111 else
112 {
113 String strPage = request.getParameter( XPageAppService.PARAM_XPAGE_APP );
114
115 if ( ( strPage == null ) || !strPage.equals( PARAMETER_XPAGE_MYLUTECE ) )
116 {
117 MyLuteceApp.setCurrentUrl( request );
118 }
119
120 HtmlTemplate tTitle = AppTemplateService.getTemplate( TEMPLATE_USER_LOGIN_TITLE, request.getLocale( ), model );
121 strUserLoginTitle = tTitle.getHtml( );
122 }
123
124 HtmlTemplate t;
125 model.put( MARK_URL_NEWACCOUNT, SecurityService.getInstance( ).getAuthenticationService( ).getNewAccountPageUrl( ) );
126
127 if ( SecurityService.getInstance( ).isMultiAuthenticationSupported( ) )
128 {
129 LuteceAuthentication luteceAuthentication = SecurityService.getInstance( ).getAuthenticationService( );
130
131 if ( luteceAuthentication instanceof MultiLuteceAuthentication )
132 {
133 model.put( MARK_LIST_AUTHENTICATIONS, ( (MultiLuteceAuthentication) luteceAuthentication ).getListLuteceAuthentication( ) );
134 }
135
136 t = AppTemplateService.getTemplate( TEMPLATE_USER_LOGIN_MULTI_FORM, request.getLocale( ), model );
137 }
138 else
139 {
140 t = AppTemplateService.getTemplate( TEMPLATE_USER_LOGIN_FORM, request.getLocale( ), model );
141 }
142
143 strUserLoginForm = t.getHtml( );
144 rootModel.put( "LUTECE_USER", user );
145 }
146 }
147
148 rootModel.put( MARK_USERLOGIN_TITLE, strUserLoginTitle );
149 rootModel.put( MARK_USERLOGIN, strUserLoginForm );
150
151 }
152 }