added admin welcome page
This commit is contained in:
parent
a76cced0fd
commit
5ebf406850
5 changed files with 101 additions and 5 deletions
|
@ -0,0 +1,39 @@
|
|||
package com.uottawa.olympus.olympusservices;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class AdminWelcome extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_admin_welcome);
|
||||
|
||||
DBHelper dbHelper = new DBHelper(this);
|
||||
List<String[]> users = dbHelper.getAllUsers();
|
||||
String[] usernames = new String[users.size()+1];
|
||||
String[] usertypes = new String[users.size()+1];
|
||||
usernames[0] = "Username";
|
||||
usertypes[0] = "User Type";
|
||||
Iterator iter = users.iterator();
|
||||
for (int i=0; i<users.size();i++){
|
||||
String[] current = (String[])iter.next();
|
||||
usernames[i+1] = current[0];
|
||||
usertypes[i+1] = current[3];
|
||||
}
|
||||
ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames);
|
||||
ListView listView = (ListView) findViewById(R.id.Users);
|
||||
listView.setAdapter(adapter);
|
||||
ArrayAdapter adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usertypes);
|
||||
ListView listView2 = (ListView) findViewById(R.id.Types);
|
||||
listView2.setAdapter(adapter2);
|
||||
|
||||
}
|
||||
}
|
|
@ -19,14 +19,21 @@ public class LogIn extends AppCompatActivity {
|
|||
String username = ((EditText) findViewById(R.id.UsernameInput)).getText().toString();
|
||||
String password = ((EditText) findViewById(R.id.PasswordInput)).getText().toString();
|
||||
DBHelper dbHelper = new DBHelper(this);
|
||||
Intent intent = new Intent(getApplicationContext(),Welcome.class);
|
||||
if(username.matches("[a-zA-Z0-9]*")&&password.matches("[a-zA-Z0-9]*")
|
||||
&& password.length()>0 && username.length()>0) {
|
||||
if (dbHelper.findUserByUsername(username) != null) {
|
||||
if (dbHelper.findUserByUsername(username).getUsername().equals(username) &&
|
||||
dbHelper.findUserByUsername(username).getPassword().equals(password)) {
|
||||
intent.putExtra("username", username);
|
||||
startActivity(intent);
|
||||
UserType user = dbHelper.findUserByUsername(username);
|
||||
if (user.getUsername().equals(username) &&
|
||||
user.getPassword().equals(password)) {
|
||||
if(user.getRole()=="Admin"){
|
||||
Intent intent = new Intent(getApplicationContext(),AdminWelcome.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
else {
|
||||
Intent intent = new Intent(getApplicationContext(),Welcome.class);
|
||||
intent.putExtra("username", username);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue