This commit is contained in:
Page Asgardius 2022-09-29 09:53:45 -07:00
parent 9d78ad4531
commit 7c095281aa
8 changed files with 192 additions and 51 deletions

View file

@ -1,6 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/4.7_WXGA_API_31.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
@ -12,6 +23,6 @@
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-09-20T11:10:14.173948Z" />
<timeTargetWasSelectedWithDropDown value="2022-09-29T15:55:29.079423Z" />
</component>
</project>

View file

@ -15,6 +15,13 @@
android:supportsRtl="true"
android:theme="@style/Theme.R3ForumTest"
tools:targetApi="31">
<activity
android:name=".MainScreen"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".SignUp"
android:exported="false"

View file

@ -3,6 +3,8 @@ package asgardius.page.r3forumtest;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@ -12,6 +14,7 @@ import android.widget.Toast;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.net.ssl.HttpsURLConnection;
@ -22,11 +25,29 @@ public class MainActivity extends AppCompatActivity {
HttpsURLConnection myConnection;
boolean success;
String myData;
SQLiteDatabase db;
MyDbHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbHelper = new MyDbHelper(this);
db = dbHelper.getWritableDatabase();
if (db != null) {
// Database Queries
try {
String query = "SELECT username, password FROM account";
Cursor cursor = db.rawQuery(query,null);
if (cursor.moveToNext()){
login(cursor.getString(0), cursor.getString(1));
db.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
user = (EditText)findViewById(R.id.username);
pwd = (EditText)findViewById(R.id.password);
signUp = (Button)findViewById(R.id.signup);
@ -45,64 +66,86 @@ public class MainActivity extends AppCompatActivity {
if(user.getText().toString().equals("") || pwd.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(),"Introduzac el usuario y contraseña", Toast.LENGTH_SHORT).show();
} else {
Thread login = new Thread(new Runnable() {
login(user.getText().toString().toLowerCase(), pwd.getText().toString());
}
}
});
}
private void login (String username, String password) {
Thread login = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
endpoint = new URL("https://desktop.asgardius.company/test/restful/items/check.php");
myConnection = (HttpsURLConnection) endpoint.openConnection();
myConnection.setRequestProperty("User-Agent", "r3-forum-test");
myConnection.setRequestMethod("POST");
// Create the data
myData = "{\n" +
"\"id\": \""+username+"\",\n" +
"\"password\": \""+password+"\"\n" +
"}";
// Enable writing
myConnection.setDoOutput(true);
// Write the data
myConnection.getOutputStream().write(myData.getBytes());
System.out.println(myConnection.getResponseCode());
if (myConnection.getResponseCode() == 201) {
success = true;
} else {
success = false;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
endpoint = new URL("https://desktop.asgardius.company/test/restful/items/check.php");
myConnection = (HttpsURLConnection) endpoint.openConnection();
myConnection.setRequestProperty("User-Agent", "r3-forum-test");
myConnection.setRequestMethod("POST");
// Create the data
myData = "{\n" +
"\"id\": \""+user.getText().toString()+"\",\n" +
"\"password\": \""+pwd.getText().toString()+"\"\n" +
"}";
// Enable writing
myConnection.setDoOutput(true);
// Write the data
myConnection.getOutputStream().write(myData.getBytes());
System.out.println(myConnection.getResponseCode());
if (myConnection.getResponseCode() == 201) {
success = true;
} else {
success = false;
//Test
if (success) {
Toast.makeText(getApplicationContext(), "Credenciales correctas", Toast.LENGTH_SHORT).show();
try {
db = dbHelper.getWritableDatabase();
db.execSQL("DELETE FROM account");
db.execSQL("INSERT INTO account VALUES (\""+username+"\", \""+password+"\")");
db.close();
mainScreen();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"Base de datos corrupta", Toast.LENGTH_SHORT).show();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
//Test
if (success) {
Toast.makeText(getApplicationContext(), "Credenciales correctas", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Credenciales incorrectas", Toast.LENGTH_SHORT).show();
}
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Conexión fallida", Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(getApplicationContext(), "Credenciales incorrectas", Toast.LENGTH_SHORT).show();
}
}
});
login.start();
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Conexión fallida", Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
//finish();
}
}
});
login.start();
}
private void mainScreen () {
Intent intent = new Intent(this, MainScreen.class);
startActivity(intent);
}
private void SignUpForm () {

View file

@ -0,0 +1,14 @@
package asgardius.page.r3forumtest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainScreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
}
}

