Search in sources :

Example 26 with User

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

Example 27 with User

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

Example 28 with User

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();
}
Also used : ManagedUser(org.traccar.model.ManagedUser) User(org.traccar.model.User) Date(java.util.Date) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 29 with User

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

Example 30 with User

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;
}
Also used : Condition(org.traccar.storage.query.Condition) User(org.traccar.model.User) Request(org.traccar.storage.query.Request)

Aggregations

User (org.traccar.model.User)33 PermitAll (javax.annotation.security.PermitAll)11 WebApplicationException (javax.ws.rs.WebApplicationException)7 POST (javax.ws.rs.POST)6 NotificationMessage (org.traccar.notification.NotificationMessage)6 Date (java.util.Date)5 Method (java.lang.reflect.Method)3 Properties (java.util.Properties)3 Session (javax.mail.Session)3 Transport (javax.mail.Transport)3 InternetAddress (javax.mail.internet.InternetAddress)3 MimeMessage (javax.mail.internet.MimeMessage)3 Response (javax.ws.rs.core.Response)3 SecurityContext (javax.ws.rs.core.SecurityContext)3 VelocityContext (org.apache.velocity.VelocityContext)3 StatisticsManager (org.traccar.database.StatisticsManager)3 ManagedUser (org.traccar.model.ManagedUser)3 SQLException (java.sql.SQLException)2 NamingException (javax.naming.NamingException)2 Attribute (javax.naming.directory.Attribute)2