01: //WebOnSwing - Web Application Framework
02: //Copyright (C) 2004 Fernando Damian Petrola
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library 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 GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: package weblog;
19:
20: import java.awt.event.*;
21:
22: import javax.swing.*;
23:
24: import net.ar.webonswing.*;
25: import net.ar.webonswing.swing.components.*;
26:
27: import org.wafer.weblog.om.*;
28: import org.wafer.weblog.servlet.*;
29:
30: public class LoginPanel extends MultipleFieldsPanel {
31: JTextField usernameField;
32: JPasswordField passwordField;
33: JLabel errorMessage;
34:
35: public LoginPanel() {
36: super (
37: new JLink(
38: "Enter your username and password to log in. New users must register first.",
39: RegisterView.class));
40: }
41:
42: protected void initialize() {
43: super .initialize();
44:
45: submitButton.setText("Login");
46: submitButton.addActionListener(new ActionListener() {
47: public void actionPerformed(ActionEvent arg0) {
48: try {
49: if (!WebLogSystem.getUserStore().verify(
50: usernameField.getText()))
51: errorMessage
52: .setText("password or username incorrect");
53: else {
54: User currentUser = WebLogSystem.getUserStore()
55: .getUser(usernameField.getText());
56:
57: if (!currentUser.getPassword()
58: .equals(
59: new String(passwordField
60: .getPassword())))
61: errorMessage
62: .setText("password or username incorrect");
63: else {
64: WosFramework.getSessionContext().put(
65: "activeUser", currentUser);
66: WosFramework.showChildWindow(
67: getTopLevelAncestor(), new Home());
68: WosFramework.hide(getTopLevelAncestor());
69: }
70: }
71: } catch (Exception e) {
72: e.printStackTrace();
73: }
74: }
75: });
76:
77: addFieldPanel("Username", usernameField = new JTextField());
78: addFieldPanel("Password", passwordField = new JPasswordField());
79: addFieldPanel("", errorMessage = new JLabel());
80: }
81: }
|