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

View file

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

View file

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

View file

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

View file

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

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:layout_marginTop="10dp"
app:fontFamily="@font/julius_sans_one" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<GridView
android:id="@+id/Users"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_height="250dp"
android:numColumns="2"
android:textColor="@android:color/white"
android:textSize="15sp" />
</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>

View file

@ -63,5 +63,13 @@
android:background="@drawable/customborder"
android:textSize="20sp"
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>