@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; }
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; }
public String updateUser() { modifyPosition(this.position); this.position = "User"; userService.editUser(user, originalPosition); this.user = new User(); return "listUser?faces-redirect=true"; }
@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; }
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"; } }
public Collection<Team> findAllTeamsByUserId() { Collection<Team> all; User user; int userId; user = userService.findByPrincipal(); userId = user.getId(); all = teamRepository.findAllTeamsByUserId(userId); return all; }
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); }
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; }
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"; } }
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); }
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"; } }
public String registerUser() { regUser.setPosition(Role.USER); userService.register(regUser); regUser = new RegistratedUser(); return "login?faces-redirect=true"; }
public String updateProfileUser() throws NoSuchAlgorithmException { userService.editUser(user, originalPosition); this.user = new User(); return "/user/index?faces-redirect=true"; }
public String refuseRegister() { userService.refuseRegister(selectedRegUser, message); this.selectedRegUser = new RegistratedUser(); this.message = new String(); return "registrate?faces-redirect=true"; }
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!"); }
public void checkPrincipal(Team team) { Assert.isTrue(team.getCaptain().equals(userService.findByPrincipal())); }