View file

@ -0,0 +1,24 @@
package asgardius.page.r3forumtest;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class MyDbHelper extends SQLiteOpenHelper {
private static final String atcreate = "CREATE TABLE IF NOT EXISTS account(username text, password text)";
//private static final String upgrade = "ALTER TABLE account add column pdfendpoint text";
private static final int DATABASE_VERSION = 1;
private static final String dbname = "accounts.sqlite3";
private static final int dbversion = 3;
public MyDbHelper(Context context) {
super(context, dbname, null, dbversion);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(atcreate);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//db.execSQL(upgrade);
}
}

View file

@ -1,5 +1,6 @@
package asgardius.page.r3forumtest;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
@ -10,6 +11,7 @@ import android.widget.EditText;
import android.widget.Toast;
import java.net.URL;
import java.util.Locale;
import javax.net.ssl.HttpsURLConnection;
@ -62,10 +64,10 @@ public class SignUp extends AppCompatActivity {
myConnection.setRequestMethod("POST");
// Create the data
myData = "{\n" +
"\"id\": \""+user.getText().toString()+"\",\n" +
"\"id\": \""+user.getText().toString().toLowerCase()+"\",\n" +
"\"firstname\": \""+fname.getText().toString()+"\",\n" +
"\"lastname\":\""+lname.getText().toString()+"\",\n" +
"\"email\":\""+mail.getText().toString()+"\",\n" +
"\"email\":\""+mail.getText().toString().toLowerCase()+"\",\n" +
"\"password\": \""+pwd.getText().toString()+"\",\n" +
"\"country\":\""+nacion.getText().toString()+"\",\n" +
"\"birthdate\": \""+datey.getText().toString()+"-"+datem.getText().toString()+"-"+dated.getText().toString()+"\"\n" +
@ -88,6 +90,7 @@ public class SignUp extends AppCompatActivity {
//Test
if (success) {
Toast.makeText(getApplicationContext(), "Registro exitoso", Toast.LENGTH_SHORT).show();
mainmenu();
} else {
Toast.makeText(getApplicationContext(), "El usuario ya existe", Toast.LENGTH_SHORT).show();
}
@ -104,7 +107,7 @@ public class SignUp extends AppCompatActivity {
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish();
//finish();
}
}
});
@ -114,4 +117,13 @@ public class SignUp extends AppCompatActivity {
}
});
}
private void mainmenu() {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
}

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/Theme.AppCompat"
android:background="@drawable/galaxy"
tools:context=".MainScreen">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bienvenido al foro"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="25sp" />
</LinearLayout>

View file

@ -16,6 +16,7 @@
android:autofillHints="username"
android:focusable="true"
android:hint="Nombre"
android:maxLength="30"
android:inputType="textNoSuggestions"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -28,6 +29,7 @@
android:autofillHints="username"
android:focusable="true"
android:hint="Apellido"
android:maxLength="30"
android:inputType="textNoSuggestions"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -40,6 +42,7 @@
android:autofillHints="username"
android:focusable="true"
android:hint="Nombre de usuario"
android:maxLength="15"
android:inputType="textNoSuggestions"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -52,6 +55,7 @@
android:autofillHints="emailAddress"
android:focusable="true"
android:hint="Correo Electronico"
android:maxLength="30"
android:inputType="textEmailAddress"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -64,6 +68,7 @@
android:autofillHints="username"
android:focusable="true"
android:hint="Contraseña"
android:maxLength="30"
android:inputType="textPassword"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -76,6 +81,7 @@
android:autofillHints="username"
android:focusable="true"
android:hint="Confirmar contraseña"
android:maxLength="30"
android:inputType="textPassword"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -87,6 +93,7 @@
android:layout_height="48dp"
android:focusable="true"
android:hint="Nacionalidad"
android:maxLength="30"
android:inputType="textNoSuggestions"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -116,6 +123,7 @@
android:layout_weight="1"
android:focusable="true"
android:hint="DD"
android:maxLength="2"
android:inputType="date"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -128,6 +136,7 @@
android:layout_weight="1"
android:focusable="true"
android:hint="MM"
android:maxLength="2"
android:inputType="date"
android:textColorHint="@color/white"
android:textColor="@color/white"
@ -140,6 +149,7 @@
android:layout_weight="1"
android:focusable="true"
android:hint="AAAA"
android:maxLength="4"
android:inputType="date"
android:textColorHint="@color/white"
android:textColor="@color/white"