Commit 445bae67 authored by chris.crook's avatar chris.crook

> register page wip added

parent c6a84bce
......@@ -5,6 +5,10 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.io.FileWriter;
public class AdminMenu extends AppCompatActivity {
......@@ -18,4 +22,20 @@ public class AdminMenu extends AppCompatActivity {
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
public void ohhshiiiiii (View view){
// wipe the user login folder and reset it
File file1;
String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
try{
FileWriter stream = new FileWriter(file1, false);
stream.append("");
stream.close();
Toast.makeText(getApplicationContext(), "User Accounts Wiped, Admin and Default accounts only", Toast.LENGTH_SHORT).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_SHORT).show();
}
}
}
\ No newline at end of file
......@@ -166,7 +166,7 @@ public class MainActivity extends AppCompatActivity {
else{
// load successful
if (tempload.equals("")){
// dont add a '#' to the start
// dont add a '%' to the start
tempload += "adminname&adminuser&adminpassword&ADMIN";
tempload += "%examplename&exampleuser&examplepassword&USER";
}
......@@ -244,6 +244,21 @@ public class MainActivity extends AppCompatActivity {
}
}
}
public void ohhshiiiiii (View view){
// wipe the user login folder and reset it
File file1;
String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
try{
FileWriter stream = new FileWriter(file1, false);
stream.append("");
stream.close();
Toast.makeText(getApplicationContext(), "User Accounts Wiped, Admin and Default accounts only", Toast.LENGTH_SHORT).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_SHORT).show();
}
}
//
}
\ No newline at end of file
......@@ -5,6 +5,12 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class register_page extends AppCompatActivity {
......@@ -18,4 +24,80 @@ public class register_page extends AppCompatActivity {
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
public void createadmin (View view){
//
String name = ((EditText) findViewById(R.id.Name_input)).getText().toString();
String user = ((EditText) findViewById(R.id.Username_input)).getText().toString();
String pass = ((EditText) findViewById(R.id.Password_input)).getText().toString();
String conf = ((EditText) findViewById(R.id.Password_confirm)).getText().toString();
if (pass.equals(conf)){
//
String reassembly = "#" + name + "%" + user + "%" + pass + "%USER";
System.out.println(reassembly);
}
else{
Toast.makeText(getApplicationContext(), "The passwords do not match", Toast.LENGTH_SHORT).show();
return;
}
}
public void createuser (View view){
//
String name = ((EditText) findViewById(R.id.Name_input)).getText().toString();
String user = ((EditText) findViewById(R.id.Username_input)).getText().toString();
String pass = ((EditText) findViewById(R.id.Password_input)).getText().toString();
String conf = ((EditText) findViewById(R.id.Password_confirm)).getText().toString();
if (name.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Name", Toast.LENGTH_SHORT).show();
}
if (user.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Username", Toast.LENGTH_SHORT).show();
}
if (pass.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Password", Toast.LENGTH_SHORT).show();
}
if (conf.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Password (confirmation)", Toast.LENGTH_SHORT).show();
}
if (pass.equals(conf)){
// put all stuff together for saving to magicwords.txt
File file1;
String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
String reassembly = name + "&" + user + "&" + pass + "&USER";
//System.out.println(reassembly);
String temp = "";
try{
Scanner reader = new Scanner(file1);
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
} catch(Exception e){
Toast.makeText(getApplicationContext(), "File Error", Toast.LENGTH_SHORT).show();
}
String write;
if (temp.equals("")){
write = "%" + reassembly;
}
else{
write = reassembly;
}
try{
FileWriter stream = new FileWriter(file1, true);
stream.append(write);
stream.close();
Toast.makeText(getApplicationContext(), "User Account Created", Toast.LENGTH_LONG).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "Internal File Error", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(getApplicationContext(), "The passwords do not match", Toast.LENGTH_SHORT).show();
return;
}
}
}
\ No newline at end of file
......@@ -23,5 +23,12 @@
android:layout_height="wrap_content"
android:onClick="goback"
android:text="Log Out" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ohhshiiiiii"
android:text="Wipe user login file" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -49,6 +49,13 @@
android:layout_height="wrap_content"
android:onClick="navigate"
android:text="register" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ohhshiiiiii"
android:text="testing" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -23,5 +23,65 @@
android:layout_height="wrap_content"
android:onClick="goback"
android:text="Log in page" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Name:" />
<EditText
android:id="@+id/Name_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Username:" />
<EditText
android:id="@+id/Username_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Password:" />
<EditText
android:id="@+id/Password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirm Password:" />
<EditText
android:id="@+id/Password_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="createuser"
android:text="Create User Account" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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