From 2002092458573b262eaf61f3e28274eb6e3d21fa Mon Sep 17 00:00:00 2001 From: IvanaE Date: Tue, 23 Oct 2018 17:16:18 -0400 Subject: [PATCH] fixed security of users --- .../app/src/main/AndroidManifest.xml | 17 ++++++++--------- .../olympus/olympusservices/AdminWelcome.java | 10 ++++++++++ .../uottawa/olympus/olympusservices/LogIn.java | 8 ++++++++ .../uottawa/olympus/olympusservices/Main.java | 6 ++++-- .../uottawa/olympus/olympusservices/SignUp.java | 16 +++++++++++----- .../olympus/olympusservices/Welcome.java | 8 ++++++++ .../main/res/layout/activity_admin_welcome.xml | 13 ++++++++++--- .../src/main/res/layout/activity_welcome.xml | 8 ++++++++ 8 files changed, 67 insertions(+), 19 deletions(-) diff --git a/OlympusServices/app/src/main/AndroidManifest.xml b/OlympusServices/app/src/main/AndroidManifest.xml index 4b9d4cb..5b8f51e 100644 --- a/OlympusServices/app/src/main/AndroidManifest.xml +++ b/OlympusServices/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ android:theme="@style/AppTheme"> + android:screenOrientation="portrait"> @@ -30,14 +30,13 @@ - - - - - + android:screenOrientation="portrait"/> + + + \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java index 4500309..3b2ee4a 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java @@ -1,5 +1,6 @@ package com.uottawa.olympus.olympusservices; +import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; @@ -34,4 +35,13 @@ public class AdminWelcome extends AppCompatActivity { gridView.setAdapter(adapter); } + @Override + public void onBackPressed(){ + } + + public void LogOut(View view){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java index 608ee97..6afde1a 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java @@ -28,11 +28,13 @@ public class LogIn extends AppCompatActivity { if(user.getRole()=="Admin"){ Intent intent = new Intent(getApplicationContext(),AdminWelcome.class); startActivity(intent); + finish(); } else { Intent intent = new Intent(getApplicationContext(),Welcome.class); intent.putExtra("username", username); startActivity(intent); + finish(); } @@ -52,6 +54,12 @@ public class LogIn extends AppCompatActivity { } + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java index 052038a..6245cb1 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java @@ -20,13 +20,15 @@ public class Main extends AppCompatActivity { public void onClickSignUp(View view){ Intent intent = new Intent(getApplicationContext(),SignUp.class); - startActivityForResult(intent,0); + startActivity(intent); + finish(); } public void onClickLogIn(View view){ Intent intent = new Intent(getApplicationContext(),LogIn.class); - startActivityForResult(intent,0); + startActivity(intent); + finish(); } } \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java index a009f14..11d52cc 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java @@ -22,6 +22,7 @@ public class SignUp extends AppCompatActivity { Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show(); } }); + } public void onClickSignUp(View view){ @@ -33,7 +34,7 @@ public class SignUp extends AppCompatActivity { MaterialSpinner spinner = findViewById(R.id.RoleInput); //TODO add message conditional to check if every EditText is filled up to standards if(username.length()>=5 && password.length()>5 && firstname.length()>0 && lastname.length()>0 && username.matches("[a-zA-Z0-9]*") && password.matches("[a-zA-Z0-9]*") - && firstname.matches("[a-zA-Z0-9]*") && lastname.matches("[a-zA-Z0-9]*")){ + && firstname.matches("[a-zA-Z]*") && lastname.matches("[a-zA-Z]*")){ switch(spinner.getText().toString()){ case "User": newUser = new User(username,password,firstname,lastname); @@ -50,7 +51,8 @@ public class SignUp extends AppCompatActivity { DBHelper dbHelper = new DBHelper(this); Intent intent = new Intent(getApplicationContext(),LogIn.class); //TODO check if signup should take to the login page or automatically login if(dbHelper.addUser(newUser)){ - startActivityForResult(intent,0); + startActivity(intent); + finish(); }else{ Toast.makeText(this,"Username is taken",Toast.LENGTH_LONG).show(); } @@ -59,13 +61,17 @@ public class SignUp extends AppCompatActivity { Toast.makeText(this, "Fields cannot be empty", Toast.LENGTH_LONG).show(); } else if (username.length()<=5 || password.length()<=5 ){ - Toast.makeText(this, "Password and username must be longer than 5 characters", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "Password and username must be longer than 4 characters", Toast.LENGTH_LONG).show(); } else{ Toast.makeText(this, "Fields may only contain alphanumeric values", Toast.LENGTH_LONG).show(); } - - + } + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java index 8759055..4389f62 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java @@ -24,6 +24,14 @@ public class Welcome extends AppCompatActivity { } + @Override + public void onBackPressed(){ + } + public void LogOut(View view){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } } diff --git a/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml b/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml index 88468cf..6aef240 100644 --- a/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml +++ b/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml @@ -24,21 +24,28 @@ android:textSize="20sp" android:layout_marginTop="10dp" app:fontFamily="@font/julius_sans_one" /> - +