Commit f0bd4ef9 authored by chris.crook's avatar chris.crook

> pass user preferences

parent c2ac6dc3
...@@ -60,13 +60,13 @@ public class AdminMenu extends AppCompatActivity { ...@@ -60,13 +60,13 @@ public class AdminMenu extends AppCompatActivity {
} }
if (temp.equals("")){ if (temp.equals("")){
// dont add a '%' to the start // dont add a '%' to the start
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN"; temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER"; temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
} }
else{ else{
temp += "%"; temp += "%";
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN"; temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER"; temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
} }
//Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_SHORT).show();
AlertDialog.Builder dataall = new AlertDialog.Builder(AdminMenu.this); AlertDialog.Builder dataall = new AlertDialog.Builder(AdminMenu.this);
...@@ -144,6 +144,9 @@ public class AdminMenu extends AppCompatActivity { ...@@ -144,6 +144,9 @@ public class AdminMenu extends AppCompatActivity {
while (reader.hasNextLine()){ while (reader.hasNextLine()){
temp = temp + reader.nextLine(); temp = temp + reader.nextLine();
} }
if (temp.equals("")){
temp = "No user data";
}
} catch(Exception e){ } catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
} }
......
...@@ -52,7 +52,7 @@ public class AdminRegister extends AppCompatActivity { ...@@ -52,7 +52,7 @@ public class AdminRegister extends AppCompatActivity {
File file1; File file1;
String filename1 = "magicwords"; String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt"); file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
String reassembly = name + "&" + user + "&" + pass.hashCode() + "&USER"; String reassembly = name + "&" + user + "&" + pass.hashCode() + "&USER&£&ENG";
//System.out.println(reassembly); //System.out.println(reassembly);
String temp = ""; String temp = "";
try{ try{
...@@ -115,7 +115,7 @@ public class AdminRegister extends AppCompatActivity { ...@@ -115,7 +115,7 @@ public class AdminRegister extends AppCompatActivity {
File file1; File file1;
String filename1 = "magicwords"; String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt"); file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
String reassembly = name + "&" + user + "&" + pass.hashCode() + "&ADMIN"; String reassembly = name + "&" + user + "&" + pass.hashCode() + "&ADMIN&£&ENG";
//System.out.println(reassembly); //System.out.println(reassembly);
String temp = ""; String temp = "";
try{ try{
......
...@@ -22,7 +22,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -22,7 +22,7 @@ public class MainActivity extends AppCompatActivity {
// generic variables and stuff // generic variables and stuff
int sizeoverride = 1000; int sizeoverride = 1000;
String tempload = ""; String tempload = "";
String [] [] magicwords = new String [sizeoverride] [5]; // storage of the login info String [] [] magicwords = new String [sizeoverride] [7]; // storage of the login info
int size = 0; int size = 0;
boolean tempbool = true; boolean tempbool = true;
int tempint = 0; int tempint = 0;
...@@ -116,16 +116,16 @@ public class MainActivity extends AppCompatActivity { ...@@ -116,16 +116,16 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
public void saveandclose(){ // public void saveandclose(){
try{ // try{
FileWriter stream = new FileWriter(file1, false); // FileWriter stream = new FileWriter(file1, false);
stream.write(" "); // stream.write(" ");
stream.close(); // stream.close();
//
} catch(Exception e){ // } catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_LONG).show(); // Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_LONG).show();
} // }
} // }
/*public void openpage(View view,String destination){ /*public void openpage(View view,String destination){
destination += ".class"; destination += ".class";
...@@ -167,13 +167,13 @@ public class MainActivity extends AppCompatActivity { ...@@ -167,13 +167,13 @@ public class MainActivity extends AppCompatActivity {
// load successful // load successful
if (tempload.equals("")){ if (tempload.equals("")){
// dont add a '%' to the start // dont add a '%' to the start
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN"; tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER"; tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
} }
else{ else{
tempload += "%"; tempload += "%";
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN"; tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER"; tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
} }
String [] temploadarray = tempload.split("%"); String [] temploadarray = tempload.split("%");
size = temploadarray.length; size = temploadarray.length;
...@@ -182,10 +182,12 @@ public class MainActivity extends AppCompatActivity { ...@@ -182,10 +182,12 @@ public class MainActivity extends AppCompatActivity {
} }
for (int i = 0; i < size; i++){ for (int i = 0; i < size; i++){
String [] sort = temploadarray [i].split("&"); String [] sort = temploadarray [i].split("&");
magicwords [i] [1] = sort [0]; magicwords [i] [1] = sort [0]; // name of user
magicwords [i] [2] = sort [1]; magicwords [i] [2] = sort [1]; // username
magicwords [i] [3] = sort [2]; magicwords [i] [3] = sort [2]; // password
magicwords [i] [4] = sort [3]; magicwords [i] [4] = sort [3]; // admin flag
magicwords [i] [5] = sort [4]; // currency mode
magicwords [i] [6] = sort [5]; // language
} }
for (int i = 0; i < sizeoverride; i++){ for (int i = 0; i < sizeoverride; i++){
if (magicwords [i] [0].equals("END")){ if (magicwords [i] [0].equals("END")){
...@@ -220,13 +222,31 @@ public class MainActivity extends AppCompatActivity { ...@@ -220,13 +222,31 @@ public class MainActivity extends AppCompatActivity {
// login is verified // login is verified
if (magicwords [i] [4].equals("ADMIN")){ if (magicwords [i] [4].equals("ADMIN")){
// user is an admin // user is an admin
Toast.makeText(getApplicationContext(), "Signed in as admin", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Signed in as " + magicwords [i] [1] + " (admin)", Toast.LENGTH_SHORT).show();
String writetotemp = magicwords [i] [1] + "&" + magicwords [i] [4] + "&" + magicwords [i] [5];
Toast.makeText(getApplicationContext(), "Admin preferences loaded: " + writetotemp, Toast.LENGTH_SHORT).show();
try{
FileWriter stream = new FileWriter(file2, false);
stream.append(writetotemp);
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "Internal File Error", Toast.LENGTH_LONG).show();
}
Intent intent = new Intent(this,AdminMenu.class); Intent intent = new Intent(this,AdminMenu.class);
startActivity(intent); startActivity(intent);
return; return;
} }
else{ else{
Toast.makeText(getApplicationContext(), "Signed in as user", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Signed in as " + magicwords [i] [1], Toast.LENGTH_SHORT).show();
String writetotemp = magicwords [i] [1] + "&" + magicwords [i] [4] + "&" + magicwords [i] [5];
Toast.makeText(getApplicationContext(), "User preferences loaded: " + writetotemp, Toast.LENGTH_SHORT).show();
try{
FileWriter stream = new FileWriter(file2, false);
stream.append(writetotemp);
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "Internal File Error", Toast.LENGTH_LONG).show();
}
Intent intent = new Intent(this,UserMenu.class); Intent intent = new Intent(this,UserMenu.class);
startActivity(intent); startActivity(intent);
return; return;
......
...@@ -25,22 +25,22 @@ public class register_page extends AppCompatActivity { ...@@ -25,22 +25,22 @@ public class register_page extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
public void createadmin (View view){ // public void createadmin (View view){
// // //
String name = ((EditText) findViewById(R.id.Name_input)).getText().toString(); // String name = ((EditText) findViewById(R.id.Name_input)).getText().toString();
String user = ((EditText) findViewById(R.id.Username_input)).getText().toString(); // String user = ((EditText) findViewById(R.id.Username_input)).getText().toString();
String pass = ((EditText) findViewById(R.id.Password_input)).getText().toString(); // String pass = ((EditText) findViewById(R.id.Password_input)).getText().toString();
String conf = ((EditText) findViewById(R.id.Password_confirm)).getText().toString(); // String conf = ((EditText) findViewById(R.id.Password_confirm)).getText().toString();
if (pass.equals(conf)){ // if (pass.equals(conf)){
// // //
String reassembly = "#" + name + "%" + user + "%" + pass + "%USER"; // String reassembly = "#" + name + "%" + user + "%" + pass + "%USER";
System.out.println(reassembly); // System.out.println(reassembly);
} // }
else{ // else{
Toast.makeText(getApplicationContext(), "The passwords do not match", Toast.LENGTH_SHORT).show(); // Toast.makeText(getApplicationContext(), "The passwords do not match", Toast.LENGTH_SHORT).show();
return; // return;
} // }
} // }
public void createuser (View view){ public void createuser (View view){
// //
...@@ -69,7 +69,7 @@ public class register_page extends AppCompatActivity { ...@@ -69,7 +69,7 @@ public class register_page extends AppCompatActivity {
File file1; File file1;
String filename1 = "magicwords"; String filename1 = "magicwords";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt"); file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
String reassembly = name + "&" + user + "&" + pass.hashCode() + "&USER"; String reassembly = name + "&" + user + "&" + pass.hashCode() + "&USER&£&ENG";
//System.out.println(reassembly); //System.out.println(reassembly);
String temp = ""; String temp = "";
try{ try{
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="wipealldialogboxopen" android:onClick="wipealldialogboxopen"
android:text="Wipe user login file" /> android:text="Reset App" />
<Button <Button
android:id="@+id/button9" android:id="@+id/button9"
......
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