Hey guys im having a problem with part of my code for my application which is currently using Parse as the back end. Basically what i want to achieve is, if a user has a Role number of 1, send them to a specific page and if the user doesnt have a role or has a role number of 2 send them to different page.
the table in parse looks like this: http://gyazo.com/2895526c7a4473d21fabf8139a50f85a
Now i have heard of official implementation of roles with parse however im not to familiar with it and so i thought id approach this scenario a much simpler way.
The code i am trying to execute i shown below:
//set onclick listener
loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Retrieve the text entered from the EditText
userNameText = userName.getText().toString();
passwordText = password.getText().toString();
// Send data to Parse.com for verification
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("role", 1);
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> parseUsers, ParseException e) {
if (parseUsers != null){
//The Query was successful so execute the log in code
ParseUser.logInInBackground(userNameText, passwordText,
new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// If user exist and authenticated, send user to Welcome.class
Intent intent = new Intent(
LoginSignupActivity.this,
Welcome.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),
"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(
getApplicationContext(),
"No such user exist, please signup",
Toast.LENGTH_LONG).show();
}
}
});
} else {
// Send the user to the Normal_Welcome view, which is for normal clients
ParseUser.logInInBackground(userNameText, passwordText,
new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// If user exist and authenticated, send user to Welcome.class
Intent intent = new Intent(
LoginSignupActivity.this,
Normal_Welcome.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),
"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(
getApplicationContext(),
"No such user exist, please signup",
Toast.LENGTH_LONG).show();
}
}
});
}
}
});
0 comments:
Post a Comment