Commit a854c703 authored by rakam's avatar rakam

Send token through headers

parent 9c0a8cc0
......@@ -126,7 +126,6 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
private void startMatch(final ProgressDialog dialogToClose) {
final JsonObject param = new JsonObject();
param.addProperty("token", PrefsUtils.getToken(this));
param.addProperty("action", "START");
param.addProperty("court", idCourt);
param.addProperty("startDate", Utils.getCurrentDateInMySQLFormat());
......@@ -144,6 +143,7 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
Ion.with(this)
.load("PUT", API_URLS.UPDATE_MATCH(match.getId()))
.setTimeout(1000 * 6)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(this))
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
......
......@@ -2,7 +2,9 @@ package fr.istic.masteru.android.utils;
public class API_URLS {
public static final String AUTH_TOKEN = "ac_token";
public static final String BASE_URL = "http://5.196.21.161:2222";
public static final String PING_ADD_NUMBER = BASE_URL + "/test/nombres/ajouterNombre";
public static final String SCORE_UPDATE = BASE_URL + "/score/update";
public static final String MATCH_WINNER = BASE_URL + "/match/finMatch";
......
......@@ -148,7 +148,6 @@ public class ScoreSyncManager {
private void synchronizePoint(final float key, final Point point) {
final Score score = point.getScore();
JsonObject param = new JsonObject();
param.addProperty("token", PrefsUtils.getToken(context));
param.addProperty("scoreA", score.getScoreA());
param.addProperty("scoreB", score.getScoreB());
param.addProperty("setNum", score.getNumSet() + 1);
......@@ -165,6 +164,7 @@ public class ScoreSyncManager {
Ion.with(context)
.load("POST", API_URLS.UPDATE_SCORE(idMatch, score.getId()))
.setTimeout(TIMEOUT_MS)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
......@@ -224,13 +224,13 @@ public class ScoreSyncManager {
*/
private void synchronizePreviousSet(final float key, PreviousSetToSync previousSet) {
JsonObject param = new JsonObject();
param.addProperty("token", PrefsUtils.getToken(context));
param.addProperty("gameA", previousSet.getSetA());
param.addProperty("gameB", previousSet.getSetB());
Ion.with(context)
.load("PUT", API_URLS.UPDATE_SET_SCORE(idMatch, previousSet.getNumSet()))
.setTimeout(TIMEOUT_MS)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
......@@ -272,12 +272,10 @@ public class ScoreSyncManager {
* @param backToSync
*/
private void syncBack(final float key, BackToSync backToSync) {
JsonObject param = new JsonObject();
param.addProperty("token", PrefsUtils.getToken(context));
Ion.with(context)
.load("DELETE", API_URLS.DELETE_SCORE(idMatch, backToSync.getId()))
.setTimeout(TIMEOUT_MS)
.setJsonObjectBody(param)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
......@@ -323,7 +321,6 @@ public class ScoreSyncManager {
private void syncWinner(final float key, WinnerToSync winnerToSync) {
JsonObject param = new JsonObject();
param.addProperty("token", PrefsUtils.getToken(context));
param.addProperty("action", winnerToSync.isAbandon() ? "ABANDON" : "END");
param.addProperty("winner", winnerToSync.getWinner());
param.addProperty("endDate", Utils.getCurrentDateInMySQLFormat());
......@@ -331,6 +328,7 @@ public class ScoreSyncManager {
Ion.with(context)
.load("PUT", API_URLS.UPDATE_MATCH(idMatch))
.setTimeout(TIMEOUT_MS)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
......
......@@ -91,7 +91,6 @@ public class Utils {
return sdf.format(new Date());
}
public static void getToken(final Context context, final OnFinishCallback callback) {
JsonObject params = new JsonObject();
params.addProperty("login", "perceval");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment