package ro.pub.cs.vmchecker.client.service.json;

import ro.pub.cs.vmchecker.client.model.AuthenticationResponse;
import ro.pub.cs.vmchecker.client.model.User;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;

public class AuthenticationResponseDecoder implements JSONDecoder<AuthenticationResponse> {

	public static final String statusKey = "status"; 
	public static final String usernameKey = "username"; 
	public static final String useridKey = "userid";
	public static final String infoKey = "info"; 
	
	@Override
	public AuthenticationResponse decode(String text) throws Exception {
		JSONValue jsonValue = JSONParser.parse(text);
		JSONObject jsonObj = jsonValue.isObject();

		boolean status = jsonObj.get(statusKey).isBoolean().booleanValue();
		String info = jsonObj.get(infoKey).isString().stringValue();
		if (!status) {
			/*
			 * Authentication failed.
			 */
			return new AuthenticationResponse(status, null, info);
		}

		String username = jsonObj.get(usernameKey).isString().stringValue();
		String userid = jsonObj.get(useridKey).isString().stringValue();
		return new AuthenticationResponse(status, new User(userid, username), info);
	}

}

@@ -460,28 +460,28 @@
 inal String 
-user
+full
 nameKey = %22u
@@ -483,19 +483,18 @@
  = %22
-user
+full
 name%22;
- 
 %0A%09pu
@@ -522,18 +522,20 @@
 ing user
-id
+name
 Key = %22u
@@ -537,18 +537,20 @@
  = %22user
-id
+name
 %22;%0A%09publ
@@ -1103,22 +1103,24 @@
 %09String 
-userid
+fullname
  = jsonO
@@ -1126,22 +1126,24 @@
 Obj.get(
-userid
+fullname
 Key).isS
@@ -1226,16 +1226,18 @@
 user
-id, user
+name, full
 name

Use new services.py reply format for login().