private Component buildFields() { HorizontalLayout fields = new HorizontalLayout(); fields.setSpacing(true); fields.addStyleName("fields"); username = new TextField("Usuario"); username.setIcon(FontAwesome.USER); username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON); username.focus(); clave = new PasswordField("Contraseña"); clave.setIcon(FontAwesome.LOCK); clave.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON); final Button signin = new Button("Entrar"); signin.addStyleName(ValoTheme.BUTTON_PRIMARY); signin.setClickShortcut(KeyCode.ENTER); fields.addComponents(username, clave, signin); fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT); signin.addClickListener( new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { doLogin(); } }); return fields; }
@AutoGenerated private HorizontalLayout buildPasswordDiv() { // common part: create layout passwordDiv = new HorizontalLayout(); passwordDiv.setImmediate(false); passwordDiv.setDescription("Your password"); passwordDiv.setWidth("291px"); passwordDiv.setHeight("34px"); passwordDiv.setMargin(false); // passwordLabel passwordLabel = new Label(); passwordLabel.setImmediate(false); passwordLabel.setWidth("80px"); passwordLabel.setHeight("20px"); passwordLabel.setValue("Password:"******"Need Password"); passwordField.setImmediate(false); passwordField.setWidth("197px"); passwordField.setHeight("20px"); passwordField.setRequired(true); passwordDiv.addComponent(passwordField); passwordDiv.setComponentAlignment(passwordField, new Alignment(34)); return passwordDiv; }
@AutoGenerated private HorizontalLayout buildConfirmDiv() { // common part: create layout confirmDiv = new HorizontalLayout(); confirmDiv.setImmediate(false); confirmDiv.setWidth("100.0%"); confirmDiv.setHeight("100.0%"); confirmDiv.setMargin(false); // confirmLabel confirmLabel = new Label(); confirmLabel.setImmediate(false); confirmLabel.setWidth("52px"); confirmLabel.setHeight("-1px"); confirmLabel.setValue("Confirm:"); confirmDiv.addComponent(confirmLabel); confirmDiv.setComponentAlignment(confirmLabel, new Alignment(9)); // passwordConfirm passwordConfirm = new PasswordField(); passwordConfirm.setCaption("Need confirm password:"******"195px"); passwordConfirm.setHeight("20px"); passwordConfirm.setRequired(true); confirmDiv.addComponent(passwordConfirm); confirmDiv.setExpandRatio(passwordConfirm, 1.0f); confirmDiv.setComponentAlignment(passwordConfirm, new Alignment(34)); return confirmDiv; }
public Field createField(Item item, Object propertyId, Component uiContext) { // Identify the fields by their Property ID. String pid = (String) propertyId; if ("userName".equals(pid)) { TextField field = new TextField("Username (Email)"); field.setRequired(true); field.setRequiredError("Please supply a username"); field.addValidator(new EmailValidator("Username must be an email address")); return field; } else if ("password".equals(pid)) { PasswordField field = new PasswordField("Password"); field.setRequired(true); field.setRequiredError("Please supply a password"); field.addValidator(new StringLengthValidator(VAL_PASSWD_LEN_MESSAGE, 5, 999, false)); field.addValidator(new NoWhiteSpaceValidator(VAL_PASSWD_TXT_MESSAGE)); return field; } else if ("confirmPassword".equals(pid)) { PasswordField field = new PasswordField("Confirm Password"); field.setRequired(true); field.setRequiredError("Please confirm your password"); field.addValidator(new StringLengthValidator(VAL_PASSWD_LEN_MESSAGE, 5, 999, false)); field.addValidator(new NoWhiteSpaceValidator(VAL_PASSWD_TXT_MESSAGE)); return field; } return null; // Invalid field (property) name. }
private com.vaadin.ui.Component buildFields() { HorizontalLayout fields = new HorizontalLayout(); fields.setSpacing(true); fields.addStyleName("fields"); final TextField username = new TextField("Username"); username.setIcon(FontAwesome.USER); username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON); final PasswordField password = new PasswordField("Password"); password.setIcon(FontAwesome.LOCK); password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON); final Button signin = new Button("Sign In"); signin.addStyleName(ValoTheme.BUTTON_PRIMARY); signin.setClickShortcut(ShortcutAction.KeyCode.ENTER); signin.focus(); fields.addComponents(username, password, signin); fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT); signin.addClickListener( new Button.ClickListener() { @Override public void buttonClick(final Button.ClickEvent event) { DashboardEventBus.post( new UserLoginRequestedEvent(username.getValue(), password.getValue())); } }); return fields; }
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()); } }
/** * Sets the corresponding values of specific user to the dialog. * * @param selectedUser . User that locate in the row of User table in which has been pressed the * button Change settings. */ public void setSelectedUser(User selectedUser) { userFullName.setValue(selectedUser.getFullName()); userName.setValue(selectedUser.getUsername()); password.setValue("*****"); passwordConfim.setValue("*****"); userEmail.setValue(selectedUser.getEmail().toString()); roleSelector.setValue(selectedUser.getRoles()); selectUser = selectedUser; }
private void limpaCampos() { ligaCampos(); nome.setValue(""); email.setValue(""); telefone.setValue(""); cargo.setValue(""); login.setValue(""); senha1.setValue(""); senha2.setValue(""); admin.setValue(false); desligaCampos(); }
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(); }); }
public StartView() { setSizeFull(); setMargin(true); // Create a panel called login Panel panel = new Panel("Login"); panel.setSizeUndefined(); // Shrink to fit content addComponent(panel); setComponentAlignment(panel, Alignment.MIDDLE_CENTER); // Create the content FormLayout content = new FormLayout(); username.setWidth("300px"); username.setRequired(true); username.setInputPrompt("Your username(eg. [email protected])"); content.addComponent(username); password.setWidth("300px"); password.setRequired(true); content.addComponent(password); HorizontalLayout buttonArea = new HorizontalLayout(); buttonArea.setSizeFull(); Button submit = new Button("Submit"); Button clear = new Button("Clear"); clear.addClickListener( new Button.ClickListener() { public void buttonClick(ClickEvent event) { username.setValue(""); password.setValue(""); } }); submit.addClickListener( new Button.ClickListener() { public void buttonClick(ClickEvent event) { checkDatabase(username.getValue(), password.getValue()); } }); buttonArea.addComponent(clear); buttonArea.addComponent(submit); content.addComponent(buttonArea); content.setSizeFull(); content.setMargin(true); panel.setContent(content); }
@Override public void resetForm() { inputUserName.setValue(""); inputName.setValue(""); inputTitle.setValue(""); inputAddress.setValue(""); inputEmployeeNum.setValue(""); inputPhoneNumber.setValue(""); inputPassword1.setValue(""); inputPassword2.setValue(""); inputSika.setValue(""); }
private void desligaCampos() { titulo.setReadOnly(true); nome.setReadOnly(true); email.setReadOnly(true); telefone.setReadOnly(true); cargo.setReadOnly(true); login.setReadOnly(true); senha1.setReadOnly(true); senha2.setReadOnly(true); admin.setReadOnly(true); // users.setEnabled(true); bloquear.setReadOnly(true); }
@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; }
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; }
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"); } }
public Validator getPasswordsMatchValidator(final PasswordField newPass) { return (Validator) value -> { if (!newPass.getValue().equals(value)) throw new Validator.InvalidValueException(getApp().getMessage("error.passwordsMatch")); }; }
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); }
@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(); } }
public LoginViewImpl() { setSizeFull(); login.setIcon(FontAwesome.HAND_O_RIGHT); // TODO remove these prefilled values used for testing username.setValue("admin"); password.setValue("password"); password.focus(); Panel loginPanel = new Panel("Login to application"); loginPanel.setSizeUndefined(); loginPanel.setContent( new MVerticalLayout(username, password, login).withAlign(login, Alignment.BOTTOM_RIGHT)); setCompositionRoot( new MVerticalLayout(loginPanel) .withAlign(loginPanel, Alignment.MIDDLE_CENTER) .withFullHeight()); }
public SimpleLoginView() { setSizeFull(); // Create the user input field userTextField = new TextField("User name: "); userTextField.setWidth("300px"); userTextField.setRequired(true); userTextField.setInputPrompt("Your username (eg. user1)"); userTextField.addValidator(new LoginValidator()); userTextField.setInvalidAllowed(false); // Create the password input field passwordField = new PasswordField("Password:"******"300px"); passwordField.setRequired(true); passwordField.addValidator(new PasswordValidator()); passwordField.setValue(""); passwordField.setNullRepresentation(""); // Create login button loginButton = new Button("Login", this); // Add all to a panel VerticalLayout fields = new VerticalLayout(userTextField, passwordField, loginButton); fields.setCaption("Please login to access the application. (user1/password)"); fields.setSpacing(true); fields.setMargin(new MarginInfo(true, true, true, false)); fields.setSizeUndefined(); // The view root layout VerticalLayout viewLayout = new VerticalLayout(fields); viewLayout.setSizeFull(); viewLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER); viewLayout.setStyleName(Reindeer.LAYOUT_BLUE); setCompositionRoot(viewLayout); }
@Override public void setEditMode(boolean editMode) { System.out.println("Edit mode " + editMode); this.editMode = editMode; if (editMode) { buttonSaveEdit.setVisible(true); buttonSubmit.setVisible(false); inputPassword1.setVisible(false); inputPassword2.setVisible(false); buttonActivation.setVisible(true); buttonResetPassword.setVisible(true); inputUserName.setEnabled(false); buttonReset.setVisible(false); } else { buttonSaveEdit.setVisible(false); buttonSubmit.setVisible(true); inputPassword1.setVisible(true); inputPassword2.setVisible(true); buttonActivation.setVisible(false); inputUserName.setEnabled(true); buttonReset.setVisible(true); buttonResetPassword.setVisible(false); } }
public Login() { // TODO Auto-generated constructor stub VaadinSession.getCurrent().setAttribute("municipaldata", null); VaadinSession.getCurrent().setAttribute("barangaydata", null); VaadinSession.getCurrent().setAttribute("id", null); setSizeFull(); dialog = new Window("Login"); dialog.setClosable(false); dialog.setResizable(false); dialog.center(); // new CreateAccount(); VerticalLayout content = new VerticalLayout(); content.setSpacing(true); content.setMargin(new MarginInfo(false, true, true, true)); dialog.setContent(content); Label title = new Label("Login"); title.addStyleName(ValoTheme.LABEL_H2); title.addStyleName(ValoTheme.LABEL_COLORED); HorizontalLayout form = new HorizontalLayout(); form.setSpacing(true); form.addStyleName("wrapping"); content.addComponent(form); username.setIcon(FontAwesome.USER); username.focus(); form.addComponent(username); password.setIcon(FontAwesome.LOCK); form.addComponent(password); Button submit = new Button("Login"); submit.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_RIGHT); submit.addStyleName(ValoTheme.BUTTON_PRIMARY); submit.setIcon(FontAwesome.ARROW_RIGHT); submit.setWidth("100%"); submit.addListener(ClickEvent.class, this, "gotoMain"); content.addComponent(submit); }
private void configureActions() { Property.ValueChangeListener clearErrorTextFields = new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { TextField curr = (TextField) event.getProperty(); curr.setComponentError(null); } }; Property.ValueChangeListener clearErrorPassFields = new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { PasswordField curr = (PasswordField) event.getProperty(); curr.setComponentError(null); } }; username.addValueChangeListener(clearErrorTextFields); password.addValueChangeListener(clearErrorPassFields); }
/** * Builds main layout * * @return mainLayout VerticalLayout with all dialog components */ @AutoGenerated private VerticalLayout buildMainLayout(final boolean newUser) { mainLayout = new VerticalLayout(); mainLayout.setImmediate(false); mainLayout.setMargin(true); mainLayout.setSpacing(true); mainLayout.setWidth("380px"); users = userFacade.getAllUsers(); userDetailsLayout = new GridLayout(2, 5); userDetailsLayout.setImmediate(false); userDetailsLayout.setSpacing(true); userFullName = new TextField(); userFullName.setImmediate(true); userFullName.setWidth("250px"); userFullName.addValidator( new Validator() { private static final long serialVersionUID = 1L; @Override public void validate(Object value) throws InvalidValueException { if (value != null && (value.getClass() == String.class && !((String) value).isEmpty())) { String inputFullName = (String) value; Pattern namePattern1 = Pattern.compile( "([A-Za-zŽžÝýŮůÚúŤťŠšŘřÓóŇňÍíĚěÉéĎďČčÁáÄäÖößÜüÀàÈèÙùÂâÊêÎîÔôÛûÇçËëÏïÜüŸÿ]+\\s*)+", Pattern.UNICODE_CASE); Matcher m = namePattern1.matcher(inputFullName); if (!m.matches()) { ex = new InvalidValueException( "Full user name must start with a letter and can only consists of letters and spaces."); throw ex; } if ((m.end() - m.start()) < 2) { ex = new InvalidValueException("Full user name must contains more than one symbol"); throw ex; } } } }); userDetailsLayout.addComponent(new Label("Full user name:"), 0, 0); userDetailsLayout.addComponent(userFullName, 1, 0); userName = new TextField(); userName.setImmediate(true); userName.setWidth("250px"); userName.addValidator( new Validator() { private static final long serialVersionUID = 1L; @Override public void validate(Object value) throws InvalidValueException { if (value.getClass() == String.class && !((String) value).isEmpty()) { String inputName = (String) value; for (User user : users) { if (user.getUsername().equals(inputName)) { if (selectUser == null || (selectUser.getId() != user.getId())) { ex = new InvalidValueException("user with this user name is already exist"); throw ex; } } } return; } ex = new InvalidValueException("user name field must be filled"); throw ex; } }); userDetailsLayout.addComponent(new Label("User name:"), 0, 1); userDetailsLayout.addComponent(userName, 1, 1); password = new PasswordField(); password.setImmediate(true); password.setWidth("250px"); password.addFocusListener( new FocusListener() { private static final long serialVersionUID = 1L; @Override public void focus(FocusEvent event) { password.setValue(""); passwordConfim.setValue(""); passChanged = true; } }); Label passLabel = new Label("Password:"******"250px"); Label confirmLabel = new Label("Password<br>confirmation:"); passwordConfim.addFocusListener( new FocusListener() { private static final long serialVersionUID = 1L; @Override public void focus(FocusEvent event) { passwordConfim.setValue(""); passChanged = true; } }); confirmLabel.setContentMode(ContentMode.HTML); userDetailsLayout.addComponent(confirmLabel, 0, 3); userDetailsLayout.addComponent(passwordConfim, 1, 3); userEmail = new TextField(); userEmail.setImmediate(true); userEmail.setWidth("250px"); userEmail.addValidator( new Validator() { private static final long serialVersionUID = 1L; @Override public void validate(Object value) throws InvalidValueException { if (value.getClass() == String.class && !((String) value).isEmpty()) { String inputEmail = (String) value; if (!inputEmail.matches( "[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})")) { ex = new InvalidValueException("wrong mail format"); throw ex; } return; } ex = new InvalidValueException("e-mail field must be filled"); throw ex; } }); userDetailsLayout.addComponent(new Label("E-mail:"), 0, 4); userDetailsLayout.addComponent(userEmail, 1, 4); userDetailsLayout.setColumnExpandRatio(0, 0.3f); userDetailsLayout.setColumnExpandRatio(1, 0.7f); roleSelector = new TwinColSelect(); roleSelector.addItem(Role.ROLE_ADMIN); roleSelector.addItem(Role.ROLE_USER); roleSelector.setNullSelectionAllowed(true); roleSelector.setMultiSelect(true); roleSelector.setImmediate(true); roleSelector.setWidth("335px"); roleSelector.setHeight("200px"); roleSelector.setLeftColumnCaption("Defined Roles:"); roleSelector.setRightColumnCaption("Set Roles:"); roleSelector.addValueChangeListener( new ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { Set<Object> selectedRoles = (Set<Object>) roleSelector.getValue(); Iterator<Object> it = selectedRoles.iterator(); Set<Role> role = new HashSet<>(); while (it.hasNext()) { Object selectRole = it.next(); if (selectRole.equals(Role.ROLE_ADMIN)) { role.add(Role.ROLE_ADMIN); role.add(Role.ROLE_USER); roleSelector.setValue(role); } } } }); // roleSelector is mandatory component roleSelector.addValidator( new Validator() { private static final long serialVersionUID = 1L; @Override public void validate(Object value) throws InvalidValueException { if (!"[]".equals(value.toString())) { return; } ex = new InvalidValueException("at least one role must be set"); throw ex; } }); // Layout with buttons Save and Cancel HorizontalLayout buttonBar = new HorizontalLayout(); // buttonBar.setMargin(true); // Save button Button createUser = new Button(); createUser.setCaption("Save"); createUser.setWidth("90px"); createUser.setImmediate(true); createUser.addClickListener( new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { String errorText = ""; // validation // User name, password,e-mail and roles should be filled // email should be in correct format try { userFullName.validate(); } catch (Validator.InvalidValueException e) { errorText = errorText + e.getMessage(); } try { userName.validate(); } catch (Validator.InvalidValueException e) { if (!errorText.equals("")) { errorText = errorText + ", " + e.getMessage(); } else { errorText = errorText + e.getMessage(); } } try { userEmail.validate(); } catch (Validator.InvalidValueException e) { if (!errorText.equals("")) { errorText = errorText + ", " + e.getMessage(); } else { errorText = errorText + e.getMessage(); } } try { roleSelector.validate(); } catch (Validator.InvalidValueException e) { if (!errorText.equals("")) { errorText = errorText + ", " + e.getMessage(); } else { errorText = errorText + e.getMessage(); } } if (!errorText.equals("")) { errorText = errorText + "."; Notification.show( "Failed to save settings. Reason:", errorText, Notification.Type.ERROR_MESSAGE); return; } // checking if the dialog was open from the User table // if no, create new user record if (newUser) { String userPassword; if (passwordConfim.getValue().equals(password.getValue())) { if (!passwordConfim.getValue().isEmpty()) { userPassword = password.getValue(); } else { userPassword = createPassword(); } } else { Notification.show( "Password confirmation is wrong", "The typed pasword is different than the retyped password", Notification.Type.ERROR_MESSAGE); return; } EmailAddress email = new EmailAddress(userEmail.getValue().trim()); user = userFacade.createUser(userName.getValue().trim(), userPassword, email); user.setFullName(userFullName.getValue().trim()); } else { user = selectUser; user.setFullName(userFullName.getValue().trim()); user.setUsername(userName.getValue().trim()); if (passChanged) { if (passwordConfim.getValue().equals(password.getValue())) { if (!passwordConfim.getValue().isEmpty()) { user.setPassword(password.getValue()); } else { user.setPassword(createPassword()); } } else { Notification.show( "Password confirmation is wrong", "The typed pasword is different than the retyped password", Notification.Type.ERROR_MESSAGE); return; } } EmailAddress email = new EmailAddress(userEmail.getValue().trim()); user.setEmail(email); } @SuppressWarnings("unchecked") Set<Object> selectedRoles = (Set<Object>) roleSelector.getValue(); Iterator<Object> it = selectedRoles.iterator(); roles = new HashSet<>(); while (it.hasNext()) { Object selectRole = it.next(); if (selectRole.equals(Role.ROLE_ADMIN)) { roles.add(Role.ROLE_ADMIN); } else { roles.add(Role.ROLE_USER); } } user.setRoles(roles); // store user record to DB userFacade.save(user); close(); } }); buttonBar.addComponent(createUser); Button cancelButton = new Button( "Cancel", new Button.ClickListener() { /** Closes Scheduling pipeline window */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancelButton.setWidth("90px"); buttonBar.addComponent(cancelButton); mainLayout.addComponent(userDetailsLayout); mainLayout.addComponent(roleSelector); mainLayout.addComponent(buttonBar); // mainLayout.setComponentAlignment(buttonBar, Alignment.MIDDLE_RIGHT); return mainLayout; }
public byte[] getPasswordVerification() { return passwordVerification.getValue().getBytes(Charset.forName("UTF-8")); }
public byte[] getPassword() { return password.getValue().getBytes(Charset.forName("UTF-8")); }
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); } }
private void hidePass() { loginBox.setVisible(false); loginInfo.setVisible(false); loginField.setValue(""); vbox.removeStyleName("fuzzy"); }
protected Panel createPasswordFieldPanel(ConfigurationParameter parameter, Validator validator) { Panel paramPanel = new Panel(); paramPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); paramPanel.setWidth("100%"); GridLayout paramLayout = new GridLayout(2, 3); paramLayout.setSpacing(true); paramLayout.setSizeFull(); paramLayout.setMargin(true); paramLayout.setColumnExpandRatio(0, .25f); paramLayout.setColumnExpandRatio(1, .75f); Label label = new Label(parameter.getName()); label.setIcon(VaadinIcons.COG); label.addStyleName(ValoTheme.LABEL_LARGE); label.addStyleName(ValoTheme.LABEL_BOLD); label.setSizeUndefined(); paramLayout.addComponent(label, 0, 0, 1, 0); paramLayout.setComponentAlignment(label, Alignment.TOP_LEFT); logger.info(parameter.getName() + " " + parameter.getValue()); Label valueLabel = new Label("Value:"); valueLabel.setSizeUndefined(); passwordField = new PasswordField(); passwordField.addValidator(validator); passwordField.setNullSettingAllowed(true); passwordField.setNullRepresentation(""); passwordField.setValidationVisible(false); passwordField.setWidth("80%"); passwordField.setId(parameter.getName()); if (parameter instanceof ConfigurationParameterIntegerImpl) { StringToIntegerConverter plainIntegerConverter = new StringToIntegerConverter() { protected java.text.NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; }; }; // either set for the field or in your field factory for multiple fields passwordField.setConverter(plainIntegerConverter); } else if (parameter instanceof ConfigurationParameterLongImpl) { StringToLongConverter plainLongConverter = new StringToLongConverter() { protected java.text.NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; }; }; // either set for the field or in your field factory for multiple fields passwordField.setConverter(plainLongConverter); } BeanItem<ConfigurationParameter> parameterItem = new BeanItem<ConfigurationParameter>(parameter); if (parameter.getValue() != null) { passwordField.setPropertyDataSource(parameterItem.getItemProperty("value")); } paramLayout.addComponent(valueLabel, 0, 1); paramLayout.addComponent(passwordField, 1, 1); paramLayout.setComponentAlignment(valueLabel, Alignment.TOP_RIGHT); paramPanel.setContent(paramLayout); return paramPanel; }
@Override public void init() { inputUserName = new TextField("Nama Untuk Log In"); inputUserName.setDescription("Nama yang digunakan untuk log in"); inputUserName.setImmediate(true); inputUserName.setWidth(function.FORM_WIDTH); inputUserName.setMaxLength(10); inputUserName.addValueChangeListener(this); inputName = new TextField("Nama Lengkap"); inputName.setDescription("Nama lengkap pengguna"); inputName.setImmediate(true); inputName.addValueChangeListener(this); inputName.setWidth(function.FORM_WIDTH); selectRole = new ComboBox("Role Pengguna"); selectRole.setImmediate(true); selectRole.setDescription("Role dari pengguna"); selectRole.addValueChangeListener(this); selectRole.setWidth(function.FORM_WIDTH); selectRole.setNullSelectionAllowed(false); inputEmployeeNum = new TextField("Nomor pegawai"); inputEmployeeNum.setDescription("Nomor pegawai"); inputEmployeeNum.addValueChangeListener(this); inputEmployeeNum.setImmediate(true); inputEmployeeNum.setWidth(function.FORM_WIDTH); inputTitle = new TextField("Jabatan"); inputTitle.setDescription("Jabatan dari pengguna"); inputTitle.addValueChangeListener(this); inputTitle.setImmediate(true); inputTitle.setWidth(function.FORM_WIDTH); inputPhoneNumber = new TextField("Nomor Telepon"); inputPhoneNumber.setDescription("Nomor Telepon yang bisa dihubungi"); inputPhoneNumber.setImmediate(true); inputPhoneNumber.addValueChangeListener(this); inputPhoneNumber.setWidth(function.FORM_WIDTH); inputAddress = new TextArea("Alamat"); inputAddress.setDescription("Alamat pengguna"); inputAddress.addValueChangeListener(this); inputAddress.setImmediate(true); inputAddress.setWidth(function.FORM_WIDTH); inputPassword1 = new PasswordField("Password"); inputPassword1.setDescription("Masukan password untuk pengguna"); inputPassword1.addValueChangeListener(this); inputPassword1.setImmediate(true); inputPassword1.setWidth(function.FORM_WIDTH); inputPassword2 = new PasswordField("Ulangi Password"); inputPassword2.setDescription("Masukan password untuk pengguna"); inputPassword2.addValueChangeListener(this); inputPassword2.setImmediate(true); inputPassword2.setWidth(function.FORM_WIDTH); inputSika = new TextField("SIKA"); inputSika.setDescription("Masukan nomor SIKA"); inputSika.addValueChangeListener(this); inputSika.setImmediate(true); inputSika.setWidth(function.FORM_WIDTH); labelError = new Label() { { setVisible(false); addStyleName("form-error"); setContentMode(ContentMode.HTML); } }; buttonSubmit = new Button("Simpan"); buttonSubmit.addClickListener(this); buttonSaveEdit = new Button("Simpan Perubahan"); buttonSaveEdit.addClickListener(this); buttonReset = new Button("Reset Form"); buttonReset.addClickListener(this); buttonCancel = new Button("Batalkan"); buttonCancel.addClickListener(this); buttonActivation = new Button(""); buttonActivation.addClickListener(this); buttonResetPassword = new Button("Reset Password"); buttonResetPassword.addClickListener(this); construct(); }