1.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Sun Apr 25 21:20:09 2010 +0200
1.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Sun Apr 25 21:41:00 2010 +0200
1.3 @@ -90,7 +90,7 @@
1.4 public String login(
1.5 @QueryParam("name") String name,
1.6 @QueryParam("password") String password
1.7 - ) {
1.8 + ) throws IOException {
1.9 File f = new File(path, "passwd"); // NOI18Nt
1.10 Properties p = new Properties();
1.11 try {
1.12 @@ -98,7 +98,14 @@
1.13 } catch (IOException ex) {
1.14 ex.printStackTrace();
1.15 }
1.16 + boolean loggedInOK = false;
1.17 if (name != null && password.equals(p.getProperty(name))) {
1.18 + loggedInOK = true;
1.19 + } else {
1.20 + loggedInOK = getUsers().verifyPassword(name, password);
1.21 + }
1.22 +
1.23 + if (loggedInOK) {
1.24 UUID uuid = UUID.randomUUID();
1.25 loggedIn.put(uuid, name);
1.26 return uuid.toString();
2.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java Sun Apr 25 21:20:09 2010 +0200
2.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java Sun Apr 25 21:41:00 2010 +0200
2.3 @@ -131,6 +131,14 @@
2.4 return Response.ok().entity(getUserInfo(null, loginId, id).getJsonSource()).build();
2.5 }
2.6
2.7 + final boolean verifyPassword(String id, String passwd) throws IOException {
2.8 + Properties p = getProp(id);
2.9 + if (p != null) {
2.10 + return passwd.equals(p.getProperty("passwd"));
2.11 + }
2.12 + return false;
2.13 + }
2.14 +
2.15 private synchronized Properties getProp(String id) throws FileNotFoundException, IOException {
2.16 Properties p = new Properties();
2.17 if (id != null && id.length() > 0) {
3.1 --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/UsersTest.java Sun Apr 25 21:20:09 2010 +0200
3.2 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/UsersTest.java Sun Apr 25 21:41:00 2010 +0200
3.3 @@ -26,6 +26,7 @@
3.4
3.5 package cz.xelfi.quoridor.webidor;
3.6
3.7 +import java.io.FileInputStream;
3.8 import com.sun.jersey.api.client.UniformInterfaceException;
3.9 import com.sun.jersey.test.framework.JerseyTest;
3.10 import java.io.File;
3.11 @@ -59,8 +60,17 @@
3.12 dir.mkdirs();
3.13 File passwd = new File(dir, "passwd");
3.14 FileOutputStream os = new FileOutputStream(passwd);
3.15 - os.write("Jarda=heslo\nJirka=pesko\n".getBytes("UTF-8"));
3.16 + os.write("Jarda=heslo\n".getBytes("UTF-8"));
3.17 os.close();
3.18 + File usersDir = new File(dir, "users");
3.19 + usersDir.mkdirs();
3.20 + File fJirka = new File(usersDir, "Jirka");
3.21 + {
3.22 + Properties p = new Properties();
3.23 + p.setProperty("email", "jir@ka.cz");
3.24 + p.setProperty("passwd", "pesko");
3.25 + p.store(new FileOutputStream(fJirka), "");
3.26 + }
3.27 super.setUp();
3.28 }
3.29
3.30 @@ -95,6 +105,7 @@
3.31 File fJirka = new File(usersDir, "Jirka");
3.32 {
3.33 Properties p = new Properties();
3.34 + p.load(new FileInputStream(fJirka));
3.35 p.setProperty("email", "jir@ka.cz");
3.36 p.store(new FileOutputStream(fJirka), "");
3.37 }