diff options
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
3 files changed, 18 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/api/resource/PasswordResource.java b/src/main/java/org/traccar/api/resource/PasswordResource.java index 91d994153..7df25c264 100644 --- a/src/main/java/org/traccar/api/resource/PasswordResource.java +++ b/src/main/java/org/traccar/api/resource/PasswordResource.java @@ -18,12 +18,14 @@ package org.traccar.api.resource; import org.apache.velocity.VelocityContext; import org.traccar.Context; import org.traccar.api.BaseResource; +import org.traccar.database.MailManager; import org.traccar.model.User; import org.traccar.notification.NotificationMessage; import org.traccar.notification.TextTemplateFormatter; import org.traccar.storage.StorageException; import javax.annotation.security.PermitAll; +import javax.inject.Inject; import javax.mail.MessagingException; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; @@ -41,6 +43,9 @@ public class PasswordResource extends BaseResource { private static final String PASSWORD_RESET_TOKEN = "passwordToken"; + @Inject + private MailManager mailManager; + @Path("reset") @PermitAll @POST @@ -56,7 +61,7 @@ public class PasswordResource extends BaseResource { velocityContext.put("token", token); NotificationMessage fullMessage = TextTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full"); - Context.getMailManager().sendMessage(user, fullMessage.getSubject(), fullMessage.getBody()); + mailManager.sendMessage(user, fullMessage.getSubject(), fullMessage.getBody()); break; } } diff --git a/src/main/java/org/traccar/api/resource/ReportResource.java b/src/main/java/org/traccar/api/resource/ReportResource.java index 3c1b8f715..3955f1d20 100644 --- a/src/main/java/org/traccar/api/resource/ReportResource.java +++ b/src/main/java/org/traccar/api/resource/ReportResource.java @@ -38,8 +38,8 @@ import javax.ws.rs.core.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.traccar.Context; import org.traccar.api.BaseResource; +import org.traccar.database.MailManager; import org.traccar.helper.LogAction; import org.traccar.model.Event; import org.traccar.model.Position; @@ -80,6 +80,9 @@ public class ReportResource extends BaseResource { @Inject private TripsReportProvider tripsReportProvider; + @Inject + private MailManager mailManager; + private interface ReportExecutor { void execute(ByteArrayOutputStream stream) throws StorageException, IOException; } @@ -99,8 +102,7 @@ public class ReportResource extends BaseResource { stream.toByteArray(), "application/octet-stream"))); User user = permissionsService.getUser(userId); - Context.getMailManager().sendMessage( - user, "Report", "The report is in the attachment.", attachment); + mailManager.sendMessage(user, "Report", "The report is in the attachment.", attachment); } catch (StorageException | IOException | MessagingException e) { LOGGER.warn("Report failed", e); } diff --git a/src/main/java/org/traccar/api/resource/ServerResource.java b/src/main/java/org/traccar/api/resource/ServerResource.java index f238e8905..51a26825b 100644 --- a/src/main/java/org/traccar/api/resource/ServerResource.java +++ b/src/main/java/org/traccar/api/resource/ServerResource.java @@ -17,6 +17,7 @@ package org.traccar.api.resource; import org.traccar.Context; import org.traccar.api.BaseResource; +import org.traccar.database.MailManager; import org.traccar.helper.LogAction; import org.traccar.model.Server; import org.traccar.storage.Storage; @@ -46,10 +47,15 @@ public class ServerResource extends BaseResource { @Inject private Storage storage; + @Inject + private MailManager mailManager; + @PermitAll @GET public Server get() throws StorageException { - return storage.getObject(Server.class, new Request(new Columns.All())); + Server server = storage.getObject(Server.class, new Request(new Columns.All())); + server.setEmailEnabled(mailManager.getEmailEnabled()); + return server; } @PUT |