use of org.traccar.model.User in project traccar by tananaev.
the class NotificatorSms method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) throws MessageException, InterruptedException {
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().sendMessageSync(user.getPhone(), shortMessage.getBody(), false);
}
}
use of org.traccar.model.User 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.model.User in project traccar by tananaev.
the class UserResource method add.
@Override
@PermitAll
@POST
public Response add(User entity) throws StorageException {
if (!Context.getPermissionsManager().getUserAdmin(getUserId())) {
Context.getPermissionsManager().checkUserUpdate(getUserId(), new User(), entity);
if (Context.getPermissionsManager().getUserManager(getUserId())) {
Context.getPermissionsManager().checkUserLimit(getUserId());
} else {
Context.getPermissionsManager().checkRegistration(getUserId());
entity.setDeviceLimit(Context.getConfig().getInteger(Keys.USERS_DEFAULT_DEVICE_LIMIT));
int expirationDays = Context.getConfig().getInteger(Keys.USERS_DEFAULT_EXPIRATION_DAYS);
if (expirationDays > 0) {
entity.setExpirationTime(new Date(System.currentTimeMillis() + (long) expirationDays * 24 * 3600 * 1000));
}
}
}
Context.getUsersManager().addItem(entity);
LogAction.create(getUserId(), entity);
if (Context.getPermissionsManager().getUserManager(getUserId())) {
Context.getDataManager().linkObject(User.class, getUserId(), ManagedUser.class, entity.getId(), true);
LogAction.link(getUserId(), User.class, getUserId(), ManagedUser.class, entity.getId());
}
Context.getUsersManager().refreshUserItems();
return Response.ok(entity).build();
}
use of org.traccar.model.User in project traccar by tananaev.
the class UsersManager method removeCachedItem.
@Override
protected void removeCachedItem(long userId) {
User cachedUser = getById(userId);
if (cachedUser != null) {
String userToken = cachedUser.getToken();
super.removeCachedItem(userId);
if (userToken != null) {
usersTokens.remove(userToken);
}
}
}
use of org.traccar.model.User in project traccar by tananaev.
the class DataManager method login.
public User login(String email, String password) throws StorageException {
User user = storage.getObject(User.class, new Request(new Columns.Include("id", "login", "hashedPassword", "salt"), new Condition.Or(new Condition.Equals("email", "email", email.trim()), new Condition.Equals("login", "email"))));
LdapProvider ldapProvider = Context.getLdapProvider();
if (user != null) {
if (ldapProvider != null && user.getLogin() != null && ldapProvider.login(user.getLogin(), password) || !forceLdap && user.isPasswordValid(password)) {
return user;
}
} else {
if (ldapProvider != null && ldapProvider.login(email, password)) {
user = ldapProvider.getUser(email);
Context.getUsersManager().addItem(user);
return user;
}
}
return null;
}
Aggregations