use of org.traccar.notification.NotificationMessage in project traccar by tananaev.
the class NotificatorTelegram method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) {
User user = Context.getPermissionsManager().getUser(userId);
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
TextMessage message = new TextMessage();
message.chatId = user.getString("telegramChatId");
if (message.chatId == null) {
message.chatId = chatId;
}
message.text = shortMessage.getBody();
executeRequest(urlSendText, message);
if (sendLocation && position != null) {
executeRequest(urlSendLocation, createLocationMessage(message.chatId, position));
}
}
use of org.traccar.notification.NotificationMessage in project traccar by tananaev.
the class PasswordResource method reset.
@Path("reset")
@PermitAll
@POST
public Response reset(@FormParam("email") String email) throws StorageException, MessagingException {
for (long userId : Context.getUsersManager().getAllItems()) {
User user = Context.getUsersManager().getById(userId);
if (email.equals(user.getEmail())) {
String token = UUID.randomUUID().toString().replaceAll("-", "");
user.set(PASSWORD_RESET_TOKEN, token);
Context.getUsersManager().updateItem(user);
VelocityContext velocityContext = TextTemplateFormatter.prepareContext(null);
velocityContext.put("token", token);
NotificationMessage fullMessage = TextTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full");
Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody());
break;
}
}
return Response.ok().build();
}
Aggregations