aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/resource
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
-rw-r--r--src/main/java/org/traccar/api/resource/EventResource.java20
-rw-r--r--src/main/java/org/traccar/api/resource/OrderResource.java35
-rw-r--r--src/main/java/org/traccar/api/resource/PasswordResource.java7
-rw-r--r--src/main/java/org/traccar/api/resource/SessionResource.java33
4 files changed, 16 insertions, 79 deletions
diff --git a/src/main/java/org/traccar/api/resource/EventResource.java b/src/main/java/org/traccar/api/resource/EventResource.java
index 34e4a94ce..e0ccf7020 100644
--- a/src/main/java/org/traccar/api/resource/EventResource.java
+++ b/src/main/java/org/traccar/api/resource/EventResource.java
@@ -1,18 +1,3 @@
-/*
- * Copyright 2016 - 2021 Anton Tananaev (anton@traccar.org)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
package org.traccar.api.resource;
import java.sql.SQLException;
@@ -22,9 +7,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import org.traccar.Context;
import org.traccar.api.BaseResource;
@@ -42,9 +25,6 @@ public class EventResource extends BaseResource {
@GET
public Event get(@PathParam("id") long id) throws SQLException {
Event event = Context.getDataManager().getObject(Event.class, id);
- if (event == null) {
- throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
- }
Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId());
if (event.getGeofenceId() != 0) {
Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId());
diff --git a/src/main/java/org/traccar/api/resource/OrderResource.java b/src/main/java/org/traccar/api/resource/OrderResource.java
deleted file mode 100644
index 77608a508..000000000
--- a/src/main/java/org/traccar/api/resource/OrderResource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2021 Anton Tananaev (anton@traccar.org)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.traccar.api.resource;
-
-import org.traccar.api.SimpleObjectResource;
-import org.traccar.model.Order;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-@Path("orders")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class OrderResource extends SimpleObjectResource<Order> {
-
- public OrderResource() {
- super(Order.class);
- }
-
-}
diff --git a/src/main/java/org/traccar/api/resource/PasswordResource.java b/src/main/java/org/traccar/api/resource/PasswordResource.java
index 1868a6191..20e8d768d 100644
--- a/src/main/java/org/traccar/api/resource/PasswordResource.java
+++ b/src/main/java/org/traccar/api/resource/PasswordResource.java
@@ -19,7 +19,7 @@ import org.apache.velocity.VelocityContext;
import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.User;
-import org.traccar.notification.NotificationMessage;
+import org.traccar.notification.FullMessage;
import org.traccar.notification.TextTemplateFormatter;
import javax.annotation.security.PermitAll;
@@ -53,9 +53,8 @@ public class PasswordResource extends BaseResource {
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());
+ FullMessage message = TextTemplateFormatter.formatFullMessage(velocityContext, "passwordReset");
+ Context.getMailManager().sendMessage(userId, message.getSubject(), message.getBody());
break;
}
}
diff --git a/src/main/java/org/traccar/api/resource/SessionResource.java b/src/main/java/org/traccar/api/resource/SessionResource.java
index 60ce5490a..e3c5d457f 100644
--- a/src/main/java/org/traccar/api/resource/SessionResource.java
+++ b/src/main/java/org/traccar/api/resource/SessionResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,19 +57,8 @@ public class SessionResource extends BaseResource {
@PermitAll
@GET
public User get(@QueryParam("token") String token) throws SQLException, UnsupportedEncodingException {
-
- if (token != null) {
- User user = Context.getUsersManager().getUserByToken(token);
- if (user != null) {
- Context.getPermissionsManager().checkUserEnabled(user.getId());
- request.getSession().setAttribute(USER_ID_KEY, user.getId());
- return user;
- }
- }
-
Long userId = (Long) request.getSession().getAttribute(USER_ID_KEY);
if (userId == null) {
-
Cookie[] cookies = request.getCookies();
String email = null, password = null;
if (cookies != null) {
@@ -88,20 +77,24 @@ public class SessionResource extends BaseResource {
if (email != null && password != null) {
User user = Context.getPermissionsManager().login(email, password);
if (user != null) {
- Context.getPermissionsManager().checkUserEnabled(user.getId());
- request.getSession().setAttribute(USER_ID_KEY, user.getId());
- return user;
+ 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);
}
}
+ }
- } else {
-
+ if (userId != null) {
Context.getPermissionsManager().checkUserEnabled(userId);
return Context.getPermissionsManager().getUser(userId);
-
+ } else {
+ throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
-
- throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
@PermitAll