I'm trying to POST an email address to the password_reset Services endpoint so that it generates and sends a password reset email for a user. When I post the uid to the endpoint, it does this successfully. That said, I want to post the user's email to the endpoint (e.g. they type in their email to retrieve their password recovery email). How can I change the below in order to allow this? I tried changing user_load($uid) to user_load_by_mail($uid), but this didn't work.
Endpoint format:
mydomain.com/myendpoint/user/[email protected]/password_reset_email
user_resource.inc
$definition = array(
'user' => array(
'operations' => array(
'actions' => array(
'help' => 'Send forgot password email',
'callback' => '_user_resource_password_reset_email',
'access callback' => 'services_access_menu',
'args' => array(
array(
'name' => 'email',
'optional' => FALSE,
'source' => array('data' => 'email'),
'type' => 'string',
'description' => 'The email address of the user whose password should be reset.',
),
),
),
),
),
),
function _user_resource_password_reset_email($data) {
global $language;
$mail = _services_arg_value($data, 'data');
$account = user_load_by_mail($mail);
if (empty($account)) {
return services_error(t('There is no user with email @email.', array('@email' => $mail)), 404);
}
// Mail one time login URL and instructions using current language.
$mail = _user_mail_notify('password_reset_email', $account, $language);
if (!empty($mail)) {
watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail));
}
else {
watchdog('user', 'There was an error re-sending password reset instructions mailed to %name at %email', array('%name' => $account->name, '%email' => $account->mail));
}
$result = "success";
return $result;
}
Obj-C
ViewController.m
- (IBAction)sendButton:(id)sender {
[DIOSUser userSendPasswordRecoveryEmailWithEmailAddress:self.forgotField.text
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Password being sent!");
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];
}failure:^( AFHTTPRequestOperation *operation , NSError *error ){
if(!error){
}
}];
}
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];
[[DIOSSession sharedSession] sendRequestWithPath:path method:@"POST" params:nil success:success failure:failure];
}