fixed security of users

This commit is contained in:
IvanaE 2018-10-23 17:16:18 -04:00
parent 27bc56bc7f
commit 2002092458
8 changed files with 67 additions and 19 deletions

View file

@ -16,7 +16,7 @@
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name=".Main" android:name=".Main"
android:label="@string/app_name"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -30,14 +30,13 @@
<activity <activity
android:name=".SignUp" android:name=".SignUp"
android:parentActivityName=".Main"> android:screenOrientation="portrait"/>
<meta-data <activity android:name=".LogIn"
android:name="android.support.PARENT_ACTIVITY" android:screenOrientation="portrait"/>
android:value=".Main" /> <activity android:name=".Welcome"
</activity> android:screenOrientation="portrait"/>
<activity android:name=".LogIn" /> <activity android:name=".AdminWelcome"
<activity android:name=".Welcome" /> android:screenOrientation="portrait"/>
<activity android:name=".AdminWelcome"></activity>
</application> </application>
</manifest> </manifest>

View file

@ -1,5 +1,6 @@
package com.uottawa.olympus.olympusservices; package com.uottawa.olympus.olympusservices;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
@ -34,4 +35,13 @@ public class AdminWelcome extends AppCompatActivity {
gridView.setAdapter(adapter); gridView.setAdapter(adapter);
} }
@Override
public void onBackPressed(){
}
public void LogOut(View view){
Intent intent = new Intent(getApplicationContext(), Main.class);
startActivity(intent);
finish();
}
} }

View file

@ -28,11 +28,13 @@ public class LogIn extends AppCompatActivity {
if(user.getRole()=="Admin"){ if(user.getRole()=="Admin"){
Intent intent = new Intent(getApplicationContext(),AdminWelcome.class); Intent intent = new Intent(getApplicationContext(),AdminWelcome.class);
startActivity(intent); startActivity(intent);
finish();
} }
else { else {
Intent intent = new Intent(getApplicationContext(),Welcome.class); Intent intent = new Intent(getApplicationContext(),Welcome.class);
intent.putExtra("username", username); intent.putExtra("username", username);
startActivity(intent); 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();
}

View file

@ -20,13 +20,15 @@ public class Main extends AppCompatActivity {
public void onClickSignUp(View view){ public void onClickSignUp(View view){
Intent intent = new Intent(getApplicationContext(),SignUp.class); Intent intent = new Intent(getApplicationContext(),SignUp.class);
startActivityForResult(intent,0); startActivity(intent);
finish();
} }
public void onClickLogIn(View view){ public void onClickLogIn(View view){
Intent intent = new Intent(getApplicationContext(),LogIn.class); Intent intent = new Intent(getApplicationContext(),LogIn.class);
startActivityForResult(intent,0); startActivity(intent);
finish();
} }
} }

View file

@ -22,6 +22,7 @@ public class SignUp extends AppCompatActivity {
Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show();
} }
}); });
} }
public void onClickSignUp(View view){ public void onClickSignUp(View view){
@ -33,7 +34,7 @@ public class SignUp extends AppCompatActivity {
MaterialSpinner spinner = findViewById(R.id.RoleInput); MaterialSpinner spinner = findViewById(R.id.RoleInput);
//TODO add message conditional to check if every EditText is filled up to standards //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]*") 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()){ switch(spinner.getText().toString()){
case "User": case "User":
newUser = new User(username,password,firstname,lastname); newUser = new User(username,password,firstname,lastname);
@ -50,7 +51,8 @@ public class SignUp extends AppCompatActivity {
DBHelper dbHelper = new DBHelper(this); 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 Intent intent = new Intent(getApplicationContext(),LogIn.class); //TODO check if signup should take to the login page or automatically login
if(dbHelper.addUser(newUser)){ if(dbHelper.addUser(newUser)){
startActivityForResult(intent,0); startActivity(intent);
finish();
}else{ }else{
Toast.makeText(this,"Username is taken",Toast.LENGTH_LONG).show(); 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(); Toast.makeText(this, "Fields cannot be empty", Toast.LENGTH_LONG).show();
} }
else if (username.length()<=5 || password.length()<=5 ){ 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{ else{
Toast.makeText(this, "Fields may only contain alphanumeric values", Toast.LENGTH_LONG).show(); 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();
} }

View file

@ -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();
}
} }

View file

@ -24,21 +24,28 @@
android:textSize="20sp" android:textSize="20sp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
app:fontFamily="@font/julius_sans_one" /> app:fontFamily="@font/julius_sans_one" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<GridView <GridView
android:id="@+id/Users" android:id="@+id/Users"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_weight="1" android:layout_weight="1"
android:layout_height="match_parent" android:layout_height="250dp"
android:numColumns="2" android:numColumns="2"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<Button
android:id="@+id/LogOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:onClick="LogOut"
android:text="Logout"
android:theme="@style/AppTheme.Button" />
</LinearLayout> </LinearLayout>

View file

@ -63,5 +63,13 @@
android:background="@drawable/customborder" android:background="@drawable/customborder"
android:textSize="20sp" android:textSize="20sp"
app:fontFamily="@font/julius_sans_one" /> app:fontFamily="@font/julius_sans_one" />
<Button
android:id="@+id/LogOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:onClick="LogOut"
android:text="Logout"
android:theme="@style/AppTheme.Button" />
</LinearLayout> </LinearLayout>