Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Steven Rayzman
2,423 PointsGroups
I want to add users to one of two groups. Faculty group 1 and faculty group 2. They are added based on wether they entered the correct code in the log in process. How would I do this, and then determine if a user is part of a particular group.
1 Answer
Stone Preston
42,016 Pointswhen they login compare the code they entered to the correct code. if its correct, set that users group to 1, else set it to 2
//log the user in
[PFUser logInWithUsernameInBackground:username password:password
block:^(PFUser *user, NSError *error) {
if (user) {
// Do stuff after successful login.
[self.navigationController popToRootViewControllerAnimated:YES];
//compare the code in the textField
if ([self.codeTextField.text isEqualToString:@"1234"]) {
user[@"group"] = 1;
} else {
user[@"group"] = 2;
}
//save the user after modifying it
[user saveInBackground];
} else {
// The login failed. Check error to see why.
NSString *errorString = [error userInfo][@"error"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
}
}];