Skip to content

Commit

Permalink
Added logout, fixed sh scripts for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
Molyna committed Oct 14, 2018
1 parent ecd574d commit 9c9ca5c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inf.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

docker run --name glicko-mongo --network=glickorater -p 27017:27017 -d mongo
docker run --name glicko-postgres --network=glickorater -p 5432:5432 -d postgres
2 changes: 1 addition & 1 deletion runimage.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

docker run --name glicko-rater --network=glickorater -p 3000:3000 -e MONGODB_ADDR="glicko-mongo" -d desp/glickorater:local
docker run --name glicko-rater --network=glickorater -p 3000:3000 -e DB_ADDR="glicko-postgres" -d desp/glickorater:local
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void doAuth(UUID token) {
}
}

public void logout(UUID authorization) {
Token token = getToken(authorization).orElseThrow(() -> new NotAuthorizedException("Not authorized"));
query.update("DELETE FROM token WHERE token = ?").params(token.token().toString()).run();
}

private Optional<Token> getToken(UUID token) {
return query.select("SELECT * FROM token WHERE token = ?").params(token.toString()).firstResult(tokenMapper());
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/solutions/desperate/glicko/rest/TokenApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import solutions.desperate.glicko.rest.dto.AuthHeader;
import solutions.desperate.glicko.rest.view.TokenView;
import solutions.desperate.glicko.domain.service.AuthService;

import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand Down Expand Up @@ -38,4 +40,11 @@ public TokenView token(@ApiParam(allowableValues = "password") @FormParam("grant
}
return authService.doLogin(username, password);
}

@ApiOperation(value = "Log out user")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public void logout(@ApiParam(hidden = true) @HeaderParam("authorization") String authorization) {
authService.logout(AuthHeader.getAuthString(authorization));
}
}

0 comments on commit 9c9ca5c

Please sign in to comment.