コード例 #1
0
  @RequestMapping(
      value = "/sendmessage",
      method = RequestMethod.POST,
      produces = "application/json")
  @ResponseBody
  public Map<String, Object> sendMessages(
      Principal principal, @RequestBody Map<String, Object> data) {

    String text = (String) data.get("text");
    String name = (String) data.get("name");
    String email = (String) data.get("email");
    // String username= (String)data.get("username");
    User msgSender = usersService.getUserByEmail(email);
    String username = msgSender.getUsername();

    //	Integer target=	(Integer)data.get("target");

    Message message = new Message();
    message.setName(principal.getName()); // siuntejo
    message.setUsername(username); // Gavejo
    message.setEmail(email);
    message.setContent(text);
    message.setSubject("Reply from: " + name);

    System.out.println(name + " " + email + " " + text);

    SimpleMailMessage mail = new SimpleMailMessage();
    mail.setFrom("*****@*****.**");
    mail.setTo(email);
    mail.setSubject("Reply from: " + name);
    mail.setText(text);

    usersService.sendMessage(message);

    try {
      mailSender.send(mail);
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Cant send");
    }

    Map<String, Object> reply = new HashMap<String, Object>();
    reply.put("success", true);
    //	reply.put("target", target);

    return reply;
  }
コード例 #2
0
  @RequestMapping("/acccreated")
  public String showAccCreated(@Valid User user, BindingResult result) {
    // System.out.println(offer);

    if (result.hasErrors()) {
      return "createacc";
    }

    user.setAuthority("ROLE_USER");
    user.setEnabled(true);

    if (usersService.exists(user.getUsername())) {
      System.out.println("Duplicate");
      result.rejectValue("username", "DuplicateKey.user.username");
      return "createacc";
    }

    usersService.create(user);
    return "acccreated";
  }