コード例 #1
0
  /**
   * * Adminsitration User edit page
   *
   * @param userId
   * @param request
   * @param response
   * @param model
   * @return
   */
  @RequestMapping(value = "/administration/users/edit/{userId}", method = RequestMethod.GET)
  public ModelAndView EditUser(
      @PathVariable Integer userId,
      @ModelAttribute("viewModel") AdministrationUserEditViewModel viewModel,
      Model model) {
    ModelAndView result = new ModelAndView("administration_user_edit");

    viewModel.setUserId(userId);
    User user = _accountService.getUserByID(userId);
    Userhandle userHandle = _accountService.GetUsrHandleByID(userId);
    if (userHandle != null) {
      viewModel.setFirstName(userHandle.getFirstName());
      viewModel.setLastName(userHandle.getLastName());
      viewModel.setHeight(String.valueOf(userHandle.getHeightIn()));
      viewModel.setGender(userHandle.getGenderName());
      Calendar dob = Calendar.getInstance();
      dob.setTime(userHandle.getDob());
      Calendar today = Calendar.getInstance();
      int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
      viewModel.setAge(age);
      viewModel.setHandedness("Right Handed");
    }

    viewModel.setEmail(user.getEmail());
    viewModel.setPassword(user.getUserpassword());
    viewModel.setAdmin(user.getIsAdmin());

    //	if(hand == 1)
    //		viewModel.setHandedness("Right");
    //	else viewModel.setHandedness("Left");

    model.addAttribute("model", viewModel);
    return result;
  }
コード例 #2
0
  /**
   * Post request to update user. Update email, first, last, password and handId. Does not update
   * birthday or gender. Gender does not exist as a field in the DB and for sake of time Birthday
   * was not completed.
   *
   * @param userId
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/adminsitration/users/update-user", method = RequestMethod.POST)
  public ModelAndView UpdateUser(
      @ModelAttribute("viewModel") AdministrationUserEditViewModel viewModel,
      Model model,
      RedirectAttributes redirectAttributes) {

    ModelAndView result = new ModelAndView("redirect:/administration/users");
    int userID = viewModel.getUserId();

    if (viewModel.getEmail() != null) _accountService.updateUserEmail(userID, viewModel.getEmail());
    if (viewModel.getFirstName() != null)
      _accountService.updateUserHandleFirstName(userID, viewModel.getFirstName());
    if (viewModel.getLastName() != null)
      _accountService.updateUserHandleLastName(userID, viewModel.getLastName());
    if (viewModel.getPassword() != null)
      _accountService.updateUserPassword(userID, viewModel.getPassword());
    if (viewModel.getHandedness() != null)
      _accountService.updateUserHandId(userID, viewModel.getHandedness());

    model.addAttribute("model", viewModel);
    return result;
  }
コード例 #3
0
  /** Lists all of the current users in the system */
  @RequestMapping(value = "/administration/users", method = RequestMethod.GET)
  public ModelAndView ListUsers(
      @ModelAttribute("viewModel") AdministrationUsersViewModel viewModel, Model model) {

    ModelAndView result = new ModelAndView("administration_users");

    // Bad name for AdmistrationUserListViewModel....
    // creates a List of AdmiistrationUserListViewModel objects with custom user fields.
    List<AdministrationUserListViewModel> usersList =
        new ArrayList<AdministrationUserListViewModel>();
    // grabs all users.
    List<User> allUsers = _accountService.GetAllUsers();
    for (User u : allUsers) {
      AdministrationUserListViewModel alvm = new AdministrationUserListViewModel();
      alvm.setEmail(u.getEmail());
      alvm.setIsAdmin(u.getIsAdmin());
      alvm.setLastLogin(new Date());
      alvm.setName("");
      alvm.setUserId(u.getUserId());
      usersList.add(alvm);
    }

    /*for(User U : allUsers){
    	AdministrationUserListViewModel temp = new AdministrationUserListViewModel();
    	Userhandle handle = _accountService.GetUsrHandleByID(U.getUserId());
    	temp.setEmail(U.getEmail());
    	temp.setIsAdmin(U.getIsAdmin());
    	temp.setUserId(U.getUserId());
    	//SET THE USER's LAST LOGINDATE

    	temp.setLastLogin(new Date()); //might have to edit this out...

    	String firstName, lastName;
    	if(handle.getFirstName() == null){firstName = " ";}
    	else firstName = handle.getFirstName();
    	if(handle.getLastName() == null){lastName = " ";}
    	else lastName = handle.getLastName();
    	temp.setName(firstName + " " + lastName);
    	usersList.add(temp);
    }*/

    // pushing all this shit into a userList...
    // view
    viewModel.setUserList(usersList);
    viewModel.setLastAccess(new Date());

    model.addAttribute("model", viewModel);

    return result;
  }
コード例 #4
0
  /** Take Test */
  @RequestMapping(value = "/home/take-test/{testId}", method = RequestMethod.GET)
  public ModelAndView TakeTest(
      @ModelAttribute("viewModel") UserDashboardViewModel viewModel, Model model) {
    ModelAndView result = new ModelAndView("user_dashboard");

    // get the testID
    int testID = viewModel.getTestId();
    Test test = this._testService.GetTestById(testID);
    viewModel.setTest(test);

    // get the words
    List<Attemptword> words = this._attemptWordService.GetAttemptWordsByTestID(testID);
    viewModel.setWords(words);

    // get the userID
    int userId = _accountService.GetUserIDFromCookie();
    viewModel.setUserId(userId);

    model.addAttribute("model", viewModel);
    return result;
  }