Commit 463bd909 authored by Tanmim's avatar Tanmim
Browse files

Working login page and user profile page

parent 8a39efc5
......@@ -5,7 +5,7 @@
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
......
package travelpals.travelpals;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Tanmimh on 05/02/2017.
*/
public class LoginRequest extends StringRequest{
private static final String LOGIN_REQUEST_URL = "http://doc.gold.ac.uk/~thani001/travelpals/Login.php";
private Map<String, String> params;
public LoginRequest(String username, String password, Response.Listener<String> listener){
super(Request.Method.POST, LOGIN_REQUEST_URL, listener, null);
params = new HashMap<>();
params.put("username", username);
params.put("password", password);
}
@Override
public Map<String, String> getParams() {
return params;
}
}
package travelpals.travelpals;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
......@@ -16,5 +17,14 @@ public class UserAreaActivity extends AppCompatActivity {
final EditText etName = (EditText) findViewById(R.id.etName);
Intent intent = getIntent();
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", -1);
String username = intent.getStringExtra("username");
etUsername.setText(username);
etName.setText(name);
etAge.setText(age + "");
}
}
package travelpals.travelpals;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
......@@ -8,6 +9,13 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
public class loginActivity extends AppCompatActivity {
@Override
......@@ -28,5 +36,51 @@ public class loginActivity extends AppCompatActivity {
loginActivity.this.startActivity(registerIntent);
}
});
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if(success){
String name = jsonResponse.getString("name");
int age = jsonResponse.getInt("age");
String username = jsonResponse.getString("username");
Intent intent = new Intent(loginActivity.this, UserAreaActivity.class);
intent.putExtra("name", name);
intent.putExtra("age", age);
intent.putExtra("username", username);
loginActivity.this.startActivity(intent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(loginActivity.this);
builder.setMessage("Login failed")
.setNegativeButton("Try again", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(loginActivity.this);
queue.add(loginRequest);
}
});
}
}
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