Commit 7db571c8 authored by chris.crook's avatar chris.crook

> login system pretty much complete

parent 445bae67
package com.example.summative_chris_crook;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
......@@ -9,6 +11,7 @@ import android.widget.Toast;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class AdminMenu extends AppCompatActivity {
......@@ -38,4 +41,93 @@ public class AdminMenu extends AppCompatActivity {
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_SHORT).show();
}
}
public void displaythemagicwords (View view){
File file1; // all this does is read the file and display it all
String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
try{
Scanner reader = new Scanner(file1);
String temp = "";
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
if (temp.equals("")){
// dont add a '%' to the start
temp += "adminname&adminuser&adminpassword&ADMIN";
temp += "%examplename&exampleuser&examplepassword&USER";
}
else{
temp += "%";
temp += "adminname&adminuser&adminpassword&ADMIN";
temp += "%examplename&exampleuser&examplepassword&USER";
}
Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_SHORT).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
}
public void displaylogins (View view){
//
}
public void delall (){
// 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();
}
}
public void disall (){
File file1; // all this does is read the file and display it all
String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
try{
Scanner reader = new Scanner(file1);
String temp = "";
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_SHORT).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
}
public void wipealldialogboxopen (View view){
AlertDialog.Builder msgbox = new AlertDialog.Builder(this);
msgbox.setMessage("This action is not reversible");
msgbox.setTitle("Are you sure");
msgbox.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// delete all the data
delall();
}
});
msgbox.setNegativeButton("Cancel", null);
msgbox.setNeutralButton("Display all login related data", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// display all data
disall();
}
});
msgbox.create().show();
}
}
\ No newline at end of file
......@@ -50,15 +50,19 @@ public class register_page extends AppCompatActivity {
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
......@@ -79,10 +83,10 @@ public class register_page extends AppCompatActivity {
}
String write;
if (temp.equals("")){
write = "%" + reassembly;
write = reassembly;
}
else{
write = reassembly;
write = "%" + reassembly;
}
try{
FileWriter stream = new FileWriter(file1, true);
......
......@@ -28,7 +28,14 @@
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ohhshiiiiii"
android:onClick="wipealldialogboxopen"
android:text="Wipe user login file" />
<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="displaythemagicwords"
android:text="Display magicwords.txt" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -50,12 +50,6 @@
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
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