1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.whatsitcalled.webflange.webapp;
18
19 import org.apache.wicket.Application;
20 import org.apache.wicket.markup.html.form.CheckBox;
21 import org.apache.wicket.markup.html.form.FormComponent;
22 import org.apache.wicket.markup.html.form.PasswordTextField;
23 import org.apache.wicket.markup.html.form.StatelessForm;
24 import org.apache.wicket.markup.html.form.TextField;
25 import org.apache.wicket.markup.html.panel.Panel;
26 import org.apache.wicket.model.CompoundPropertyModel;
27 import org.apache.wicket.model.PropertyModel;
28 import org.apache.wicket.util.value.ValueMap;
29
30
31
32
33
34
35 public abstract class UsernamePasswordSignInPanel extends Panel
36 {
37
38
39
40
41
42
43 public UsernamePasswordSignInPanel(final String id)
44 {
45 super(id);
46 add(new SignInForm("signInForm").setOutputMarkupId(false));
47 }
48
49
50
51
52
53
54
55
56 public abstract boolean signIn(String username, String password);
57
58
59
60
61 public final class SignInForm extends StatelessForm
62 {
63 private static final long serialVersionUID = 1L;
64
65
66
67
68 private boolean rememberMe = true;
69
70
71
72
73
74
75
76 public SignInForm(final String id)
77 {
78 super(id, new CompoundPropertyModel(new ValueMap()));
79
80
81 add(new TextField("username").setPersistent(rememberMe).setOutputMarkupId(false));
82 add(new PasswordTextField("password").setOutputMarkupId(false));
83 add(new CheckBox("rememberMe", new PropertyModel(this, "rememberMe")));
84 }
85
86
87
88
89
90 public String getMarkupId()
91 {
92
93 return getId();
94 }
95
96
97
98
99
100 public final void onSubmit()
101 {
102 if (!rememberMe)
103 {
104
105 getPage().removePersistedFormData(SignInForm.class, true);
106 }
107
108 ValueMap values = (ValueMap)getModelObject();
109 String username = values.getString("username");
110 String password = values.getString("password");
111
112 if (signIn(username, password))
113 {
114
115 if (!getPage().continueToOriginalDestination())
116 {
117 setResponsePage(Application.get().getHomePage());
118 }
119 }
120 else
121 {
122
123
124 error(getLocalizer().getString("exception.login", this,
125 "Illegal username password combo"));
126 }
127 }
128
129
130
131
132
133 public boolean getRememberMe()
134 {
135 return rememberMe;
136 }
137
138
139
140
141
142
143
144 public void setRememberMe(boolean rememberMe)
145 {
146 this.rememberMe = rememberMe;
147 ((FormComponent)get("username")).setPersistent(rememberMe);
148 }
149 }
150 }