Example #1
0
  @Override
  public String execute(HttpServletRequest request, HttpServletResponse response)
      throws FunctionalException, TechnicalException {
    String username = request.getParameter(BaseConfig.USERNAME);
    String password = request.getParameter(BaseConfig.PASSWORD);

    UserService service;
    if (BaseConfig.USEMOCK) {
      service = UserServiceMock.getInstance();
    } else {
      service = UserServiceImpl.getInstance();
    }

    User user = null;

    user = service.find(username);

    if (user != null && user.getPassword().equals(password)) {

      HttpSession session = request.getSession();
      session.setAttribute(BaseConfig.USERNAME, user.getName());
      Role role = user.getRole();
      session.setAttribute(BaseConfig.ROLE, role);

    } else {
      throw new FunctionalException(Level.WARNING, BaseConfig.INVALID_DATA);
    }

    return BaseConfig.APP_CONTEXT; // Redirect to home page.
  }
  public void DisjoinTeam(Team team) {

    User user;

    user = userService.findByPrincipal();

    team.getUsers().remove(user);
    user.getTeams().remove(team);

    save(team);
    userService.save(user);
  }
  // Sending request------------------------------------------------------------------
  @RequestMapping(value = "/sendRequest", method = RequestMethod.GET)
  public ModelAndView sendRequest(@RequestParam int teamId) {

    ModelAndView result;
    Collection<Team> teams;
    Collection<Team> teamsRequested = new ArrayList<Team>();
    Team team;
    Boolean showSend = true;
    Collection<RequestTeam> requestTeam;
    User principal;

    principal = userService.findByPrincipal();
    team = teamService.findOne(teamId);
    requestTeamService.sendRequest(teamId);
    teams = teamService.findAllOtherUser(principal.getId());
    requestTeam = requestTeamService.findAllRequestSendFromUser(principal.getId());

    for (RequestTeam r : requestTeam) {
      teamsRequested.add(r.getTeam());
    }

    result = new ModelAndView("team/list");

    result.addObject("teams", teams);
    result.addObject("teamsRequested", teamsRequested);
    result.addObject("showSend", showSend);
    result.addObject("requestURI", "team/user/listAllTeams.do");

    return result;
  }
Example #4
0
 public String changePassword() {
   if (newPassword != null) {
     user.setPassword(newPassword);
     userService.editUserPassword(user);
   }
   return "/user/index?faces-redirect=true";
 }
  public Team create() {
    Team team;
    Collection<User> users;
    Collection<Tournament> tournaments;
    Collection<Match> matchs;
    Collection<Match> winners;
    Collection<RequestTeam> requestTeams;
    User captain;

    team = new Team();
    captain = userService.findByPrincipal();
    users = new ArrayList<User>();
    tournaments = new ArrayList<Tournament>();
    matchs = new ArrayList<Match>();
    winners = new ArrayList<Match>();
    requestTeams = new ArrayList<RequestTeam>();

    users.add(captain);

    team.setCaptain(captain);
    team.setUsers(users);
    team.setTournaments(tournaments);
    team.setMatchs(matchs);
    team.setWinners(winners);
    team.setRequests(requestTeams);

    return team;
  }
Example #6
0
 public String updateUser() {
   modifyPosition(this.position);
   this.position = "User";
   userService.editUser(user, originalPosition);
   this.user = new User();
   return "listUser?faces-redirect=true";
 }
Example #7
0
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String username = req.getParameter("username");
    String password = req.getParameter("password");

    Map<String, String> messages = new HashMap<String, String>();
    req.setAttribute("messageMap", messages);

    if (username.isEmpty() || password.isEmpty()) {
      messages.put("fieldIsEmpty", "Fields cannot not be empty");
      req.getRequestDispatcher("login.jsp").forward(req, resp);
    }

    user = userService.getUser(username);

    if (user.getPassword().equals(password)) {
      req.setAttribute("name", username);
      HttpSession session = req.getSession();
      session.setAttribute("username", username);
      req.getRequestDispatcher("index.jsp").forward(req, resp);
    } else {
      messages.put("noUser", "This user is not registered. Please use link below to register!");
      req.getRequestDispatcher("login.jsp").forward(req, resp);
    }
  }
  public Team save(Team team) {
    Team result;
    User principal;

    principal = userService.findByPrincipal();

    result = teamRepository.save(team);

    if (team.getId() == 0) {
      principal.getTeamsCreated().add(result);
      principal.getTeams().add(result);
    }

    userService.save(principal);

    return result;
  }
Example #9
0
 public String selectedToUpdateProfile(String name) {
   this.selectedUser = userService.findByLoginName(name);
   if (selectedUser != null) {
     this.originalPosition = selectedUser.getPosition();
     this.user = selectedUser;
     return "/user/profilePage?faces-redirect=true";
   } else {
     return "?faces-redirect=false";
   }
 }
