diff --git a/SWADroid/src/es/ugr/swad/swadroid/Global.java b/SWADroid/src/es/ugr/swad/swadroid/Global.java index 5b7c015a..61ec553d 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/Global.java +++ b/SWADroid/src/es/ugr/swad/swadroid/Global.java @@ -24,14 +24,18 @@ package es.ugr.swad.swadroid; * @author Juan Miguel Boyero Corral */ public class Global { - /** - * Request code for Login module. - */ - public static final int LOGIN_REQUEST_CODE = 1; + /** + * SWAD application key + */ + private static final String AppKey = "HTC-Desire"; /** * User logged flag */ private static boolean logged; + /** + * Request code for Login module. + */ + public static final int LOGIN_REQUEST_CODE = 1; /** * Enum type defining allowed user types */ @@ -105,6 +109,14 @@ public class Global { * Table name for for relationship between test's questions and tags */ public static final String DB_TABLE_TEST_QUESTIONS_TAGS = "tst_questions_tags"; + + /** + * Gets the SWAD application key + * @return SWAD application key + */ + public static String getAppKey() { + return AppKey; + } /** * Checks if user is already logged on SWAD * @return User logged flag diff --git a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java index 44be4d6a..713787c5 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java +++ b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java @@ -31,6 +31,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.Window; import es.ugr.swad.swadroid.model.DataBaseHelper; +import es.ugr.swad.swadroid.model.User; import es.ugr.swad.swadroid.modules.Login; import es.ugr.swad.swadroid.ssl.SecureConnection; diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java b/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java index 9ab07e8c..64b83035 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/Login.java @@ -22,13 +22,14 @@ package es.ugr.swad.swadroid.modules; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; +import android.util.Base64; import android.util.Log; +import es.ugr.swad.swadroid.Global; import es.ugr.swad.swadroid.R; import es.ugr.swad.swadroid.model.User; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import org.kobjects.base64.Base64; import org.ksoap2.SoapFault; import org.xmlpull.v1.XmlPullParserException; @@ -53,7 +54,7 @@ public class Login extends Module { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setMETHOD_NAME("loginByUserPassword"); + setMETHOD_NAME("loginByUserPasswordKey"); connect(); } @@ -75,26 +76,27 @@ public class Login extends Module { private void requestService() throws NoSuchAlgorithmException, IOException, XmlPullParserException, SoapFault { - //Encrypts user password with SHA-512 and encodes it to Base64 + //Encrypts user password with SHA-512 and encodes it to Base64 md = MessageDigest.getInstance("SHA-512"); md.update(prefs.getUserPassword().getBytes()); - userPassword = Base64.encode(md.digest()); + userPassword = new String(Base64.encode(md.digest(), Base64.URL_SAFE + Base64.NO_PADDING + Base64.NO_WRAP)); //Creates webservice request, adds required params and sends request to webservice createRequest(); addParam("userID", prefs.getUserID()); addParam("userPassword", userPassword); + addParam("appKey", Global.getAppKey()); sendRequest(); //Stores user data returned by webservice response - User.setUserCode(result.getProperty("userCode").toString()); - User.setUserTypeCode(result.getProperty("userTypeCode").toString()); - User.setWsKey(result.getProperty("wsKey").toString()); - User.setUserID(result.getProperty("userID").toString()); - User.setUserSurname1(result.getProperty("userSurname1").toString()); - User.setUserSurname2(result.getProperty("userSurname2").toString()); - User.setUserFirstName(result.getProperty("userFirstName").toString()); - User.setUserTypeName(result.getProperty("userTypeName").toString()); + User.setUserCode(result.get(0).toString()); + User.setUserTypeCode(result.get(1).toString()); + User.setWsKey(result.get(2).toString()); + User.setUserID(result.get(3).toString()); + User.setUserSurname1(result.get(4).toString()); + User.setUserSurname2(result.get(5).toString()); + User.setUserFirstName(result.get(6).toString()); + User.setUserTypeName(result.get(7).toString()); //Request finalized without errors setResult(RESULT_OK); diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java b/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java index dfd9e733..c4b0d7a1 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/Module.java @@ -29,8 +29,11 @@ import es.ugr.swad.swadroid.Global; import es.ugr.swad.swadroid.Preferences; import es.ugr.swad.swadroid.R; import java.io.IOException; +import java.util.ArrayList; + import org.ksoap2.SoapEnvelope; import org.ksoap2.SoapFault; +import org.ksoap2.serialization.KvmSerializable; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; @@ -68,7 +71,7 @@ public class Module extends Activity { /** * Webservice result. */ - SoapObject result; + ArrayList result; /** * Shows error messages. */ @@ -174,7 +177,7 @@ public class Module extends Activity { * Gets webservice result. * @return Webservice result. */ - public SoapObject getResult() { + public ArrayList getResult() { return result; } @@ -182,7 +185,7 @@ public class Module extends Activity { * Sets webservice result. * @param result Webservice result. */ - public void setResult(SoapObject result) { + public void setResult(ArrayList result) { this.result = result; } @@ -227,7 +230,7 @@ public class Module extends Activity { */ protected void createRequest() { request = new SoapObject(NAMESPACE, METHOD_NAME); - result = null; + result = new ArrayList(); } /** @@ -260,7 +263,11 @@ public class Module extends Activity { androidHttpTransport.call(SOAP_ACTION, envelope); } - result = (SoapObject) envelope.getResponse(); + KvmSerializable ks = (KvmSerializable)envelope.bodyIn; + for(int i=0;i