account edit

This commit is contained in:
Page Asgardius 2022-10-13 11:29:04 -07:00
parent d39a7d3480
commit 23336e07ad
11 changed files with 516 additions and 11 deletions

View file

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

View file

@ -0,0 +1,106 @@
package asgardius.page.r3forumtest;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class AccountDel extends AppCompatActivity {
EditText user;
Button delAccount;
boolean success;
HttpsURLConnection myConnection;
URL endpoint;
String myData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_del);
user = (EditText)findViewById(R.id.username);
delAccount = (Button)findViewById(R.id.delete);
delAccount.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
if(user.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(),"Seleccione un usuario", Toast.LENGTH_SHORT).show();
}else {
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/delete.php");
myConnection = (HttpsURLConnection) endpoint.openConnection();
myConnection.setRequestProperty("User-Agent", "r3-forum-test");
myConnection.setRequestMethod("POST");
// Create the data
myData = "{\n" +
"\"id\": \""+user.getText().toString().toLowerCase()+"\"\n" +
"}";
// Enable writing
myConnection.setDoOutput(true);
// Write the data
myConnection.getOutputStream().write(myData.getBytes());
System.out.println(myConnection.getResponseCode());
if (myConnection.getResponseCode() == 200) {
success = true;
} else {
success = false;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
//Test
if (success) {
Toast.makeText(getApplicationContext(), "Usuario eliminado", Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(getApplicationContext(), "Usuario inexistente", 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();
}
}
});
login.start();
}
}
});
}
private void mainMenu() {
Intent intent = new Intent(this, MainScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
}

View file

@ -0,0 +1,138 @@
package asgardius.page.r3forumtest;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class AccountEdit extends AppCompatActivity {
Button editUser;
EditText user, pwd, pwdc, nacion, fname, lname, mail, dated, datem, datey;
@SuppressLint("UseSwitchCompatOrMaterialCode")
Switch setAdmin;
URL endpoint;
HttpsURLConnection myConnection;
boolean success;
String myData, permission;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_edit);
user = (EditText)findViewById(R.id.username);
pwd = (EditText)findViewById(R.id.password);
pwdc = (EditText)findViewById(R.id.passwordConfirm);
nacion = (EditText)findViewById(R.id.nacionalidad);
fname = (EditText)findViewById(R.id.firstname);
mail = (EditText)findViewById(R.id.email);
dated = (EditText)findViewById(R.id.Date);
datem = (EditText)findViewById(R.id.Month);
datey = (EditText)findViewById(R.id.Year);
lname = (EditText)findViewById(R.id.lastname);
setAdmin = (Switch)findViewById(R.id.permission);
editUser = (Button)findViewById(R.id.edituser);
editUser.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
if(user.getText().toString().equals("") || pwd.getText().toString().equals("") ||
pwdc.getText().toString().equals("") || nacion.getText().toString().equals("") ||
fname.getText().toString().equals("") || lname.getText().toString().equals("") ||
mail.getText().toString().equals("") || dated.getText().toString().equals("") ||
datem.getText().toString().equals("") || datey.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(),"Todos los campos son obligatorios", Toast.LENGTH_SHORT).show();
} else if(!pwd.getText().toString().equals(pwdc.getText().toString())) {
Toast.makeText(getApplicationContext(),"Las contraseñas no coinciden", Toast.LENGTH_SHORT).show();
}else {
Thread login = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
if(setAdmin.isChecked()) {
permission = "admin";
} else {
permission = "user";
}
endpoint = new URL("https://desktop.asgardius.company/test/restful/items/update.php");
myConnection = (HttpsURLConnection) endpoint.openConnection();
myConnection.setRequestProperty("User-Agent", "r3-forum-test");
myConnection.setRequestMethod("POST");
// Create the data
myData = "{\n" +
"\"id\": \""+user.getText().toString().toLowerCase()+"\",\n" +
"\"firstname\": \""+fname.getText().toString()+"\",\n" +
"\"lastname\":\""+lname.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" +
"\"permission\":\""+permission+"\"\n" +
"}";
// Enable writing
myConnection.setDoOutput(true);
// Write the data
myConnection.getOutputStream().write(myData.getBytes());
System.out.println(myConnection.getResponseCode());
if (myConnection.getResponseCode() == 200) {
success = true;
} else {
success = false;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
//Test
if (success) {
Toast.makeText(getApplicationContext(), "Datos actualizados", Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(getApplicationContext(), "Usuario invalido", 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();
}
}
});
login.start();
}
}
});
}
private void mainMenu() {
Intent intent = new Intent(this, MainScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
}

View file

@ -12,9 +12,6 @@ import android.widget.EditText;
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;
@ -50,7 +47,7 @@ public class MainActivity extends AppCompatActivity {
}
user = (EditText)findViewById(R.id.username);
pwd = (EditText)findViewById(R.id.password);
signUp = (Button)findViewById(R.id.signup);
signUp = (Button)findViewById(R.id.delete);
login = (Button)findViewById(R.id.login);
signUp.setOnClickListener(new View.OnClickListener(){
@Override

View file

@ -67,6 +67,7 @@ public class MainScreen extends AppCompatActivity {
try {
//Your code goes here
endpoint = new URL("https://desktop.asgardius.company/test/restful/items/read.php");
//System.out.println(endpoint);
myConnection = (HttpsURLConnection) endpoint.openConnection();
myConnection.setRequestProperty("User-Agent", "r3-forum-test");
myConnection.setRequestMethod("POST");
@ -87,7 +88,7 @@ public class MainScreen extends AppCompatActivity {
while ((output = br.readLine()) != null) {
sb.append(output);
}
System.out.println(sb.toString());
//System.out.println(sb.toString());
jsonObj = new JSONObject(sb.toString());
} else {
success = false;
@ -200,14 +201,16 @@ public class MainScreen extends AppCompatActivity {
@Override
public void onClick(View view) {
//buttonaction
Toast.makeText(getApplicationContext(),"editar", Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(),"editar", Toast.LENGTH_SHORT).show();
accountEdit();
}
});
delete.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
Toast.makeText(getApplicationContext(),"eliminar", Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(),"eliminar", Toast.LENGTH_SHORT).show();
accountDelete();
}
});
}
@ -221,6 +224,20 @@ public class MainScreen extends AppCompatActivity {
}
private void accountEdit() {
Intent intent = new Intent(this, AccountEdit.class);
startActivity(intent);
}
private void accountDelete() {
Intent intent = new Intent(this, AccountDel.class);
startActivity(intent);
}
public void onBackPressed(){
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);

View file

@ -36,7 +36,7 @@ public class SignUp extends AppCompatActivity {
datem = (EditText)findViewById(R.id.Month);
datey = (EditText)findViewById(R.id.Year);
lname = (EditText)findViewById(R.id.lastname);
signUp = (Button)findViewById(R.id.signup);
signUp = (Button)findViewById(R.id.signUp);
signUp.setOnClickListener(new View.OnClickListener(){
@Override

View file

@ -0,0 +1,45 @@
<?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:background="@drawable/galaxy"
android:orientation="vertical"
android:theme="@style/Theme.AppCompat"
tools:context=".AccountDel">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="48dp"
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"
tools:ignore="MissingConstraints" />
<LinearLayout
android:id="@+id/linearLayoutSubmit"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="20dp"
android:orientation="horizontal"
tools:layout_editor_absoluteX="20dp">
<Button
android:id="@+id/delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:backgroundTint="@color/black"
android:text="Eliminar"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,188 @@
<?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:background="@drawable/galaxy"
android:orientation="vertical"
android:theme="@style/Theme.AppCompat"
tools:context=".AccountEdit">
<EditText
android:id="@+id/firstname"
android:layout_width="match_parent"
android:layout_height="48dp"
android:autofillHints="username"
android:focusable="true"
android:hint="Nombre"
android:maxLength="30"
android:inputType="textNoSuggestions"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/lastname"
android:layout_width="match_parent"
android:layout_height="48dp"
android:autofillHints="username"
android:focusable="true"
android:hint="Apellido"
android:maxLength="30"
android:inputType="textNoSuggestions"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="48dp"
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"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="48dp"
android:autofillHints="emailAddress"
android:focusable="true"
android:hint="Correo Electronico"
android:maxLength="30"
android:inputType="textEmailAddress"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="48dp"
android:autofillHints="username"
android:focusable="true"
android:hint="Contraseña"
android:maxLength="30"
android:inputType="textPassword"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/passwordConfirm"
android:layout_width="match_parent"
android:layout_height="48dp"
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"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/nacionalidad"
android:layout_width="match_parent"
android:layout_height="48dp"
android:focusable="true"
android:hint="Nacionalidad"
android:maxLength="30"
android:inputType="textNoSuggestions"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fecha de nacimiento"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/linearLayoutDate"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="20dp"
android:orientation="horizontal"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<EditText
android:id="@+id/Date"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="DD"
android:maxLength="2"
android:inputType="date"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/Month"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="MM"
android:maxLength="2"
android:inputType="date"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/Year"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="AAAA"
android:maxLength="4"
android:inputType="date"
android:textColorHint="@color/white"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutSubmit"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="20dp"
android:orientation="horizontal"
tools:ignore="MissingConstraints,UseSwitchCompatOrMaterialXml"
tools:layout_editor_absoluteX="20dp">
<Switch
android:id="@+id/permission"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Administrador" />
<Button
android:id="@+id/edituser"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:backgroundTint="@color/black"
android:text="Guardar cambios"
android:textColor="@color/white"
tools:ignore="MissingConstraints" />
</LinearLayout>
</LinearLayout>

View file

@ -69,7 +69,7 @@
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/signup"
android:id="@+id/delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"

View file

@ -167,7 +167,7 @@
tools:layout_editor_absoluteX="20dp">
<Button
android:id="@+id/signup"
android:id="@+id/signUp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"

View file

@ -66,7 +66,7 @@
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/signup"
android:id="@+id/delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"