Ejemplo n.º 1
0
  public String sendEmail(String email, String senderEmail) {
    UserDAO userDAO = new UserDAO();
    String name = userDAO.getUser(senderEmail).getName();
    final String username = "******";
    final String password = "******";

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
              }
            });

    try {

      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress("*****@*****.**"));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
      message.setSubject(name + " wants you to join Near!");
      message.setContent(
          "<html><body style='background: #e9eaed;margin: 0px;font-family:helvetica;padding: 10px;'><div style='padding: 20px;text-color: black;background: white;overflow: hidden;border: 2px solid LightGray;'><h2 style='margin: 0px;color: #00bf8f;border-bottom: 3px solid #00bf8f;padding-bottom: 10px;'>Join Near Today</h2><p>Your friend, "
              + name
              + " is using Near, the android app, and thinks you should too!</p><p>Place messages and photos in your location for the community to see. Engage in interesting conversations with nearby peers. Promote your local events.</p><a href='#' style='background: #00bf8f;color: white;text-decoration: none;line-height: 40px;height: 40px;padding: 0px 20px;float:left;'>Accept Invitation</a></div><p style='color: gray;font-size: 10pt;padding: 0px 5px;'>Please do not reply to this email</p></body></html>",
          "text/html; charset=utf-8");

      Transport.send(message);

      System.out.println("Done");
      return "1";

    } catch (MessagingException e) {
      java.util.Date date = new java.util.Date();
      LogDAO.save(new Log(LogDAO.getStringFromException(e), new Timestamp(date.getTime()), 0));
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 2
0
  public GenericEntity<List<com.near.senders.Notification>> getNotifications(int userId) {
    NotificationDAO notificationDAO = new NotificationDAO();
    List<Integer> notificationIds = notificationDAO.getNotifications(userId);
    List<com.near.senders.Notification> notifications =
        new ArrayList<com.near.senders.Notification>();
    for (Integer notificationId : notificationIds) {
      com.near.senders.Notification notification = new com.near.senders.Notification();
      UserDAO userDAO = new UserDAO();
      if (userDAO.getUser(userId).getNotify() == 1) {
        UserProfileDAO userProfileDAO = new UserProfileDAO();

        Notification notificationDB = notificationDAO.getNotification(notificationId);

        notification.setId(notificationDB.getId());
        notification.setNotification(notificationDB.getNotification());
        notification.setNotifierName(userDAO.getUser(notificationDB.getUserId()).getName());
        notification.setNotifierPhoto(
            userProfileDAO.getUserProfile(notificationDB.getRecieverId()).getAvatar());
        notification.setUserId(notificationDB.getUserId());

        String posted = "";
        java.util.Date date = new java.util.Date();
        int days =
            (int)
                ((date.getTime() - notificationDB.getDateNotified().getTime())
                    / (1000 * 60 * 60 * 24));

        if (days == 0) posted += "Today";
        else if (days == 1) posted += "Yesterday";
        else posted += days + " days ago";
        notification.setDateNotified(posted);

        notifications.add(notification);
        notificationDAO.delete(notificationId);
      }
    }
    return new GenericEntity<List<com.near.senders.Notification>>(notifications) {};
  }
Ejemplo n.º 3
0
  public GenericEntity<List<Person>> getPeopleNearMe(int user, int lastId) {
    ArrayList<Person> list = new ArrayList<Person>();

    UserDAO userDAO = new UserDAO();
    List<Integer> users = userDAO.getUserIds();

    UserInfoDAO userInfoDAO = new UserInfoDAO();
    UserInfo userInfo = userInfoDAO.getUserInfo(user);
    int i = 0;
    for (Integer userId : users) {
      if (i < 40) {
        UserInfo otherInfo = userInfoDAO.getUserInfo(userId);
        if ((userId < lastId || lastId == 0) && otherInfo.getCanLocate() == 1) {

          double distance =
              Feed.distance(
                  userInfo.getCurrentLat(),
                  userInfo.getCurrentLng(),
                  otherInfo.getCurrentLat(),
                  otherInfo.getCurrentLng(),
                  'M');

          if (isInsideCircle((long) distance)) {
            UserProfileDAO userProfileDAO = new UserProfileDAO();
            Person person = new Person();
            person.setName(userDAO.getUser(userId).getName());
            person.setDistance((int) distance);
            person.setUserId(userId);
            person.setAvatar(userProfileDAO.getUserProfile(userId).getAvatar());
            list.add(person);
          }
          i++;
        }
      }
    }
    return new GenericEntity<List<Person>>(list) {};
  }