Source code: nectar/template/blocks/LoginBlockView.java
1 /*
2 Copyright (C) 2003 Kai Schutte
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 2 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, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 * LoginBlockView.java
19 *
20 * Created on March 27, 2003, 12:24 PM
21 */
22
23 package nectar.template.blocks;
24
25 import nectar.view.PersonView;
26 import org.apache.struts.action.ActionForm;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpSession;
29 import nectar.ServicesUtil;
30 import nectar.record.PersonRecord;
31 import nectar.data.DataException;
32
33 /**
34 *
35 * @author Kai Schutte skander@skander.com
36 */
37 public class LoginBlockView extends BlockView {
38 PersonView user = null;
39 public static final String LOGIN_ERROR_KEY = "nectar_view_blocks_LoginBlockView";
40
41 public boolean isLoggedIn() { if (user == null) return false; return true; }
42 public void setLoggedIn(boolean b) { }
43 public PersonView getView() { return user; }
44 public void setView(PersonView s){ user = s; }
45 public String getErrorKey() { return LOGIN_ERROR_KEY; }
46
47 public void init() throws DataException {
48 HttpSession session = this.request.getSession(false);
49 if (session != null) {
50 Object userID = session.getAttribute("User");
51 PersonRecord userRecord = null;
52 if (userID != null) {
53 userRecord = ServicesUtil.getRecordService().getPerson(project, (Long)userID);
54 }
55 if (userRecord != null)
56 this.user = new PersonView(userRecord);
57 }
58 }
59
60 }