resetPassword static method
Uses reset_password.pl to send a password reset Email needs only Returns Status.status 200 = complete; 400 = wrong inputs or other error + Status.error; 500 = server error;
Implementation
static Future<Status> resetPassword(
String emailOrUserID, {
QueryType? queryType,
}) async {
var passwordResetUri = UriHelper.getUri(
path: '/cgi/reset_password.pl',
queryType: queryType,
addUserAgentParameters: false,
);
Map<String, String> data = <String, String>{
'userid_or_email': emailOrUserID,
'action': 'process',
'type': 'send_email',
'submit': '.submit',
};
Status status = await HttpHelper().doMultipartRequest(
passwordResetUri,
data,
queryType: queryType,
);
if (status.body == null) {
return Status(
status: 500,
error:
'No response, open an issue here: https://github.com/openfoodfacts/openfoodfacts-dart/issues/new',
);
} else if (status.body!.contains('There is no account with this email')) {
return Status(
status: 400,
body: 'There is no account with this email',
);
} else if (status.body!.contains('has been sent to the e-mail address')) {
return Status(
status: 200,
body:
'An email with a link to reset your password has been sent to the e-mail address associated with your account.',
);
} else {
return status.copyWith(status: 400);
}
}