Example #10
0
  public Collection<Team> findAllTeamsByUserId() {
    Collection<Team> all;
    User user;
    int userId;

    user = userService.findByPrincipal();
    userId = user.getId();
    all = teamRepository.findAllTeamsByUserId(userId);

    return all;
  }
Example #11
0
  public void joinTeam(Team team, RequestTeam requestTeam) {

    User user;

    user = requestTeam.getUser();

    requestTeam.setRequest(true);
    team.getUsers().add(user);
    user.getTeams().add(team);

    requestTeamService.save(requestTeam);
    save(team);
    userService.save(user);
  }
Example #12
0
  public String deleteUser() {
    if (selectedUser != null) {
      if (!"admin".equals(selectedUser.getLoginName())) {
        List<Account> accountList = accountService.getAllByUser(selectedUser);
        for (Account account : accountList) {
          account.setDestroy(true);
          account.setUser(null);
          accountService.updateAccount(account);
        }
        List<Topic> topicList = messageService.findByUser(selectedUser);
        for (Topic topic : topicList) {
          List<Message> messageList = messageService.findByTopic(topic);
          topic.setLastMessage(null);
          messageService.editTopic(topic);
          for (Message message : messageList) {
            message.setSender(null);
            message.setTopic(null);
            messageService.removeMessage(message);
          }
          messageList.clear();
          messageService.removeTopic(topic);
        }

        topicList.clear();

        userService.removeUser(selectedUser);
        selectedUser = new User();
        return "listUser?faces-redirect=true";
      } else {
        FacesContext.getCurrentInstance()
            .addMessage(
                null,
                new FacesMessage(
                    FacesMessage.SEVERITY_INFO,
                    "Deleting error",
                    "This user has leaded projects or you tried to delete admin! >> nice try! "));
        return "listUser?faces-redirect=false";
      }
    } else {
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_INFO,
                  "User has not selected",
                  "You did not select any user!"));
      return "listUser?faces-redirect=false";
    }
  }
  // Listing------------------------------------------------------------------
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  public ModelAndView list() {

    ModelAndView result;
    Collection<RequestTeam> requestTeams;
    User principal;

    principal = userService.findByPrincipal();
    requestTeams = requestTeamService.findAllRequestTeamUser(principal.getId());

    result = new ModelAndView("requestTeam/list");

    result.addObject("requestTeams", requestTeams);
    result.addObject("requestURI", "requestTeam/user/list.do");

    return result;
  }
Example #14
0
  public String selectedToAccountList() {
    if (selectedUser != null) {
      this.user = selectedUser;
      selectedUser = new User();
      accountList = userService.getAccountList(user);
      return "/admin/user/account/listUserAccount?faces-redirect=true";
    } else {
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_INFO,
                  "Felhasználó nincs kiválasztva",
                  "Felhasználó nincs kiválasztva"));

      return "/admin/user/account/listUser?faces-redirect=false";
    }
  }
Example #15
0
  public void delete(Team team) {

    User captain;

    captain = team.getCaptain();

    for (Tournament t : team.getTournaments()) {
      Assert.isTrue(t.getFinishMoment().before(new Date()));
    }

    captain.getTeams().remove(team);
    captain.getTeamsCreated().remove(team);

    Assert.notNull(team);
    checkPrincipal(team);
    teamRepository.delete(team);

    userService.save(captain);
  }
Example #16
0
  public String acceptRegister() {
    boolean isAccept = userService.acceptRegister(selectedRegUser);
    this.selectedRegUser = new RegistratedUser();

    if (isAccept) {
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_INFO, "Felhasználó regisztrálása sikeres volt!", ""));
      return "registrate?faces-redirect=true";
    } else {
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_INFO,
                  "Felhasználó regisztrálása helytelen adatok miatt sikertelen volt!",
                  ""));
      return "registrate?faces-redirect=true";
    }
  }
Example #17
0
 public String registerUser() {
   regUser.setPosition(Role.USER);
   userService.register(regUser);
   regUser = new RegistratedUser();
   return "login?faces-redirect=true";
 }
Example #18
0
 public String updateProfileUser() throws NoSuchAlgorithmException {
   userService.editUser(user, originalPosition);
   this.user = new User();
   return "/user/index?faces-redirect=true";
 }
Example #19
0
 public String refuseRegister() {
   userService.refuseRegister(selectedRegUser, message);
   this.selectedRegUser = new RegistratedUser();
   this.message = new String();
   return "registrate?faces-redirect=true";
 }
Example #20
0
 private void addUser() {
   user.setPosition(Role.USER);
   userService.addUser(user);
   this.user = new User();
 }
 public Result index() {
   userService.addUser(new User("Saeed", "Zarinfam", "zarin"));
   return ok("insert user saeed successfully!");
 }
Example #22
0
 public void checkPrincipal(Team team) {
   Assert.isTrue(team.getCaptain().equals(userService.findByPrincipal()));
 }