我已经重新设置了密码,但仍需要更多密码。我的意思是,如果用户向文本字段添加电子邮件并按下发送按钮,则如果它等于Parse上的用户名,则会返回警报。如果没有,请显示警报。有任何想法吗? 谢谢
ForgottenViewController.h
-(IBAction)logoutPressed:(id)sender;
@property(nonatomic, strong) IBOutlet UITextField *maill;
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *activityLog;
@end
ForgottenViewController.m
#import "ForgottenViewController.h"
#import "SignUpViewController.h"
@interface ForgottenViewController ()
@end
@implementation ForgottenViewController
@synthesize maill;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)logoutPressed:(id)sender {
PFQuery *query=[PFUser query];
[query whereKey:@"username" equalTo:maill];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (object) {
NSString *myString = maill.text;
[PFUser requestPasswordResetForEmailInBackground:myString];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Great" message:@"Now check your email. You will be able to change your password right now." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[_activityLog stopAnimating];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Sorry, but the email is not registred." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[_activityLog stopAnimating];
}
}];}
@end
答案 0 :(得分:3)
对于Android用户:如果有人遇到同样的问题
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("email", "demo11@gmail.com");
query.countInBackground(new CountCallback(){
@Override
public void done(int count, ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
if(count==0){
//Username doesnt exit
}
}
}
});
答案 1 :(得分:1)
问题很可能是whereKey搜索区分大小写。确保您完全按照存储方式输入电子邮件。 Parse建议您在这种情况下使用规范字段,在这种情况下,您将电子邮件全部小写,并将单独的电子邮件存储给用户。
我应该第一次看到这个。变量mail
是UITextField而不是NSString。尝试将mail.text
而非mail
传递给查询。