use of org.traccar.model.User in project traccar by tananaev.
the class NotificatorFirebase method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) {
final User user = Context.getPermissionsManager().getUser(userId);
if (user.getAttributes().containsKey("notificationTokens")) {
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
Notification notification = new Notification();
notification.title = shortMessage.getSubject();
notification.body = shortMessage.getBody();
notification.sound = "default";
Message message = new Message();
message.tokens = user.getString("notificationTokens").split("[, ]");
message.notification = notification;
Context.getClient().target(url).request().header("Authorization", "key=" + key).async().post(Entity.json(message), new InvocationCallback<Object>() {
@Override
public void completed(Object o) {
}
@Override
public void failed(Throwable throwable) {
LOGGER.warn("Firebase notification error", throwable);
}
});
}
}
use of org.traccar.model.User in project traccar by tananaev.
the class NotificatorSms method sendAsync.
@Override
public void sendAsync(long userId, Event event, Position position) {
final User user = Context.getPermissionsManager().getUser(userId);
if (user.getPhone() != null) {
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
Main.getInjector().getInstance(StatisticsManager.class).registerSms();
Context.getSmsManager().sendMessageAsync(user.getPhone(), shortMessage.getBody(), false);
}
}
use of org.traccar.model.User in project traccar by tananaev.
the class NotificatorPushover method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) {
final User user = Context.getPermissionsManager().getUser(userId);
String device = "";
if (user.getAttributes().containsKey("notificator.pushover.device")) {
device = user.getString("notificator.pushover.device").replaceAll(" *, *", ",");
}
if (token == null) {
LOGGER.warn("Pushover token not found");
return;
}
if (this.user == null) {
LOGGER.warn("Pushover user not found");
return;
}
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
Message message = new Message();
message.token = token;
message.user = this.user;
message.device = device;
message.title = shortMessage.getSubject();
message.message = shortMessage.getBody();
Context.getClient().target(url).request().async().post(Entity.json(message), new InvocationCallback<Object>() {
@Override
public void completed(Object o) {
}
@Override
public void failed(Throwable throwable) {
LOGGER.warn("Pushover API error", throwable);
}
});
}
use of org.traccar.model.User in project traccar by tananaev.
the class NotificationSms method sendSmsSync.
public static void sendSmsSync(long userId, Event event, Position position) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {
User user = Context.getPermissionsManager().getUser(userId);
if (Context.getSmppManager() != null && user.getPhone() != null) {
Context.getStatisticsManager().registerSms();
Context.getSmppManager().sendMessageSync(user.getPhone(), NotificationFormatter.formatSmsMessage(userId, event, position), false);
}
}
use of org.traccar.model.User in project traccar by traccar.
the class SessionResource method get.
@PermitAll
@GET
public User get(@QueryParam("token") String token) throws SQLException, UnsupportedEncodingException {
Long userId = (Long) request.getSession().getAttribute(USER_ID_KEY);
if (userId == null) {
Cookie[] cookies = request.getCookies();
String email = null, password = null;
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(USER_COOKIE_KEY)) {
byte[] emailBytes = DataConverter.parseBase64(URLDecoder.decode(cookie.getValue(), StandardCharsets.US_ASCII.name()));
email = new String(emailBytes, StandardCharsets.UTF_8);
} else if (cookie.getName().equals(PASS_COOKIE_KEY)) {
byte[] passwordBytes = DataConverter.parseBase64(URLDecoder.decode(cookie.getValue(), StandardCharsets.US_ASCII.name()));
password = new String(passwordBytes, StandardCharsets.UTF_8);
}
}
}
if (email != null && password != null) {
User user = Context.getPermissionsManager().login(email, password);
if (user != null) {
userId = user.getId();
request.getSession().setAttribute(USER_ID_KEY, userId);
}
} else if (token != null) {
User user = Context.getUsersManager().getUserByToken(token);
if (user != null) {
userId = user.getId();
request.getSession().setAttribute(USER_ID_KEY, userId);
}
}
}
if (userId != null) {
Context.getPermissionsManager().checkUserEnabled(userId);
return Context.getPermissionsManager().getUser(userId);
} else {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
}
Aggregations