Example #1
0
 private Button genBut(String name) {
   Button b = new Button(name);
   b.addStyleName("user-select");
   b.setIcon(userIcon);
   b.addClickListener(
       e -> {
         if (loginBox.isVisible()) {
           hidePass();
           return;
         }
         loginField.setValue("");
         String t = e.getButton().getCaption();
         if (Globals.control.hasPassword(t)) {
           selected = Globals.control.getUser(t);
           showPassField();
         } else {
           User s = Globals.control.getUser(t);
           if (s == null) {
             return;
           }
           Globals.user = s;
           Globals.root.changeScreen(Globals.user);
         }
       });
   return b;
 }
Example #2
0
  public UserSelect() {
    loginInfo = new Label("");
    loginInfo.addStyleName("error-font");
    loginInfo.addStyleName("margin15");
    loginInfo.addStyleName("margin-top40");
    loginInfo.setVisible(false);
    selected = null;
    loginField = new PasswordField("");
    loginField.setWidth("200px");
    loginField.addStyleName("margin15");
    loginField.addStyleName("margin-bot40");
    loginBut = new Button("login");
    loginBut.addStyleName("margin15");
    loginBut.addClickListener(
        e -> {
          if (loginField.getValue().equals(selected.getPassword())) {
            hidePass();
            Globals.user = selected;
            Globals.root.changeScreen(Globals.user);
          } else {
            loginInfo.setVisible(true);
            loginInfo.setValue("Wrong password");
            loginField.setValue("");
          }
        });

    loginBox = new HorizontalLayout();
    loginBox.addStyleName("popup-box");
    loginBox.addComponents(loginField, loginBut, loginInfo);
    loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_LEFT);
    loginBox.setComponentAlignment(loginBut, Alignment.MIDDLE_CENTER);
    loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_RIGHT);
    loginBox.setVisible(false);
    userIcon = new ThemeResource("icons/user.png");
    users = Globals.control.usersData();
    vbox = new VerticalLayout();
    // vbox.setSizeUndefined();
    vbox.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    Panel p = new Panel();
    p.setSizeFull();

    p.setContent(vbox);
    // vbox.addStyleName("border-l-r");
    this.addComponent(p, "left: 25%; right: 25%; top: 15px");
    this.addComponent(loginBox, "left: 25%; right: 25%; top: 40%");

    this.addLayoutClickListener(
        e -> {
          if (!loginBox.isVisible()) return;
          System.out.println(e.getClickedComponent());
          if (e.getClickedComponent() == null || e.getClickedComponent().equals(vbox)) hidePass();
        });
  }
 private void login() {
     try {
         final Authentication authentication = vaadinSecurity.login(userName.getValue(), passwordField.getValue());
         eventBus.publish(this, new SuccessfulLoginEvent(getUI(), authentication));
     } catch (AuthenticationException ex) {
         userName.focus();
         userName.selectAll();
         passwordField.setValue("");
         loginFailedLabel.setValue(String.format("Login failed: %s", ex.getMessage()));
         loginFailedLabel.setVisible(true);
     } catch (Exception ex) {
         Notification.show("An unexpected error occurred", ex.getMessage(), Notification.Type.ERROR_MESSAGE);
         LoggerFactory.getLogger(getClass()).error("Unexpected error while logging in", ex);
     } finally {
         login.setEnabled(true);
     }
 }
  public LoginModule() {

    setMargin(true);
    setSpacing(true);
    grid.setSizeFull();
    grid.setSpacing(true);

    final TextField username = new TextField();
    username.setValue("username");
    username.setWidth("120px");
    username.setStyleName("small");
    grid.addComponent(username, 0, 0);

    final PasswordField password = new PasswordField();
    password.setValue("password");
    password.setWidth("120px");
    password.setStyleName("small");
    grid.addComponent(password, 0, 1);

    Button button = new Button("Login");
    button.setWidth("120px");
    button.setStyleName("small");
    button.addListener(
        new Button.ClickListener() {

          @Override
          public void buttonClick(ClickEvent event) {
            login.setUsername(username.getValue().toString());
            login.setPassword(password.getValue().toString());
            String user = login.getUsername();
            String pass = login.getPassword();
            // login.setResult(authLog.login(user, pass));
            boolean result = authLog.login(user, pass);
            if (result == true) {
              label.setCaption("Successfully Login");
            } else {
              label.setCaption("SQL Error");
            }
          }
        });
    grid.addComponent(button, 0, 2);
    panel.addComponent(grid);
    addComponent(panel);
    addComponent(label);
  }
Example #5
0
 @Test
 public void testPasswordField() {
   PasswordField field = new PasswordField("pwd");
   field.setValue("1234");
   assertOut(field, "<input type='password' name='pwd' value=''>");
 }
Example #6
0
 private void hidePass() {
   loginBox.setVisible(false);
   loginInfo.setVisible(false);
   loginField.setValue("");
   vbox.removeStyleName("fuzzy");
 }