-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetTokenTask.java
79 lines (59 loc) · 2.11 KB
/
GetTokenTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.mathur.android.listit;
import android.content.Context;
import android.os.AsyncTask;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.net.MalformedURLException;
/**
* Created by neerajpooja on 5/31/2016.
*/
public class GetTokenTask extends AsyncTask<Void, Void, Boolean> {
private final String mEmail;
private final String mPassword;
private Context mContext;
GetTokenTask(String email, String password, Context context) {
mEmail = email;
mPassword = password;
mContext = context;
}
@Override
protected Boolean doInBackground(Void... params) {
// TODO: attempt authentication against a network service.
String result;
try {
RestClient restClient = new RestClient();
result = restClient.getToken(mEmail, mPassword, mContext);
JSONObject resultJson = new JSONObject(result);
//int id = Integer.parseInt(resultJson.getString("id"));
//String token = resultJson.getString("token");
//((Global) getApplicationContext()).set_userId(id);
//Thread.sleep(2000);
//} catch (InterruptedException e) {
//return false;
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
} catch (JSONException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
// for (String credential : DUMMY_CREDENTIALS) {
// String[] pieces = credential.split(":");
// if (pieces[0].equals(mEmail)) {
// // Account exists, return true if the password matches.
// return pieces[1].equals(mPassword);
// }
// }
return true;
}
@Override
protected void onPostExecute(final Boolean success) {
}
@Override
protected void onCancelled() {
}
}