Package br.com.caelum.vraptor.musicjungle.model

Examples of br.com.caelum.vraptor.musicjungle.model.User


     * This method adds a music to a user's collection.
     */
    @Path("/users/{user.login}/musics/{music.id}")
    @Put
  public void addToMyList(final User user, final Music music) {
      final User sessionUser = refreshUser();
     
      validator.check(user.getLogin().equals(sessionUser.getLogin()),
              new ValidationMessage("user", "you_cant_add_to_others_list"));

      validator.check(!sessionUser.getMusics().contains(music),
              new ValidationMessage("music", "you_already_have_this_music"));

    validator.onErrorUsePageOf(UsersController.class).home();

    musicDao.add(new MusicOwner(user, music));
View Full Code Here


    /*
     * Refreshes user data from database
     */
    private User refreshUser() {
        User user = userInfo.getUser();
    userDao.refresh(user);
        return user;
    }
View Full Code Here

   */
  @Post
  @Public
  public void login(String login, String password) {
    // search for the user in the database
    final User currentUser = dao.find(login, password);

    // if no user is found, adds an error message to the validator
    // "invalid_login_or_password" is the message key from messages.properties,
    // and that key is used with the fmt taglib in index.jsp, for example: <fmt:message key="error.key">
    validator.check(currentUser != null, new ValidationMessage("login", "invalid_login_or_password"));
View Full Code Here

  }

  @Override
  public User find(String login, String password) {
    try {
      User user = entityManager
        .createQuery("select u from User u where u.login = :login and u.password = :password", User.class)
          .setParameter("login", login)
          .setParameter("password", password)
          .getSingleResult();
      return user;
View Full Code Here

   * Intercepts the request and checks if there is a user logged in.
   */
  @AroundCall
  public void intercept(SimpleInterceptorStack stack) {

    User current = null;
    try {
      current = dao.refresh(info.getUser());
    } catch (Exception e) {
      // could happen if the user does not exist in the database or if there's no user logged in.
    }
View Full Code Here

  }

  @Override
  public User find(String login, String password) {
    try {
      User user = entityManager
        .createQuery("select u from User u where u.login = :login and u.password = :password", User.class)
          .setParameter("login", login)
          .setParameter("password", password)
          .getSingleResult();
      return user;
View Full Code Here

   */
  @Post
  @Public
  public void login(String login, String password) {
    // search for the user in the database
    final User currentUser = dao.find(login, password);

    // if no user is found, adds an error message to the validator
    // "invalid_login_or_password" is the message key from messages.properties,
    // and that key is used with the fmt taglib in index.jsp, for example: <fmt:message key="error.key">
    validator.check(currentUser != null, new SimpleMessage("login", "invalid_login_or_password"));
View Full Code Here

     * This method adds a music to a user's collection.
     */
    @Path("/users/{user.login}/musics/{music.id}")
    @Put
  public void addToMyList(User user, Music music) {
      User currentUser = userInfo.getUser();
      userDao.refresh(currentUser);
     
      validator.check(user.getLogin().equals(currentUser.getLogin()),
              new SimpleMessage("user", "you_cant_add_to_others_list"));

      validator.check(!currentUser.getMusics().contains(music),
              new SimpleMessage("music", "you_already_have_this_music"));

    validator.onErrorUsePageOf(UsersController.class).home();

    music = musicDao.load(music);
    currentUser.add(music);
   
    result.redirectTo(UsersController.class).home();
  }
View Full Code Here

   * Intercepts the request and checks if there is a user logged in.
   */
  @AroundCall
  public void intercept(SimpleInterceptorStack stack) {

    User current = info.getUser();
    try {
      dao.refresh(current);
    } catch (Exception e) {
      // could happen if the user does not exist in the database or if there's no user logged in.
    }
View Full Code Here

  public void add(final @NotNull @Valid Music music, UploadedFile file) {
    validator.onErrorForwardTo(UsersController.class).home();

    musicDao.add(music);
   
    User currentUser = userInfo.getUser();
    userDao.refresh(currentUser);
   
    currentUser.add(music);
   
    // is there a file?
    if (file != null) {
        // Let's save the file
      musics.save(file, music);
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.musicjungle.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.