コード例 #1
0
ファイル: Login.java プロジェクト: youtestit/youtestit
 /**
  * Check if user is authorized.
  *
  * @param user the user to check
  * @return true, if successful
  */
 protected boolean authorizeUser(User user) {
   boolean authorize = true;
   if (user == null) {
     messages.error(new YoutestitMSG("error.login.user.not.exists"));
     authorize = false;
   } else if (!user.isEnable()) {
     messages.error(new YoutestitMSG("error.login.user.not.enable"));
     authorize = false;
   } else if (user.getProfile() != null && !user.getProfile().isEnable()) {
     messages.error(new YoutestitMSG("error.login.profile.not.enable"));
     authorize = false;
   }
   return authorize;
 }
コード例 #2
0
 /**
  * This method just shows another approach to adding a status message.
  *
  * <p>Invoked by:
  *
  * <p>
  *
  * <pre>
  * &lt;f:event type="preRenderView" listener="#{register.notifyIfDeletingIsInvalid}"/>
  * </pre>
  */
 public void notifyIfDeletingIsInvalid() {
   if (facesContext.isValidationFailed()) {
     messages
         .warn(new DefaultBundleKey("receipt_invalid"))
         .defaults("Invalid receipt. Please correct the errors and try again.");
   }
 }
コード例 #3
0
 /**
  * This method just shows another approach to adding a status message.
  *
  * <p>Invoked by:
  *
  * <p>
  *
  * <pre>
  * &lt;f:event type="preRenderView" listener="#{register.notifyIfRegistrationIsInvalid}"/>
  * </pre>
  */
 public void notifyIfRegistrationIsInvalid() {
   if (facesContext.isValidationFailed() || registrationInvalid) {
     messages
         .warn(new DefaultBundleKey("magazzino_invalid"))
         .defaults("Invalid jar. Please correct the errors and try again.");
   }
 }
コード例 #4
0
 public void onBookingComplete(
     @Observes(during = TransactionPhase.AFTER_SUCCESS) @Confirmed final Booking booking) {
   log.bookingConfirmed(booking.getHotel().getName(), booking.getUser().getName());
   messages
       .info(new DefaultBundleKey("booking_confirmed"))
       .defaults("You're booked to stay at the {0} {1}.")
       .params(
           booking.getHotel().getName(), new PrettyTime(locale).format(booking.getCheckinDate()));
 }
コード例 #5
0
  public void delete(Receipt receipt) {
    Receipt oldReceipt;
    if ((oldReceipt = verifyNumberIsAvailable(receipt)) != null) {
      em.remove(oldReceipt);
      receiptSearch.currentPage();
    }

    messages
        .info(new DefaultBundleKey("receipt_deleted"))
        .defaults("You have been successfully deleted the receipt {0}!")
        .params(receipt.getCodeReceipt());
  }
コード例 #6
0
  public void bookHotel() {
    booking = new Booking(hotelSelection, user, 7, 2);
    hotelSelection = null;

    // for demo convenience
    booking.setCreditCardNumber("1111222233334444");
    log.bookingInitiated(user.getName(), booking.getHotel().getName());

    messages
        .info(new DefaultBundleKey("booking_initiated"))
        .defaults("You've initiated a booking at the {0}.")
        .params(booking.getHotel().getName());
  }
コード例 #7
0
 @Override
 @SuppressWarnings("unchecked")
 public void validate(final FacesContext context, final UIComponent comp, final Object value) {
   Map<String, UIComponent> fields = (Map<String, UIComponent>) value;
   if ((password1 != null) && (password2 != null)) {
     if (!password1.equals(password2)) {
       for (UIComponent c : fields.values()) {
         messages.error("Passwords must match").targets(c.getClientId());
       }
       throw new ValidatorException(new FacesMessage("Please correct the errors below."));
     }
   }
 }
コード例 #8
0
  private boolean verifyNumberIsAvailable() {
    Magazzino existing = em.find(Magazzino.class, newJar.getCodeJar());
    if (existing != null) {
      messages
          .warn(new BundleKey("messages", "account_numberTaken"))
          .defaults("The number '{0}' is already taken. Please choose another number.")
          .targets(numberInput.getClientId())
          .params(newJar.getCodeJar());
      log.jarAvailable(existing.getCodeJar() + "", existing != null);
      return false;
    }

    return true;
  }
コード例 #9
0
ファイル: Login.java プロジェクト: youtestit/youtestit
  /**
   * Authenticate jpa.
   *
   * @throws ClientException the client exception
   */
  protected void authenticateJPA() throws ClientException {
    User user = userDAO.getUserByLogin(credentials.getUsername());
    boolean hasNoError = true;

    hasNoError = authorizeUser(user);

    String password = null;
    if (hasNoError) {
      if (credentials != null && credentials.getCredential() instanceof PasswordCredential) {
        password = ((PasswordCredential) credentials.getCredential()).getValue();
      }
      if (password == null) {
        messages.error(new YoutestitMSG("error.login.password.require"));
        hasNoError = false;
      }
    }

    if (hasNoError) {
      final String cryptedPassword = Sha1Encryption.getInstance().encryptToSha1(password);

      if (user.getPassword().equals(cryptedPassword)) {
        loginEventSrc.fire(user);
        setUser(new SimpleUser(user.getLogin()));
        identity.getUser();
      } else {
        messages.error(new YoutestitMSG("error.login.password.wrong"));
        hasNoError = false;
      }
    }

    if (hasNoError) {
      setStatus(AuthenticationStatus.SUCCESS);
    } else {
      setStatus(AuthenticationStatus.FAILURE);
    }
  }
コード例 #10
0
  public void register() {
    if (verifyNumberIsAvailable()) {
      registered = true;
      List<Data> files = newJar.getFiles();
      for (Data file : files) {
        file.setJar(newJar);
        em.persist(file);
      }
      em.persist(newJar);

      messages
          .info(new DefaultBundleKey("magazzino_registered"))
          .defaults("You have been successfully registered as the jar {0}!")
          .params(newJar.getCodeJar());
      log.jarConfirmed(newJar.getCodeJar() + "", newJar.getCodCustomer());
    } else {
      registrationInvalid = true;
    }
  }
コード例 #11
0
 public void disableEditMode() {
   setEditable(false);
   messages.info(new BundleKey("messages", "com.acme.youTask.msg.profile.editDisabled"));
 }
コード例 #12
0
 // -------------- Actions -------------------------------------------------------------
 public void enableEditMode() {
   setEditable(true);
   messages.info(new BundleKey("messages", "com.acme.youTask.msg.profile.editEnabled"));
 }
コード例 #13
0
 public void postAuthenticate(@Observes PostAuthenticateEvent event) {
   messages.info(DEFAULT_LOGIN_SUCCESSFUL_MESSAGE, identity.getUser().getId());
 }