在我的 iOS 应用中,我需要我的用户能够恢复/重置他们的密码。我正在使用 Drupal iOS SDK 来管理用户登录。一切正常,但是我想弄清楚如何将用户的电子邮件地址发布到服务端点以触发 drupal 密码恢复电子邮件? 例如 用户将电子邮件输入到 UITextField 中,然后点击提交按钮。但是,似乎没有任何相关文档?
代码如下 - 我只是不确定应该在 sendButton 中放入什么方法? DIOS用户? DIOSSession?
DIOSUser.m
+ (void)userSendPasswordRecoveryEmailWithEmailAddress: (NSString*)email
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
NSString *path = [NSString stringWithFormat:@"user/request_new_password/%@", email];
NSLog(@"This is the input email %@", email);
[[DIOSSession sharedSession] sendRequestWithPath:path method:@"POST" params:nil success:success failure:failure];
}
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.forgotField.returnKeyType = UIReturnKeyDone;
[self.forgotField setDelegate:self];
// Do any additional setup after loading the view from its nib.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
- (IBAction)return:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)sendButton:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Retrieving Password"
message:@"We're helping you retrieve your password! Please check your email in a few minutes for a rescue link."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
错误日志:
2017-07-12 22:29:34.264669-0700 myApp[4523:1331335]
----- DIOS Failure -----
Status code: 404
URL: http://url.com/endpoint01/user/request_new_password/me@email.com
----- Response -----
----- Error -----
Request failed: not found (404)
最佳答案
您应该简单地执行以下操作,假设 forgotField 将 emailID 作为输入并且您有适当的验证来检查有效的电子邮件。
- (IBAction)sendButton:(id)sender {
[DIOSUser userSendPasswordRecoveryEmailWithEmailAddress:self.forgotField.text
success:^(AFHTTPRequestOperation *operation, id responseObject) failure:^( AFHTTPRequestOperation *operation , NSError *error )){
if(!error){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Retrieving Password"
message:@"We're helping you retrieve your password! Please check your email in a few minutes for a rescue link."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}];
}
查找文档 here
干杯。
关于iOS - 触发来自 Drupal 的密码恢复电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42288049/