- PHP CODE connect.php
<?php
//$conn=mysqli_connect("localhost","root","","users");
?>
- REGISTER.PHP
<?php
if ($_SERVER['REQUEST_METHOD'] =='POST'){
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$password = password_hash($password, PASSWORD_DEFAULT);
require_once 'connect.php';
$sql = "INSERT INTO users_table (name, email, password) VALUES ('$name', '$email', '$password')";
if ( mysqli_query($conn, $sql) ) {
$result["success"] = "1";
$result["message"] = "success";
echo json_encode($result);
mysqli_close($conn);
} else {
$result["success"] = "0";
$result["message"] = "error";
echo json_encode($result);
mysqli_close($conn);
}
}
?>
- 3 LOGIN.PHP
<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {
$email = $_POST['email'];
$password = $_POST['password'];
require_once 'connect.php';
$sql = "SELECT * FROM users_table WHERE email='$email' ";
$response = mysqli_query($conn, $sql);
$result = array();
$result['login'] = array();
if ( mysqli_num_rows($response) === 1 ) {
$row = mysqli_fetch_assoc($response);
if ( password_verify($password, $row['password']) ) {
$index['name'] = $row['name'];
$index['email'] = $row['email'];
$index['id'] = $row['id'];
array_push($result['login'], $index);
$result['success'] = "1";
$result['message'] = "success";
echo json_encode($result);
mysqli_close($conn);
} else {
$result['success'] = "0";
$result['message'] = "error";
echo json_encode($result);
mysqli_close($conn);
}
}
}
?>
- 4 EDIT DETAIL.PHP
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_POST['name'];
$email = $_POST['email'];
$id = $_POST['id'];
require_once 'connect.php';
$sql = "UPDATE users_table SET name='$name', email='$email' WHERE id='$id' ";
if(mysqli_query($conn, $sql)) {
$result["success"] = "1";
$result["message"] = "success";
echo json_encode($result);
mysqli_close($conn);
}
}
else{
$result["success"] = "0";
$result["message"] = "error!";
echo json_encode($result);
mysqli_close($conn);
}
?>
- 5 READ DETAIL.PHP
<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {
$id = $_POST['id'];
require_once 'connect.php';
$sql = "SELECT * FROM users_table WHERE id='$id' ";
$response = mysqli_query($conn, $sql);
$result = array();
$result['read'] = array();
if( mysqli_num_rows($response) === 1 ) {
if ($row = mysqli_fetch_assoc($response)) {
$h['name'] = $row['name'] ;
$h['email'] = $row['email'] ;
array_push($result["read"], $h);
$result["success"] = "1";
echo json_encode($result);
}
}
}else {
$result["success"] = "0";
$result["message"] = "Error!";
echo json_encode($result);
mysqli_close($conn);
}
?>
- UPLOAD .PHP
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$id = $_POST['id'];
$photo = $_POST['photo'];
$path = "profile_image/$id.jpeg";
$finalPath = "http://192.168.1.104/android_register_login/".$path;
require_once 'connect.php';
$sql = "UPDATE users_table SET photo='$finalPath' WHERE id='$id' ";
if (mysqli_query($conn, $sql)) {
if ( file_put_contents( $path, base64_decode($photo) ) ) {
$result['success'] = "1";
$result['message'] = "success";
echo json_encode($result);
mysqli_close($conn);
}
}
}
?>
- 7 MAIN ACTIVITY.JAVA
package com.t.indoreview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread thread = new Thread() {
public void run() {
try {
sleep(5000);
} catch (Exception e)
{
e.printStackTrace();
} finally {
Intent intent = new Intent(getApplicationContext(), Register.class);
startActivity(intent);
finish();
}
}
};
thread.start();
}
}
- 8 REGISTER .JAVA
package com.t.indoreview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class Register extends AppCompatActivity {
private EditText name, email, password, confirmpassword;
private Button register_button;
private ProgressBar progressBar;
private static String URL_REGIST = "https://applicatory-shadow.000webhostapp.com/register.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
name = (EditText) findViewById(R.id.id_name);
email = (EditText) findViewById(R.id.id_emailid);
password = (EditText) findViewById(R.id.id_password);
confirmpassword = (EditText) findViewById(R.id.id_confirmpsword);
progressBar = (ProgressBar) findViewById(R.id.progressbarloding);
register_button = (Button) findViewById(R.id.id_customer_register_button);
register_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Regist();
}
});
}
private void Regist() {
progressBar.setVisibility(View.VISIBLE);
register_button.setVisibility(View.GONE);
final String name_get_var = this.name.getText().toString();
final String email_get_var = this.email.getText().toString();
final String password_get_var = this.password.getText().toString();
StringRequest string_post_Request = new StringRequest(Request.Method.POST, URL_REGIST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
//php page ke liye
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
if (success.equals("1")) {
Toast.makeText(Register.this, "REGISTER SUcCESSFULL", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
register_button.setVisibility(View.VISIBLE);
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(Register.this, "REGISTER ERROR !" + e.toString(), Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
register_button.setVisibility(View.VISIBLE);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Register.this, "REGISTER ERROR !" + error.toString(), Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
register_button.setVisibility(View.VISIBLE);
}
}
) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("name", name_get_var);
params.put("email", email_get_var);
params.put("password", password_get_var);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(string_post_Request);
}
//code for moving from one to another page
public void login_page_link(View view) {
Intent intent = new Intent(Register.this, loginActivity.class);
startActivity(intent);
}
}
- 9 LOGIN ACTIVITY .JAVA
package com.t.indoreview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class loginActivity extends AppCompatActivity {
private EditText email, password;
private Button btn_login;
private TextView link_regist;
private ProgressBar loading;
private static final String URL_LOGIN = "https://applicatory-shadow.000webhostapp.com/login.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loading = findViewById(R.id.loding_progressbar);
email = findViewById(R.id.id_emailid);
password = findViewById(R.id.id_password);
btn_login = findViewById(R.id.id_customer_login_button);
link_regist = findViewById(R.id.id_customer_register_text);
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String mEmail = email.getText().toString().trim();
String mPass = password.getText().toString().trim();
if (!mEmail.isEmpty() || !mPass.isEmpty()) {
Login(mEmail, mPass);
} else {
email.setError("Please insert email");
password.setError("Please insert password");
}
}
});
link_regist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(loginActivity.this, Register.class));
}
});
}
private void Login(final String email, final String password) {
loading.setVisibility(View.VISIBLE);
btn_login.setVisibility(View.GONE);
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_LOGIN,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
JSONArray jsonArray = jsonObject.getJSONArray("login");
if (success.equals("1")) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
String name = object.getString("name").trim();
String email = object.getString("email").trim();
String id = object.getString("id").trim();
// sessionManager.createSession(name, email, id);
Intent intent = new Intent(loginActivity.this, LOGOUT.class);
intent.putExtra("name", name);
intent.putExtra("email", email);
startActivity(intent);
finish();
loading.setVisibility(View.GONE);
}
}
} catch (JSONException e) {
e.printStackTrace();
loading.setVisibility(View.GONE);
btn_login.setVisibility(View.VISIBLE);
Toast.makeText(loginActivity.this, "Error " +e.toString(), Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
loading.setVisibility(View.GONE);
btn_login.setVisibility(View.VISIBLE);
Toast.makeText(loginActivity.this, "Error " +error.toString(), Toast.LENGTH_SHORT).show();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("email", email);
params.put("password", password);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
}
- LOGOUT PAGE.JAVA
package com.t.indoreview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class userimageDisplayactivity extends AppCompatActivity {
private TextView name,email;
private Button btn_logout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userimage_displayactivity);
name=(TextView)findViewById(R.id.id_name);
email=(TextView)findViewById(R.id.id_email_welcome);
Intent intent=getIntent();
String extraname=intent.getStringExtra("name");
String extraemail=intent.getStringExtra("email");
name.setText(extraname);
email.setText(extraemail);
btn_logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
- 11REGISTRATION .XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Register">
<ImageView
android:id="@+id/customer_password_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="fitStart"
android:src="@drawable/screen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:gravity="center">
<TextView
android:id="@+id/customer_status_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:text="CUSTOMER REGISTRATION"
android:textColor="@color/primary_txt"
android:textSize="25dp"
android:textStyle="bold" />
<EditText
android:id="@+id/id_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:hint="ENTER NAME"
android:textColor="@color/orange"
android:layout_marginBottom="10dp"
android:inputType="textPersonName" />
<EditText
android:id="@+id/id_emailid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:hint="ENTER E MAIL ID"
android:textColor="@color/orange"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/id_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:hint="ENTER PASSWORD"
android:textColor="@color/orange"
android:layout_marginBottom="10dp"
android:inputType="textPassword"
/>
<EditText
android:id="@+id/id_confirmpsword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:hint="ENTER CONFIRM PASSWORD"
android:textColor="@color/orange"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress" />
<ProgressBar
android:id="@+id/progressbarloding"
android:layout_marginTop="10dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/id_customer_register_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/progressbarloding"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@color/colorPrimary"
android:text="REGISTER"
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_customer_register_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/id_customer_register_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:text="Already Have An Account ? SIGN UP"
android:textColor="@color/colorAccent"
android:textSize="18sp"
android:textStyle="bold"
android:onClick="login_page_link"/>
</LinearLayout>
</RelativeLayout>
- 12LOGIN .XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".loginActivity">
<ImageView
android:id="@+id/customer_password_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="fitStart"
android:src="@drawable/screen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:gravity="center">
<TextView
android:id="@+id/customer_status_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_gravity="center"
android:text="CUSTOMER LOGIN"
android:textColor="@color/primary_txt"
android:textSize="25dp"
android:textStyle="bold" />
<EditText
android:id="@+id/id_emailid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:hint="ENTER E MAIL ID"
android:textColor="@color/orange"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/id_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:hint="ENTER PASSWORD"
android:textColor="@color/orange"
android:layout_marginBottom="10dp"
android:inputType="textPassword"
/>
<ProgressBar
android:id="@+id/loding_progressbar"
android:layout_marginTop="10dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/id_customer_login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/progressbarloding"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@color/colorPrimary"
android:text="LOGIN"
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_customer_register_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/id_customer_login_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:text="DONT Have An Account ? REGISTER"
android:textColor="@color/colorAccent"
android:textSize="18sp"
android:textStyle="bold"
/>
</LinearLayout>
</RelativeLayout>
- 13 LOGOUT PAGE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".userimageDisplayactivity">
<TextView
android:id="@+id/id_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:text="WELCOME ! "
android:textColor="@color/orange"
android:textSize="25sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/id_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_below="@id/id_welcome"
android:layout_marginTop="137dp"
android:gravity="center_horizontal"
android:text="NAME : "
android:textColor="@color/orange"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_email_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/id_name"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:text="EMAIL IS : "
android:textColor="@color/orange"
android:textSize="25sp"
android:textStyle="bold" />
<Button
android:id="@+id/logoutbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="57dp"
android:background="@color/orange"
android:text="LOGOUT"
android:textColor="@color/primary_txt"
android:textSize="25dp"
android:textStyle="bold" />
</RelativeLayout>
- 14
- 15
- 16
- 17
- 18
0 comments:
Post a Comment