successful login-reg using web server
This commit is contained in:
parent
614ba6a192
commit
07de13c552
|
@ -28,4 +28,5 @@ dependencies {
|
|||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
implementation 'com.android.support:cardview-v7:29.0.2'
|
||||
implementation "androidx.annotation:annotation:1.1.0"
|
||||
implementation 'com.android.volley:volley:1.1.1'
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.alzapp">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/app_icon"
|
||||
|
@ -9,7 +11,8 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<activity android:name=".QuickPlayMenu"></activity>
|
||||
<activity android:name=".UserAreaActivity"></activity>
|
||||
<activity android:name=".QuickPlayMenu" />
|
||||
<activity android:name=".TileMatchingActivity" />
|
||||
<activity android:name=".WelcomeActivity" />
|
||||
<activity android:name=".JumbleActivity" />
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.widget.Toast;
|
||||
/*******
|
||||
Created on: 21/01/2020
|
||||
|
||||
By: B.Priyatham sai chand
|
||||
|
||||
|
||||
********/
|
||||
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final String DATABASE_NAME = "User.db";
|
||||
private static final String TABLE_NAME = "tblUser";
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
private Context context;
|
||||
|
||||
DatabaseHelper(Context context){
|
||||
super (context, DATABASE_NAME,null, DATABASE_VERSION);
|
||||
this.context = context;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
|
||||
db.execSQL("CREATE TABLE GENDER (GENDER INTEGER PRIMARY KEY, VALUE VARCHAR(20));");
|
||||
db.execSQL("CREATE TABLE TBLUSERINFO (USERID INTEGER PRIMARY KEY AUTOINCREMENT,USERNAME TEXT,PASSWORD TEXT,FIRSTNAME VARCHAR(20),LASTNAME VARCHAR(20), DOB TEXT,EMAIL TEXT, GENDER INTEGER,FOREIGN KEY(GENDER) REFERENCES GENDER(GENDER));");
|
||||
db.execSQL("CREATE TABLE TBLUSERNAME(ID INTEGER PRIMARY KEY, USERNAME TEXT,PASSWORD TEXT)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
db.execSQL("DROP TABLE IF EXISTS TBLUSERINFO;");
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
public Cursor getAllData() {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
Cursor res = db.rawQuery("select * from TBLUSERINFO ORDER BY USERID",null);
|
||||
return res;
|
||||
}
|
||||
|
||||
public void insertUsername(String username ,String password){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
db.execSQL("INSERT INTO TBLUSERNAME VALUES (username,password);");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void insertData(String reg_username,String reg_password,String first_name,String Last_name,String dob, String email,int gender) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
db.execSQL("INSERT INTO TBLUSERINFO VALUES (reg_username,reg_password,first_name,last_name,dob,email,gender);");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Cursor selectData(String firstname) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
Cursor res = db.rawQuery("select * from TBLUSERINFO WHERE FIRSTNAME='" + firstname + "' ORDER BY ID",null);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.toolbox.StringRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LoginRequest extends StringRequest {
|
||||
private static final String LOGIN_REQUEST_URL = "https://eclectic-sweeps.000webhostapp.com/login.php";
|
||||
private Map<String, String> params;
|
||||
|
||||
public LoginRequest(String username, String password, Response.Listener<String> listener) {
|
||||
super(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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.toolbox.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Registerequest extends StringRequest {
|
||||
private static final String REGISTER_REQUEST_URL = "https://eclectic-sweeps.000webhostapp.com/registration.php";
|
||||
private Map<String, String> params;
|
||||
|
||||
public Registerequest(String firstname, String lastname,String username,String dob,String email,String password, Response.Listener<String> listener) {
|
||||
super(Method.POST, REGISTER_REQUEST_URL, listener, null);
|
||||
params = new HashMap<>();
|
||||
params.put("username", username);
|
||||
params.put("password", password);
|
||||
params.put("firstname", firstname);
|
||||
params.put("lastname", lastname);
|
||||
params.put("dob",dob);
|
||||
params.put("email",email);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParams() {
|
||||
return params;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class UserAreaActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_user_area);
|
||||
|
||||
Intent intent = getIntent();
|
||||
String username = intent.getStringExtra("username");
|
||||
|
||||
|
||||
TextView tvWelcomeMsg = (TextView) findViewById(R.id.tvWelcomeMsg);
|
||||
EditText etUsername = (EditText) findViewById(R.id.etUsername);
|
||||
|
||||
|
||||
// Display user details
|
||||
String message = username + " welcome to your user area";
|
||||
tvWelcomeMsg.setText(message);
|
||||
etUsername.setText(username);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,13 +1,17 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.widget.EditText;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.*;
|
||||
import java.lang.*;
|
||||
import com.android.volley.*;
|
||||
import com.android.volley.toolbox.*;
|
||||
import android.app.AlertDialog;
|
||||
/*******
|
||||
Created on: 21/01/2020
|
||||
|
||||
|
@ -18,13 +22,16 @@ import android.widget.TextView;
|
|||
|
||||
public class login extends AppCompatActivity {
|
||||
private TextView signup;
|
||||
private Button signin;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
|
||||
signin = (Button) findViewById(R.id.signin_button);
|
||||
signup = (TextView) findViewById(R.id.signUp_text);
|
||||
final EditText etUsername = (EditText) findViewById(R.id.etUsername);
|
||||
final EditText etPassword = (EditText) findViewById(R.id.etPassword);
|
||||
|
||||
signup.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -41,6 +48,7 @@ public class login extends AppCompatActivity {
|
|||
|
||||
|
||||
|
||||
|
||||
Button back = (Button) findViewById(R.id.back);
|
||||
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -50,6 +58,55 @@ public class login extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
signin.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 username1 = jsonResponse.getString("username");
|
||||
|
||||
|
||||
Intent intent = new Intent(login.this, UserAreaActivity.class);
|
||||
intent.putExtra("name", username1);
|
||||
|
||||
|
||||
login.this.startActivity(intent);
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(login.this);
|
||||
builder.setMessage("Login Failed")
|
||||
.setNegativeButton("Retry", null)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
|
||||
RequestQueue queue = Volley.newRequestQueue(login.this);
|
||||
queue.add(loginRequest);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,11 +17,16 @@ import java.text.DateFormat;
|
|||
import java.util.Calendar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import android.widget.Toast;
|
||||
import android.view.View;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Gravity;
|
||||
import org.json.*;
|
||||
import java.lang.*;
|
||||
import com.android.volley.*;
|
||||
import com.android.volley.toolbox.*;
|
||||
import android.app.AlertDialog;
|
||||
/*******
|
||||
Created on: 21/01/2020
|
||||
|
||||
|
@ -33,7 +38,7 @@ import android.view.Gravity;
|
|||
public class registration extends AppCompatActivity implements DatePickerDialog.OnDateSetListener {
|
||||
private TextView signin;
|
||||
private TextView dob;
|
||||
com.example.alzapp.DatabaseHelper dal;
|
||||
|
||||
SQLiteDatabase sqLiteDatabase;
|
||||
private RadioGroup radioSexGroup;
|
||||
private RadioButton radioSexButton;
|
||||
|
@ -50,8 +55,8 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_registration);
|
||||
|
||||
dal = new DatabaseHelper(registration.this);
|
||||
username = (EditText) findViewById(R.id.reg_useername);
|
||||
|
||||
username = (EditText) findViewById(R.id.reg_username);
|
||||
password = (EditText) findViewById(R.id.reg_password);
|
||||
firstname = (EditText) findViewById(R.id.firstname);
|
||||
lastname = (EditText) findViewById(R.id.lastname);
|
||||
|
@ -83,9 +88,34 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
|||
|
||||
else {
|
||||
|
||||
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) {
|
||||
Intent intent = new Intent(registration.this,login.class);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(registration.this);
|
||||
builder.setMessage("Register Failed")
|
||||
.setNegativeButton("Retry", null)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
Registerequest reg_request = new Registerequest(firstname.getText().toString(),lastname.getText().toString(),username.getText().toString(),dob.getText().toString(),email_id.getText().toString(),password.getText().toString(),responseListener);
|
||||
RequestQueue queue = Volley.newRequestQueue(registration.this);
|
||||
queue.add(reg_request);
|
||||
|
||||
|
||||
|
||||
|
||||
insertData();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -151,15 +181,15 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
|||
radioSexButton = (RadioButton) findViewById(selectedId);
|
||||
|
||||
if(radioSexButton.getText() == "Male"){
|
||||
sex = 0;
|
||||
sex = 1;
|
||||
}
|
||||
else if (radioSexButton.getText() == "Female"){
|
||||
|
||||
sex = 1;
|
||||
sex = 2;
|
||||
}
|
||||
else{
|
||||
|
||||
sex = -1;
|
||||
sex = 3;
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,12 +198,7 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
|||
|
||||
|
||||
}
|
||||
public void insertData(){
|
||||
|
||||
dal.insertData(username.getText().toString(),lastname.getText().toString(),firstname.getText().toString(),lastname.getText().toString(),dob.getText().toString(),email_id.getText().toString(),sex);
|
||||
|
||||
|
||||
}
|
||||
public boolean isEmpty(EditText etText) {
|
||||
return etText.getText().toString().trim().length() == 0;
|
||||
}
|
||||
|
@ -196,4 +221,8 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
|||
toast.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etUsername"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/edit_text_top"
|
||||
|
@ -54,6 +55,7 @@
|
|||
android:padding="15dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etPassword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/edit_text_bottom"
|
||||
|
@ -63,6 +65,7 @@
|
|||
|
||||
|
||||
<Button
|
||||
android:id="@+id/signin_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
android:textSize="14sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/reg_useername"
|
||||
android:id="@+id/reg_username"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_marginStart="24dp"
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/activity_horizontal_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvWelcomeMsg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:text="hello world"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/tvWelcomeMsg"
|
||||
android:text="Username"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etUsername"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/textView"
|
||||
android:editable="false" />
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
Binary file not shown.
Before Width: | Height: | Size: 3.7 KiB |
|
@ -0,0 +1,6 @@
|
|||
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|
Loading…
Reference in New Issue