Commit 30b6f87e authored by chris.crook's avatar chris.crook

> added more admin functionality

parent 7db571c8
......@@ -9,7 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Summative_Chris_Crook">
<activity android:name=".AdminMenu"></activity>
<activity android:name=".AdminRegister"></activity>
<activity android:name=".AdminMenu" />
<activity android:name=".UserMenu" />
<activity android:name=".register_page" />
<activity android:name=".MainActivity">
......
......@@ -26,6 +26,11 @@ public class AdminMenu extends AppCompatActivity {
startActivity(intent);
}
public void register2electricboogaloo (View view){
Intent intent = new Intent(this,AdminRegister.class);
startActivity(intent);
}
public void ohhshiiiiii (View view){
// wipe the user login folder and reset it
File file1;
......@@ -55,15 +60,20 @@ public class AdminMenu extends AppCompatActivity {
}
if (temp.equals("")){
// dont add a '%' to the start
temp += "adminname&adminuser&adminpassword&ADMIN";
temp += "%examplename&exampleuser&examplepassword&USER";
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
}
else{
temp += "%";
temp += "adminname&adminuser&adminpassword&ADMIN";
temp += "%examplename&exampleuser&examplepassword&USER";
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
}
Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_SHORT).show();
AlertDialog.Builder dataall = new AlertDialog.Builder(AdminMenu.this);
dataall.setMessage(temp);
dataall.setTitle("User Data: ");
dataall.setNegativeButton("OK", null);
dataall.create().show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
......@@ -120,11 +130,29 @@ public class AdminMenu extends AppCompatActivity {
msgbox.setNegativeButton("Cancel", null);
msgbox.setNeutralButton("Display all login related data", new DialogInterface.OnClickListener() {
msgbox.setNeutralButton("Display all wipe-able data", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// display all data
disall();
// display all data in an alert box
File file1; // all this does is read the file and display it all
String filename1 = "magicwords";
String temp = "";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
try{
Scanner reader = new Scanner(file1);
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
//disall();
AlertDialog.Builder dataall = new AlertDialog.Builder(AdminMenu.this);
dataall.setMessage(temp);
dataall.setTitle("User Data: ");
dataall.setNegativeButton("OK", null);
dataall.create().show();
}
});
......
package com.example.summative_chris_crook;
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 AdminRegister extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_register);
}
public void goback (View view){
Intent intent = new Intent(this,AdminMenu.class);
startActivity(intent);
}
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();
return;
}
if (user.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Username", Toast.LENGTH_SHORT).show();
return;
}
if (pass.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Password", Toast.LENGTH_SHORT).show();
return;
}
if (conf.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Password (confirmation)", Toast.LENGTH_SHORT).show();
return;
}
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.hashCode() + "&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;
}
}
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 (name.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Name", Toast.LENGTH_SHORT).show();
return;
}
if (user.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Username", Toast.LENGTH_SHORT).show();
return;
}
if (pass.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Password", Toast.LENGTH_SHORT).show();
return;
}
if (conf.equals("")){
Toast.makeText(getApplicationContext(), "Enter a Password (confirmation)", Toast.LENGTH_SHORT).show();
return;
}
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.hashCode() + "&ADMIN";
//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(), "Admin 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
......@@ -167,13 +167,13 @@ public class MainActivity extends AppCompatActivity {
// load successful
if (tempload.equals("")){
// dont add a '%' to the start
tempload += "adminname&adminuser&adminpassword&ADMIN";
tempload += "%examplename&exampleuser&examplepassword&USER";
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
}
else{
tempload += "%";
tempload += "adminname&adminuser&adminpassword&ADMIN";
tempload += "%examplename&exampleuser&examplepassword&USER";
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
}
String [] temploadarray = tempload.split("%");
size = temploadarray.length;
......@@ -211,6 +211,7 @@ public class MainActivity extends AppCompatActivity {
Toast.makeText(getApplicationContext(), "Enter a valid Password", Toast.LENGTH_SHORT).show();
return;
}
epass = epass.hashCode() + "";
boolean wasthereausername = false;
for (int i = 0; i < sizeoverride; i++){
if (euser.equals(magicwords [i] [2])){
......
......@@ -69,7 +69,7 @@ public class register_page extends AppCompatActivity {
File file1;
String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
String reassembly = name + "&" + user + "&" + pass + "&USER";
String reassembly = name + "&" + user + "&" + pass.hashCode() + "&USER";
//System.out.println(reassembly);
String temp = "";
try{
......
......@@ -36,6 +36,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="displaythemagicwords"
android:text="Display magicwords.txt" />
android:text="Display all avaliable logins" />
<Button
android:id="@+id/button13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="register2electricboogaloo"
android:text="Register page (admin)" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".AdminRegister">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register user" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="goback"
android:text="Back to Admin menu" />
<TextView
android:id="@+id/textView10"
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/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Username:" />
<EditText
android:id="@+id/username_input2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Password:" />
<EditText
android:id="@+id/password_input2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="@+id/textView13"
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/button11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="createuser"
android:text="Create User Account" />
<Button
android:id="@+id/button12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="createadmin"
android:text="Create Admin Account" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -50,6 +50,13 @@
android:onClick="navigate"
android:text="register" />
<Button
android:id="@+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ohhshiiiiii"
android:text="Button" />
</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