use of org.apache.tapestry5.runtime.Component in project tapestry5-hotel-booking by ccordenier.
the class Book method validateBooking.
@OnEvent(value = EventConstants.VALIDATE, component = "bookingForm")
public void validateBooking() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
if (booking.getCheckinDate().before(calendar.getTime())) {
bookingForm.recordError(messages.get("booking_checkInNotFutureDate"));
return;
} else if (!booking.getCheckinDate().before(booking.getCheckoutDate())) {
bookingForm.recordError(messages.get("booking_checkOutBeforeCheckIn"));
return;
}
userWorkspace.getCurrent().setStatus(true);
}
use of org.apache.tapestry5.runtime.Component in project tapestry5-hotel-booking by ccordenier.
the class View method startBooking.
/**
* Start booking process.
*
* @param hotel
* @return link to the current hotel booking
*/
@OnEvent(value = EventConstants.SUCCESS, component = "startBookingForm")
Object startBooking(Hotel hotel) {
User user = (User) dao.find(User.class, authenticator.getLoggedUser().getId());
userWorkspace.startBooking(hotel, user);
return Book.class;
}
use of org.apache.tapestry5.runtime.Component in project tapestry5-hotel-booking by ccordenier.
the class Signup method proceedSignup.
@OnEvent(value = EventConstants.SUCCESS, component = "RegisterForm")
public Object proceedSignup() {
User userVerif = crudServiceDAO.findUniqueWithNamedQuery(User.BY_USERNAME_OR_EMAIL, QueryParameters.with("username", username).and("email", email).parameters());
if (userVerif != null) {
registerForm.recordError(messages.get("error.userexists"));
return null;
}
User user = new User(fullName, username, email, password);
crudServiceDAO.create(user);
try {
authenticator.login(username, password);
} catch (AuthenticationException ex) {
registerForm.recordError("Authentication process has failed");
return this;
}
return Search.class;
}
use of org.apache.tapestry5.runtime.Component in project tapestry5-hotel-booking by ccordenier.
the class AuthenticationFilter method dispatchedToLoginPage.
private boolean dispatchedToLoginPage(String pageName) throws IOException {
if (authenticator.isLoggedIn()) {
// Logged user should not go back to Signin or Signup
if (signinPage.equalsIgnoreCase(pageName) || signupPage.equalsIgnoreCase(pageName)) {
Link link = renderLinkSource.createPageRenderLink(defaultPage);
response.sendRedirect(link);
return true;
}
return false;
}
Component page = componentSource.getPage(pageName);
if (page.getClass().isAnnotationPresent(AnonymousAccess.class)) {
return false;
}
Link link = renderLinkSource.createPageRenderLink("Signin");
response.sendRedirect(link);
return true;
}
Aggregations