1
2
3
4
5
6 package com.hack23.cia.web.views.user;
7
8 import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
9 import org.springframework.security.authentication.encoding.PasswordEncoder;
10
11 import thinwire.ui.Button;
12 import thinwire.ui.Label;
13 import thinwire.ui.Panel;
14 import thinwire.ui.TextField;
15 import thinwire.ui.AlignTextComponent.AlignX;
16 import thinwire.ui.event.ActionEvent;
17 import thinwire.ui.event.ActionListener;
18 import thinwire.ui.layout.TableLayout;
19
20 import com.hack23.cia.model.application.dto.common.UserSessionDTO;
21 import com.hack23.cia.model.application.impl.common.Agency;
22 import com.hack23.cia.model.application.impl.user.UserAccountActionEvent;
23 import com.hack23.cia.web.action.user.UserAccountAction;
24 import com.hack23.cia.web.common.BeanLocator;
25
26 /***
27 * The Class LoginPanel.
28 */
29 public class LoginPanel extends Panel {
30
31 /*** The login action listener. */
32 private final ActionListener loginActionListener = new ActionListener() {
33 @Override
34 public void actionPerformed(final ActionEvent ev) {
35 final Button okButton = (Button) ev.getSource();
36 okButton.setUserObject(new UserAccountAction(UserAccountActionEvent.Operation.Process_login, nameField.getText(), passwordEncoder.encodePassword(passwordField.getText(), null)));
37 BeanLocator.getApplicationActionListener().actionPerformed(ev);
38 }
39 };
40
41 /*** The name field. */
42 private final TextField nameField = new TextField();
43
44 /*** The password encoder. */
45 private final PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
46
47 /*** The password field. */
48 private final TextField passwordField = new TextField();
49
50 /***
51 * Instantiates a new login panel.
52 *
53 * @param userSessionDTO the user session dto
54 */
55 public LoginPanel(final UserSessionDTO userSessionDTO) {
56 super();
57 setLayout(new TableLayout(new double[][] { { 0, 0 },
58
59 { 0, 0, 0, 0 } },
60 10,
61 5));
62 final Label nameLabel = new Label(userSessionDTO
63 .getLanguageResource(Agency.LanguageContentKey.NAME));
64 nameLabel.setLimit("0,0");
65 getChildren().add(nameLabel);
66
67 nameField.setLimit("1,0");
68 getChildren().add(nameField);
69
70 final Label passwordLabel = new Label(userSessionDTO
71 .getLanguageResource(Agency.LanguageContentKey.PASSWORD));
72 passwordLabel.setLimit("0,1");
73 passwordLabel.setAlignX(AlignX.LEFT);
74 getChildren().add(passwordLabel);
75
76 passwordField.setLimit("1,1");
77 passwordField.setInputHidden(true);
78 getChildren().add(passwordField);
79
80 final Button okButton = new Button(userSessionDTO
81 .getLanguageResource(Agency.LanguageContentKey.BUTTON_OK));
82 okButton.setLimit("1,3");
83 okButton.addActionListener(ACTION_CLICK, loginActionListener);
84 getChildren().add(okButton);
85 }
86 }