diff --git a/.idea/libraries/activation_1_1_1.xml b/.idea/libraries/activation_1_1_1.xml new file mode 100644 index 0000000..79e88f2 --- /dev/null +++ b/.idea/libraries/activation_1_1_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/commons_email_1_4.xml b/.idea/libraries/commons_email_1_4.xml new file mode 100644 index 0000000..9dd524d --- /dev/null +++ b/.idea/libraries/commons_email_1_4.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/javax_mail_1_5_2.xml b/.idea/libraries/javax_mail_1_5_2.xml new file mode 100644 index 0000000..de8bd30 --- /dev/null +++ b/.idea/libraries/javax_mail_1_5_2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/cecs343.iml b/cecs343.iml index 973b2cb..1097d3c 100644 --- a/cecs343.iml +++ b/cecs343.iml @@ -17,5 +17,8 @@ + + + \ No newline at end of file diff --git a/src/ChangeCancelAppointment.kt b/src/ChangeCancelAppointment.kt index 46f380c..f11deea 100644 --- a/src/ChangeCancelAppointment.kt +++ b/src/ChangeCancelAppointment.kt @@ -218,7 +218,7 @@ object ChangeCancelAppointment { hBox.children.addAll(modify, back,cancel ) gridPane.add(hBox, 0, 2) - return Scene(gridPane, 350.0, 325.0) + return Scene(gridPane, 350.0, 375.0) } // Window shown verifying changes to Appointment diff --git a/src/FileExplorer.kt b/src/FileExplorer.kt index 766b6bd..6f355fb 100644 --- a/src/FileExplorer.kt +++ b/src/FileExplorer.kt @@ -46,7 +46,9 @@ object FileExplorer { val idResult = idStatement.executeQuery(checkForExistingAppt(it.id)) // Modify if the ID already exists, else create a new one - if (idResult.next()) { + idResult.next() + val count = idResult.getInt(1) + if (count > 0) { val titleStatement = connection.createStatement() val startStatement = connection.createStatement() val endStatement = connection.createStatement() @@ -60,6 +62,7 @@ object FileExplorer { creationStatement.executeUpdate(createAppointment(it.title, it.startDate, it.endDate, account.id, aptID, null)) } } + ChangeCancelAppointment.updateComboBox() } // Appointment reminders aren't saved diff --git a/src/MakeAppointment.kt b/src/MakeAppointment.kt index 6f774b2..f2d63ba 100644 --- a/src/MakeAppointment.kt +++ b/src/MakeAppointment.kt @@ -110,7 +110,7 @@ object MakeAppointment { hBox.children.addAll(register, back) gridPane.add(hBox, 0, 2) - return Scene(gridPane, 350.0, 250.0) + return Scene(gridPane, 350.0, 300.0) } // Window shown when changing Appointment Creation has failed diff --git a/src/Registrar.kt b/src/Registrar.kt index ac539b6..76d29f4 100644 --- a/src/Registrar.kt +++ b/src/Registrar.kt @@ -170,6 +170,7 @@ object Registrar { status = RegistrationStatus.SUCCESS try { successStatement.executeUpdate(createAccount(maxID + 1, pendingUser)) + pendingUser.id = maxID + 1 account = pendingUser Welcome.welcomeBanner.text = "Logged in as " + pendingUser.username } catch (e: Exception) { diff --git a/src/Squeal.kt b/src/Squeal.kt index 4d6045d..cf561d8 100644 --- a/src/Squeal.kt +++ b/src/Squeal.kt @@ -1,5 +1,9 @@ import java.time.LocalDateTime + +import org.apache.commons.mail.DefaultAuthenticator +import org.apache.commons.mail.HtmlEmail + // We will be using the user's locally installed database for the purposes // of this assignment. The user should already have a MYSQL database // created with the name "scheduler" @@ -103,16 +107,29 @@ fun removeAppointment(appID: Int): String { //Returns true for email sent //Returns false for email not sent fun sendEmail(emailAddress: String, appointmentName: String, startDate: LocalDateTime, username: String): Boolean{ - - val emailSent = emailAddress == ""//Set to true if email is sent - val emailMSG = " Hello, $username \nYou have a/an $appointmentName @ ${startDate.toLocalDate()} ${startDate.toLocalTime()} "//Message String + val emailMSG = " Hello, $username ($emailAddress). \nYou have an appointment: '$appointmentName' @ ${startDate.toLocalDate()} ${startDate.toLocalTime()} "//Message String println(emailMSG) - - //TODO actually send message emailMSG and update emailSent - - - - return emailSent + return true + + val senderEmail = "diego@sn.gy" + val password = "#passsword" + return try { + val email = HtmlEmail() + email.hostName = "smtp.googlemail.com" + email.setSmtpPort(465) + email.setAuthenticator(DefaultAuthenticator(senderEmail, password)) + email.isSSLOnConnect = true + email.setFrom(senderEmail) + email.addTo(emailAddress) + email.subject = "You have an Appointment coming up" + email.setHtmlMsg("

$emailMSG

") + email.send() + + true + } catch (ex: Exception) { + ex.printStackTrace() + false + } } // Change the reminder for this appointment diff --git a/src/Welcome.kt b/src/Welcome.kt index cbab3d9..9a57d18 100644 --- a/src/Welcome.kt +++ b/src/Welcome.kt @@ -11,10 +11,12 @@ import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.* import kotlin.concurrent.schedule +import kotlin.math.absoluteValue // Main menu object Welcome { var welcomeBanner = Text() + var appointmentList = mutableListOf() // Stage for many of the menu bar options available val stage = Stage() @@ -157,16 +159,20 @@ object Welcome { timer.schedule(1000, 60000) { val emailStatement = connection.createStatement() val emailResult = emailStatement.executeQuery(getAppointments(account.username)) - var remindersSet = false while (emailResult.next()) { val name = emailResult.getString("title") val start = emailResult.getString("start_date") val reminder = emailResult.getInt("reminder") + val aptID = emailResult.getInt("appointment_id") + val startDate = LocalDateTime.parse(start, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) val now = LocalDateTime.now() - val minutes = Duration.between(startDate, now).toMinutes() - if (minutes < reminder && startDate > now) { - remindersSet = sendEmail(account.email, name, startDate, account.username) + val minutes = Duration.between(startDate, now).toMinutes().absoluteValue + + if (minutes < reminder && startDate > now && !appointmentList.contains(aptID)) { + if (sendEmail(account.email, name, startDate, account.username)) { + appointmentList.add(aptID) + } } } }