Exemplo n.º 1
0
  protected void doLogin() {
    if (error != null) {
      errores.removeComponent(error);
    }
    username.setComponentError(null);
    clave.setComponentError(null);

    if (username.getValue() == null || username.getValue().trim().equalsIgnoreCase("")) {
      username.setComponentError(new UserError("Ingrese su usuario"));
      return;
    }
    if (clave.getValue() == null || clave.getValue().trim().equalsIgnoreCase("")) {
      clave.setComponentError(new UserError("Ingrese su clave"));
      return;
    }

    Usuario usuario;
    try {
      String md5 = new Encrypter().MD5(clave.getValue());
      usuario = servicio.getLogin(username.getValue(), md5);
      if (!(usuario == null)) {
        if (usuario.getType().equals("Administrador")) {

          ((SapoBackofficeUI) UI.getCurrent()).login(usuario);
        } else cargarError("Usuario no habilitado para este sistema");
      } else {
        cargarError("Usuario/Clave incorrectos o no esta registrado");
      }
    } catch (Exception e) {
      cargarError(e.getMessage());
    }
  }
Exemplo n.º 2
0
 protected void checkDatabase(String uname, String pword) {
   try {
     Connection conn = new MyDatabaseHandler().getConn();
     PreparedStatement stat =
         conn.prepareStatement(
             "select * from staff where s_uname = '" + uname + "' and s_pword = '" + pword + "'");
     ResultSet rs = stat.executeQuery();
     if (rs.next()) {
       SharedValues.StaffID = rs.getString(1).toString();
       SharedValues.StaffName = rs.getString(2);
       SharedValues.StaffType = rs.getString(6);
       Mc_projectUI.navigator.navigateTo(Mc_projectUI.MAINVIEW);
     } else if (username.getValue() == "" && password.getValue() == "") {
       blankErrNote.show(Page.getCurrent());
       blankErrNote.setDelayMsec(500);
       blankErrNote.setPosition(Position.MIDDLE_CENTER);
     } else {
       loginErrNote.show(Page.getCurrent());
       loginErrNote.setDelayMsec(500);
       loginErrNote.setPosition(Position.MIDDLE_CENTER);
     }
   } catch (Exception e) {
     Logger log = new Logger();
     log.logCreator("Login Error");
   }
 }
 @Override
 public FormData getFormData() {
   FormData data = new FormData(function);
   data.setAddress(inputAddress.getValue());
   data.setEmployeeNum(inputEmployeeNum.getValue());
   data.setName(inputName.getValue());
   data.setPassword1(inputPassword1.getValue());
   data.setPassword2(inputPassword2.getValue());
   data.setPhoneNumber(inputPhoneNumber.getValue());
   data.setRole((String) selectRole.getValue());
   data.setSika(inputSika.getValue());
   data.setTitle(inputTitle.getValue());
   data.setUserName(inputUserName.getValue());
   data.setEditMode(editMode);
   return data;
 }
Exemplo n.º 4
0
 public Validator getPasswordsMatchValidator(final PasswordField newPass) {
   return (Validator)
       value -> {
         if (!newPass.getValue().equals(value))
           throw new Validator.InvalidValueException(getApp().getMessage("error.passwordsMatch"));
       };
 }
Exemplo n.º 5
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();
        });
  }
  @Override
  public void buttonClick(ClickEvent event) {
    if (!userTextField.isValid() || !passwordField.isValid()) {
      return;
    }

    AuthenticationImpl auth = new AuthenticationImpl();
    boolean isValid = auth.authenticate(userTextField.getValue(), passwordField.getValue());

    if (isValid) {
      // set session parameters
      getSession().setAttribute("user", userTextField.getValue());

      // Navigate to main view
      getUI().getNavigator().navigateTo(SimpleLoginMainView.NAME);
    } else {
      passwordField.setValue(null);
      passwordField.focus();
    }
  }
Exemplo n.º 7
0
 public byte[] getPasswordVerification() {
   return passwordVerification.getValue().getBytes(Charset.forName("UTF-8"));
 }
Exemplo n.º 8
0
 public byte[] getPassword() {
   return password.getValue().getBytes(Charset.forName("UTF-8"));
 }
Exemplo n.º 9
0
  public void gotoMain(ClickEvent event) {

    if (!username.getValue().isEmpty() && !password.getValue().isEmpty()) {

      Accounts acc = service.validate(username.getValue(), password.getValue());

      if (acc != null) {

        VaadinSession.getCurrent().setAttribute("id", acc.getId());
        switch (acc.getUsertype().getName()) {
          case "Administrator":
            closeModal();
            UI.getCurrent().getNavigator().navigateTo(Main.NAME);
            break;
          case "Municipal":
            Information info = iService.by_account(acc.getId());
            try {
              User_municipal userInMunicipal = uService.user_municipal(info.getInfoid());
              VaadinSession.getCurrent()
                  .setAttribute("municipaldata", userInMunicipal.getMunicipal());
              closeModal();
              UI.getCurrent().getNavigator().navigateTo(MunicipalView.VIEW_NAME);
            } catch (NullPointerException e) {
              Notification.show("Acount is invalid", Notification.TYPE_ERROR_MESSAGE);
            }
            break;
          case "Barangay":
            Information info1 = iService.by_account(acc.getId());
            try {
              User_barangay userBarangay = uService.get_barangay_info(info1.getInfoid());
              VaadinSession.getCurrent().setAttribute("barangaydata", userBarangay.getBarangay());
              closeModal();
              UI.getCurrent().getNavigator().navigateTo(BarangayView.VIEW_NAME);
            } catch (NullPointerException e) {
              Notification.show("Acount is invalid", Notification.TYPE_ERROR_MESSAGE);
              VaadinSession.getCurrent().setAttribute("barangaydata", null);
            }
            break;
          case "Voter":
            System.out.println("Voter");
            Information info2 = iService.by_account(acc.getId());
            try {
              User_voter userVoter = uService.get_voter_barangay_info(info2.getInfoid());
              VaadinSession.getCurrent().setAttribute("barangaydata", userVoter.getBarangay());
              closeModal();
              UI.getCurrent().getNavigator().navigateTo(VoterView.VIEW_NAME);
            } catch (NullPointerException e) {
              Notification.show("Acount is invalid", Notification.TYPE_ERROR_MESSAGE);
              VaadinSession.getCurrent().setAttribute("barangaydata", null);
            }
            break;
          default:
            UI.getCurrent().getNavigator().navigateTo("/");
            break;
        }
      } else {
        Notification.show("Acount is invalid", Notification.TYPE_ERROR_MESSAGE);
      }
    } else {
      Notification.show("Empty field", Notification.TYPE_WARNING_MESSAGE);
    }
  }