In my iOS app, I need my users to be able to recover/reset their passwords. I'm using the Drupal iOS SDK in order to manage user login. Everything works, however I'm trying to figure out how to post the user's email address to the services end point in order to trigger the drupal password recovery email? E.g. user inputs email into UITextField, and taps a submit button. However there doesn't seem to be any documentation for this?
Code is as follows - I'm just not sure what method I should put inside of my sendButton? DIOSUser? 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]; }
Error log:
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)
2 Answers
Answers 1
You should simply do the following, assuming forgotField takes emailID as input and you have proper validation to check valid email.
- (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]; } }]; }
Find the documentation here
Cheers.
Answers 2
You can send reset request using below code :
- (IBAction)sendButton:(id)sender { [DIOSUser userSendPasswordRecoveryEmailWithEmailAddress:self.txtForgotPassword.text success:^(AFHTTPRequestOperation *operation, id responseObject) { // Success Block UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Retrieving Password" message:@"We have send you reset link to your email Please check your email." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }failure:^( AFHTTPRequestOperation *operation , NSError *error ){ // Failure Block if(!error){ // error.description UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oopss" message: error.description delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } }]; }
I hope this will help you .
0 comments:
Post a Comment