freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java
changeset 82 9ac7acee7d9f
parent 80 e03f660f0e0a
child 83 8dd8b041a3e1
     1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Sat Sep 12 09:11:13 2009 +0200
     1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Sun Sep 13 16:48:54 2009 +0200
     1.3 @@ -35,14 +35,11 @@
     1.4  import com.sun.jersey.api.view.Viewable;
     1.5  import com.sun.net.httpserver.HttpServer;
     1.6  import java.io.File;
     1.7 -import java.io.FileInputStream;
     1.8 -import java.io.IOException;
     1.9  import java.net.URI;
    1.10  import java.util.HashMap;
    1.11  import java.util.Locale;
    1.12  import java.util.Map;
    1.13  import java.util.MissingResourceException;
    1.14 -import java.util.Properties;
    1.15  import java.util.ResourceBundle;
    1.16  import java.util.concurrent.Callable;
    1.17  import javax.ws.rs.DefaultValue;
    1.18 @@ -71,13 +68,16 @@
    1.19      @Context
    1.20      private HttpHeaders headers;
    1.21      private String user;
    1.22 +    private String uuid;
    1.23  
    1.24      public UI() {
    1.25      }
    1.26  
    1.27      private Viewable checkLogin() {
    1.28          if (headers.getCookies().containsKey("login")) {
    1.29 -            user = headers.getCookies().get("login").getValue();
    1.30 +            uuid = headers.getCookies().get("login").getValue();
    1.31 +            user = base.path("login").queryParam("id", uuid).
    1.32 +                accept(MediaType.TEXT_PLAIN).get(String.class);
    1.33              return null;
    1.34          }
    1.35          return viewable("login.fmt", null);
    1.36 @@ -89,16 +89,11 @@
    1.37      public Response login(
    1.38          @FormParam("name") String name, @FormParam("password") String password
    1.39      ) throws Exception {
    1.40 -        File f = new File(new File(System.getProperty("quoridor.dir")), "passwd");
    1.41 -        Properties p = new Properties();
    1.42 -        try {
    1.43 -            p.load(new FileInputStream(f));
    1.44 -        } catch (IOException ex) {
    1.45 -            ex.printStackTrace();
    1.46 -        }
    1.47 -        if (name != null && password.equals(p.getProperty(name))) {
    1.48 +        uuid = base.path("login").queryParam("name", name).queryParam("password", password).
    1.49 +            accept(MediaType.TEXT_PLAIN).put(String.class);
    1.50 +        if (uuid != null) {
    1.51              user = name;
    1.52 -            return Response.ok().cookie(new NewCookie("login", name)).entity(viewable("login.fmt", null)).build();
    1.53 +            return Response.ok().cookie(new NewCookie("login", uuid)).entity(viewable("login.fmt", null)).build();
    1.54          } else {
    1.55              Viewable v = viewable("login.fmt", null, "message", "Invalid name or password: " + name);
    1.56              return Response.status(1).entity(v).build();
    1.57 @@ -145,7 +140,9 @@
    1.58          if (v != null) {
    1.59              return v;
    1.60          }
    1.61 -        WebResource wr = base.path("games").path(id).queryParam("player", user);
    1.62 +        WebResource wr = base.path("games").path(id).
    1.63 +            queryParam("loginID", uuid).
    1.64 +            queryParam("player", user);
    1.65          try {
    1.66              if (type.equals("resign")) {
    1.67                  wr.queryParam("move", "RESIGN").put();
    1.68 @@ -179,7 +176,9 @@
    1.69  
    1.70          if (user.equals(white) || user.equals(black)) {
    1.71              Object obj =
    1.72 -                base.path("games").queryParam("white", white).
    1.73 +                base.path("games").
    1.74 +                queryParam("loginID", uuid).
    1.75 +                queryParam("white", white).
    1.76                  queryParam("black", black).accept(MediaType.TEXT_XML).post(Document.class);
    1.77              return Response.ok(welcomeImpl()).build();
    1.78          } else {