Search in sources :

Example 6 with User

use of org.traccar.model.User in project traccar by tananaev.

the class SessionResource method add.

@PermitAll
@POST
public User add(@FormParam("email") String email, @FormParam("password") String password) throws SQLException {
    User user = Context.getPermissionsManager().login(email, password);
    if (user != null) {
        request.getSession().setAttribute(USER_ID_KEY, user.getId());
        LogAction.login(user.getId());
        return user;
    } else {
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
    }
}
Also used : User(org.traccar.model.User) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 7 with User

use of org.traccar.model.User in project traccar by tananaev.

the class NotificationMail method sendMailSync.

public static void sendMailSync(long userId, Event event, Position position) throws MessagingException {
    User user = Context.getPermissionsManager().getUser(userId);
    Properties properties = null;
    if (!Context.getConfig().getBoolean("mail.smtp.ignoreUserConfig")) {
        properties = getProperties(new PropertiesProvider(user));
    }
    if (properties == null || !properties.containsKey("mail.smtp.host")) {
        properties = getProperties(new PropertiesProvider(Context.getConfig()));
    }
    if (!properties.containsKey("mail.smtp.host")) {
        Log.warning("No SMTP configuration found");
        return;
    }
    Session session = Session.getInstance(properties);
    MimeMessage message = new MimeMessage(session);
    String from = properties.getProperty("mail.smtp.from");
    if (from != null) {
        message.setFrom(new InternetAddress(from));
    }
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
    MailMessage mailMessage = NotificationFormatter.formatMailMessage(userId, event, position);
    message.setSubject(mailMessage.getSubject());
    message.setSentDate(new Date());
    message.setContent(mailMessage.getBody(), "text/html; charset=utf-8");
    Transport transport = session.getTransport();
    try {
        Context.getStatisticsManager().registerMail();
        transport.connect(properties.getProperty("mail.smtp.host"), properties.getProperty("mail.smtp.username"), properties.getProperty("mail.smtp.password"));
        transport.sendMessage(message, message.getAllRecipients());
    } finally {
        transport.close();
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) User(org.traccar.model.User) MimeMessage(javax.mail.internet.MimeMessage) Properties(java.util.Properties) Transport(javax.mail.Transport) Date(java.util.Date) Session(javax.mail.Session)

Example 8 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 SQLException {
    User user = QueryBuilder.create(dataSource, getQuery("database.loginUser")).setString("email", email.trim()).executeQuerySingle(User.class);
    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 : User(org.traccar.model.User) ManagedUser(org.traccar.model.ManagedUser)

Example 9 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 10 with User

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

Aggregations

User (org.traccar.model.User)12 PermitAll (javax.annotation.security.PermitAll)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 Date (java.util.Date)2 POST (javax.ws.rs.POST)2 ManagedUser (org.traccar.model.ManagedUser)2 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 Session (javax.mail.Session)1 Transport (javax.mail.Transport)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1 NamingException (javax.naming.NamingException)1 Attribute (javax.naming.directory.Attribute)1 SearchResult (javax.naming.directory.SearchResult)1 Cookie (javax.servlet.http.Cookie)1 GET (javax.ws.rs.GET)1 Response (javax.ws.rs.core.Response)1 SecurityContext (javax.ws.rs.core.SecurityContext)1