update login
not working yet
This commit is contained in:
parent
ca00426965
commit
58b54678c3
Binary file not shown.
|
@ -9,7 +9,9 @@ import android.view.View;
|
|||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import monnethic.mobile.restApi.Config;
|
||||
|
@ -68,37 +70,45 @@ public class LoginActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
//AsyncTask for login
|
||||
private class UserLoggerTask extends AsyncTask<String,String,String> {
|
||||
private class UserLoggerTask extends AsyncTask<String,String,JSONObject> {
|
||||
Context mContext;
|
||||
private UserLoggerTask(final Context context){
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
if(result!=null){
|
||||
Intent accountIntent = new Intent(LoginActivity.this, UserAccountActivity.class);
|
||||
accountIntent.putExtra("userHash", result);
|
||||
LoginActivity.this.startActivity(accountIntent);
|
||||
finish();
|
||||
}else{
|
||||
Toast.makeText(mContext, "Wrong authentication", Toast.LENGTH_SHORT).show();
|
||||
protected void onPostExecute(JSONObject result) {
|
||||
try{
|
||||
if(result!=null){
|
||||
if(result.getString("response").equals("Ok")){
|
||||
Intent accountIntent = new Intent(LoginActivity.this, UserAccountActivity.class);
|
||||
accountIntent.putExtra("userHash", result.getString("userHash"));
|
||||
LoginActivity.this.startActivity(accountIntent);
|
||||
finish();
|
||||
}else {
|
||||
Toast.makeText(mContext, result.getString("response"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}else{
|
||||
Toast.makeText(mContext, "AN ERROR OCCURED", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
protected JSONObject doInBackground(String... params) {
|
||||
try{
|
||||
String url = Config.USER_GET;
|
||||
String email = params[1];
|
||||
String password = params[2];
|
||||
String[] paramsList = {email,password};
|
||||
String url = Config.USER_LOGIN;
|
||||
//String email = params[0];
|
||||
//String password = params[1];
|
||||
String[] paramsList = {params[0],params[1]};
|
||||
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
String response = httpCallHandler.executeGetHttp(url,paramsList);
|
||||
JSONObject json = new JSONObject(response);
|
||||
String response = httpCallHandler.executePostHttp(url,paramsList);
|
||||
|
||||
return json.getString("user_hash");
|
||||
return new JSONObject(response);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
|
@ -2,7 +2,7 @@ package monnethic.mobile.restApi;
|
|||
|
||||
public class Config {
|
||||
//BASE
|
||||
static private String BASE_URL = "http://10.0.2.2:8083/";
|
||||
static private String BASE_URL = "http://10.0.2.2:10053/";
|
||||
|
||||
//DATABASE
|
||||
static private String BASE_URL_USER = BASE_URL+"api/rest/user/";
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package monnethic.mobile.restApi;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -55,4 +58,58 @@ public class HttpCallHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String executePostHttp(String urlParam, String[] params){
|
||||
InputStream inputStream;
|
||||
BufferedReader bufferedReader = null;
|
||||
HttpURLConnection urlConnection = null;
|
||||
try{
|
||||
System.out.println("executePostHttp");
|
||||
|
||||
URL url = new URL(urlParam);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||
connection.setRequestProperty("Accept","application/json");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
|
||||
System.out.println("coucou");
|
||||
|
||||
JSONObject jsonParam = new JSONObject();
|
||||
jsonParam.put("email",params[0]);
|
||||
jsonParam.put("password",params[1]);
|
||||
|
||||
System.out.println("jsonParam : "+jsonParam.toString());
|
||||
|
||||
DataOutputStream os = new DataOutputStream(connection.getOutputStream());
|
||||
os.writeBytes(jsonParam.toString());
|
||||
|
||||
os.flush();
|
||||
os.close();
|
||||
|
||||
System.out.println("STATUS "+String.valueOf(connection.getResponseCode()));
|
||||
System.out.println("MSG "+connection.getResponseMessage());
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if(urlConnection != null){
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
if(bufferedReader != null){
|
||||
try {
|
||||
bufferedReader.close();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue