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

> pass user preferences

parent c2ac6dc3
......@@ -60,13 +60,13 @@ public class AdminMenu extends AppCompatActivity {
}
if (temp.equals("")){
// dont add a '%' to the start
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
}
else{
temp += "%";
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
temp += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
temp += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
}
//Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_SHORT).show();
AlertDialog.Builder dataall = new AlertDialog.Builder(AdminMenu.this);
......@@ -144,6 +144,9 @@ public class AdminMenu extends AppCompatActivity {
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
if (temp.equals("")){
temp = "No user data";
}
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
......
......@@ -52,7 +52,7 @@ public class AdminRegister extends AppCompatActivity {
File file1;
String filename1 = "magicwords";
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);
String temp = "";
try{
......@@ -115,7 +115,7 @@ public class AdminRegister extends AppCompatActivity {
File file1;
String filename1 = "magicwords";
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);
String temp = "";
try{
......
......@@ -22,7 +22,7 @@ public class MainActivity extends AppCompatActivity {
// generic variables and stuff
int sizeoverride = 1000;
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;
boolean tempbool = true;
int tempint = 0;
......@@ -116,16 +116,16 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
}
public void saveandclose(){
try{
FileWriter stream = new FileWriter(file1, false);
stream.write(" ");
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_LONG).show();
}
}
// public void saveandclose(){
// try{
// FileWriter stream = new FileWriter(file1, false);
// stream.write(" ");
// stream.close();
//
// } catch(Exception e){
// Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_LONG).show();
// }
// }
/*public void openpage(View view,String destination){
destination += ".class";
......@@ -167,13 +167,13 @@ public class MainActivity extends AppCompatActivity {
// load successful
if (tempload.equals("")){
// dont add a '%' to the start
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
}
else{
tempload += "%";
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER";
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
}
String [] temploadarray = tempload.split("%");
size = temploadarray.length;
......@@ -182,10 +182,12 @@ public class MainActivity extends AppCompatActivity {
}
for (int i = 0; i < size; i++){
String [] sort = temploadarray [i].split("&");
magicwords [i] [1] = sort [0];
magicwords [i] [2] = sort [1];
magicwords [i] [3] = sort [2];
magicwords [i] [4] = sort [3];
magicwords [i] [1] = sort [0]; // name of user
magicwords [i] [2] = sort [1]; // username
magicwords [i] [3] = sort [2]; // password
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++){
if (magicwords [i] [0].equals("END")){
......@@ -220,13 +222,31 @@ public class MainActivity extends AppCompatActivity {
// login is verified
if (magicwords [i] [4].equals("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);
startActivity(intent);
return;
}
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);
startActivity(intent);
return;
......
......@@ -25,22 +25,22 @@ public class register_page extends AppCompatActivity {
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 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){
//
......@@ -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.hashCode() + "&USER";
String reassembly = name + "&" + user + "&" + pass.hashCode() + "&USER&£&ENG";
//System.out.println(reassembly);
String temp = "";
try{
......
......@@ -29,7 +29,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="wipealldialogboxopen"
android:text="Wipe user login file" />
android:text="Reset App" />
<Button
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