Search in sources :

Example 1 with Mail

use of email.Mail in project common by zenlunatics.

the class Site method mailPassword.

// --------------------------------------------------------------------------
public boolean mailPassword(String user_name, Request request) {
    if (user_name == null)
        return false;
    int id = request.db.lookupInt(new Select("id").from("people").where("user_name='" + DBConnection.escape(user_name) + "'"), -1);
    if (id == -1)
        return false;
    String email = request.db.lookupString(new Select("email").from("people").whereIdEquals(id));
    if (email == null)
        return false;
    String password = UUID.randomUUID().toString();
    request.db.update("people", "password=md5('" + DBConnection.escape(password) + "')", id);
    StringBuilder message = new StringBuilder("Hello,\n\n").append("Your password for the ").append(getDisplayName()).append(" web site has been reset and is now \"").append(password).append("\". The double quotes are not part of the password. Copy the password, being sure not to select the double quotes, then log into the site by entering your username and pasting the password into the password field. After you log in, change your password by clicking on the popup menu with your name in the upper right and selecting Settings.");
    new Mail(this).send(email, getDisplayName() + " Website Account", message.toString(), false);
    return true;
}
Also used : Mail(email.Mail) FilePathStringBuilder(web.FilePathStringBuilder) Select(db.Select)

Example 2 with Mail

use of email.Mail in project common by zenlunatics.

the class EventProvider method sendReminders.

// --------------------------------------------------------------------------
@AdminTask({ "nightly" })
public void sendReminders(LocalDateTime now, boolean nightly, Site site, DBConnection db) {
    Mail mail = new Mail(site);
    ArrayList<Integer> delete_ids = new ArrayList<Integer>();
    String reminders_table = m_events_table + "_reminders";
    try {
        StringBuilder columns = new StringBuilder();
        columns.append(m_events_table).append(".id,").append(reminders_table).append(".id AS reminder_id,").append(m_events_table).append("_id,last_sent,note,email,num,unit,before,date,notes");
        if (m_events_have_event)
            columns.append(",event");
        if (m_events_can_repeat)
            columns.append(",repeat,end_date,repeat_days");
        if (m_events_have_start_time)
            columns.append(",start_time,end_time");
        if (m_events_are_owned)
            columns.append(",").append(m_events_table).append("._owner_");
        Select query = new Select(columns.toString()).from(m_events_table).joinOn(reminders_table, "(" + m_events_table + ".id=" + reminders_table + "." + m_events_table + "_id OR " + reminders_table + "." + m_events_table + "_id IS NULL)").where(nightly ? "(unit='day' OR unit='week')" : "(unit='hour' OR unit='minute')");
        andFilters(query);
        ResultSet rs = db.select(query);
        Calendar calendar = site.newCalendar();
        while (rs.next()) {
            int num = rs.getInt("num");
            String unit = rs.getString("unit");
            boolean before = rs.getBoolean("before");
            int num_days = numDays(num, unit, before);
            LocalDate reminder_date = site.newLocalDate().minusDays(num_days);
            Event event = new Event(this, calendar, null);
            event.load(rs, site);
            if (event.hasEndedBy(reminder_date)) {
                int id = rs.getInt(3);
                if (!rs.wasNull())
                    delete_ids.add(id);
            } else {
                boolean occurs_on = false;
                boolean last_event = false;
                if (m_events_can_repeat) {
                    String repeat_days = rs.getString("repeat_days");
                    if ("first event".equals(repeat_days))
                        occurs_on = reminder_date.isEqual(rs.getDate("date").toLocalDate());
                    else if ("last event".equals(repeat_days)) {
                        occurs_on = reminder_date.isEqual(rs.getDate("end_date").toLocalDate());
                        last_event = true;
                    } else
                        occurs_on = event.occursOn(reminder_date);
                } else
                    occurs_on = event.occursOn(reminder_date);
                if (occurs_on) {
                    Date last_sent = rs.getDate("last_sent");
                    if (last_sent == null || !last_sent.toLocalDate().equals(now.toLocalDate())) {
                        if (m_events_have_start_time && (unit.equals("hour") || unit.equals("minute"))) {
                            LocalTime time = before ? rs.getTime("start_time").toLocalTime() : rs.getTime("end_time").toLocalTime();
                            if (unit.equals("hour"))
                                if (before)
                                    time = time.minusHours(num);
                                else
                                    time = time.plusHours(num);
                            else if (before)
                                time = time.minusMinutes(num);
                            else
                                time = time.plusMinutes(num);
                            if (now.toLocalTime().isBefore(time))
                                continue;
                        }
                        String recipient = rs.getString("email");
                        sendReminder(mail, recipient, event, rs.getString("note"), reminder_date, num_days, last_event, site, db);
                        if (!event.isRepeating()) {
                            int id = rs.getInt(3);
                            if (!rs.wasNull()) {
                                delete_ids.add(id);
                                continue;
                            }
                        }
                        db.update(reminders_table, new NameValuePairs().setDate("last_sent", now.toLocalDate()), rs.getInt("reminder_id"));
                    }
                }
            }
        }
        rs.getStatement().close();
    } catch (Exception e) {
        System.out.println("EventProvider.sendReminders");
        e.printStackTrace(System.out);
    }
    for (Integer id : delete_ids) db.deleteById(reminders_table, id);
}
Also used : FilePathStringBuilder(web.FilePathStringBuilder) LocalTime(java.time.LocalTime) NameValuePairs(db.NameValuePairs) Calendar(java.util.Calendar) ICalendar(biweekly.ICalendar) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) LocalDate(java.time.LocalDate) Date(java.sql.Date) SQLException(java.sql.SQLException) IOException(java.io.IOException) Mail(email.Mail) Select(db.Select) ResultSet(java.sql.ResultSet) VEvent(biweekly.component.VEvent) AdminTask(web.AdminTask)

Aggregations

Select (db.Select)2 Mail (email.Mail)2 FilePathStringBuilder (web.FilePathStringBuilder)2 ICalendar (biweekly.ICalendar)1 VEvent (biweekly.component.VEvent)1 NameValuePairs (db.NameValuePairs)1 IOException (java.io.IOException)1 Date (java.sql.Date)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 LocalDate (java.time.LocalDate)1 LocalTime (java.time.LocalTime)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 AdminTask (web.AdminTask)1