Search in sources :

Example 6 with NotificationMessage

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));
    }
}
Also used : User(org.traccar.model.User) NotificationMessage(org.traccar.notification.NotificationMessage)

Example 7 with NotificationMessage

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();
}
Also used : User(org.traccar.model.User) NotificationMessage(org.traccar.notification.NotificationMessage) VelocityContext(org.apache.velocity.VelocityContext) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Aggregations

NotificationMessage (org.traccar.notification.NotificationMessage)7 User (org.traccar.model.User)6 StatisticsManager (org.traccar.database.StatisticsManager)2 PermitAll (javax.annotation.security.PermitAll)1 MessagingException (javax.mail.MessagingException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 VelocityContext (org.apache.velocity.VelocityContext)1 MessageException (org.traccar.notification.MessageException)1