Refactored UserREST login to populate session itself

This commit is contained in:
Sankaranarayanan Viswanathan
2014-10-09 08:38:50 -04:00
parent e38778b4d0
commit 54cc265ee6
3 changed files with 6 additions and 8 deletions

View File

@@ -79,6 +79,7 @@ public class UserREST {
private final PasswordEncryptionService encryptionService;
private final MailService mailService;
private final CommaFeedConfiguration config;
public static final String SESSION_KEY_USER = "user";
@Path("/settings")
@GET
@@ -243,8 +244,9 @@ public class UserREST {
@UnitOfWork
@ApiOperation(value = "Login and create a session")
public Response login(@ApiParam(required = true) LoginRequest req, @Session HttpSession session) {
Optional<User> user = userService.login(req.getName(), req.getPassword(), session);
Optional<User> user = userService.login(req.getName(), req.getPassword());
if (user.isPresent()) {
session.setAttribute(SESSION_KEY_USER, user.get());
return Response.ok().build();
} else {
return Response.status(Response.Status.UNAUTHORIZED).entity("wrong username or password").build();