mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
hide session management inside UserService
This commit is contained in:
@@ -11,11 +11,12 @@ import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
import com.commafeed.CommaFeedApplication;
|
||||
import com.commafeed.backend.dao.UnitOfWork;
|
||||
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserSettings;
|
||||
import com.commafeed.backend.service.UserService;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@RequiredArgsConstructor
|
||||
@@ -23,20 +24,21 @@ public class CustomCssServlet extends HttpServlet {
|
||||
|
||||
private final SessionFactory sessionFactory;
|
||||
private final UserSettingsDAO userSettingsDAO;
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("text/css");
|
||||
|
||||
final User user = (User) req.getSession().getAttribute(CommaFeedApplication.SESSION_USER);
|
||||
if (user == null) {
|
||||
final Optional<User> user = userService.login(req.getSession());
|
||||
if (!user.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserSettings settings = new UnitOfWork<UserSettings>(sessionFactory) {
|
||||
@Override
|
||||
protected UserSettings runInSession() {
|
||||
return userSettingsDAO.findByUser(user);
|
||||
return userSettingsDAO.findByUser(user.get());
|
||||
}
|
||||
}.run();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user