webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java
changeset 144 cc04ede4cb5e
parent 143 4eb88f05c207
child 145 ac9bd9be5263
     1.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java	Sat Nov 07 15:23:14 2009 +0100
     1.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java	Sat Nov 07 18:31:47 2009 +0100
     1.3 @@ -30,6 +30,7 @@
     1.4  import java.io.File;
     1.5  import java.io.FileInputStream;
     1.6  import java.io.FileNotFoundException;
     1.7 +import java.io.FileOutputStream;
     1.8  import java.io.IOException;
     1.9  import java.util.ArrayList;
    1.10  import java.util.Collections;
    1.11 @@ -38,11 +39,13 @@
    1.12  import java.util.logging.Logger;
    1.13  import javax.ws.rs.DefaultValue;
    1.14  import javax.ws.rs.GET;
    1.15 +import javax.ws.rs.POST;
    1.16  import javax.ws.rs.Path;
    1.17  import javax.ws.rs.PathParam;
    1.18  import javax.ws.rs.Produces;
    1.19  import javax.ws.rs.QueryParam;
    1.20  import javax.ws.rs.core.MediaType;
    1.21 +import javax.ws.rs.core.Response;
    1.22  
    1.23  /**
    1.24   *
    1.25 @@ -82,7 +85,32 @@
    1.26          return user;
    1.27      }
    1.28  
    1.29 -    private Properties getProp(String id) throws FileNotFoundException, IOException {
    1.30 +    @POST
    1.31 +    @Path("{id}")
    1.32 +    @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
    1.33 +    public synchronized Response changeProperty(
    1.34 +        @QueryParam("loginID") String loginId,
    1.35 +        @PathParam("id") String id,
    1.36 +        @QueryParam("name") String name,
    1.37 +        @QueryParam("value") String value
    1.38 +    ) throws IOException {
    1.39 +        String myid = quoridor.isLoggedIn(loginId);
    1.40 +        if (!id.equals(myid) || name.startsWith("permission.")) {
    1.41 +            return Response.status(Response.Status.UNAUTHORIZED).build();
    1.42 +        }
    1.43 +
    1.44 +        Properties p = getProp(myid);
    1.45 +        p.setProperty(name, value);
    1.46 +
    1.47 +        File f = new File(dir, id);
    1.48 +        FileOutputStream os = new FileOutputStream(f);
    1.49 +        p.store(os, "");
    1.50 +        os.close();
    1.51 +        
    1.52 +        return Response.ok().entity(getUserInfo(loginId, id)).build();
    1.53 +    }
    1.54 +
    1.55 +    private synchronized Properties getProp(String id) throws FileNotFoundException, IOException {
    1.56          Properties p = new Properties();
    1.57          if (id != null && id.length() > 0) {
    1.58              File f = new File(dir, id);