This is a migrated thread and some comments may be shown as answers.

Invalid body request

10 Answers 86 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcel
Top achievements
Rank 1
Marcel asked on 08 Mar 2016, 03:13 AM

Everytime I press reset password to have an email sent to Usero get the error.

 

Could someone help me.

 

Thank you 

10 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 08 Mar 2016, 12:31 PM

Hi Marcel,

I assume you are calling the function users.resetPassword()Please notice that the function is taking an object as a parameter so the supplied userName should be an object and not a string. Probably this is causing the "invalid request body" error whic is returned by the server when malformed request parameters are sent.

Let me know if the error persists.


Regards,
Martin
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Marcel
Top achievements
Rank 1
answered on 09 Mar 2016, 03:24 AM

this is how I set up my

service.js - resetPassword: function (loginData) {
                      return el.Users.resetPassword(
                            loginData.username)
                          .then(function (data) {
                            return data;
                                                          },
                             function(error){
                            return error;
                                                });
                                   },             

 

this is how i set it up in 

controller.js - // Perform the reset password action when the user press forgot password
    $scope.openForgotpasswd = function () {
        User.resetPassword($scope.loginData).then(function (data) {
            if (data.result) {
                //send password
                $scope.loginData.username;
                $scope.openForgotpasswd();
                $state.go("/loginmain");
                $scope.loginmodal.hide();
            } else {
                $ionicPopup.alert({
                    title: data.message,
                    template: 'Please try again!'
                });
            }
        });

    };

0
Martin
Telerik team
answered on 09 Mar 2016, 04:37 PM

Hi Marcel,

Thank you for getting back to me.

Instead of a string you should construct and pass an object to the Users.resetPassword() function like this:

resetPassword: function(loginData) {
    return el.Users.resetPassword({
            "Username": loginData.username // object instead of string
        })
        .then(function(data) {
                return data;
            },
            function(error) {
                return error;
            });
}

Let me know if this has worked.

Regards,
Martin
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Marcel
Top achievements
Rank 1
answered on 09 Mar 2016, 10:10 PM
Yes that works well Martin, only problem is when sending the link to email it sends it over 228 times. Is there a way to make sure the request is only sent once?
0
Marcel
Top achievements
Rank 1
answered on 10 Mar 2016, 03:30 AM

there are hundreds of emails coming to me with the email and username ive provided myself with on the app.

Also when a user register the ionicpopup display the username is already taken and pops up twice after click ok the first time. 

Could it be how the code i have is structured thats causing the problem?

0
Martin
Telerik team
answered on 10 Mar 2016, 02:27 PM

Hi Marcel,

1. About the multiple emails sent with resetPassword() - this behavior is really strange. Each call of the resetPassword() function should send one request to the server and subsequently for each request for password reset one email is sent. Therefore the multiple emails received indicate that the function has been called multiple times.

I have checked our server and indeed there are more than 2000 requests in a few minutes time period with resetPassword. Still I could not replicate this behavior.

Please check on your side if the function is not being called multiple times or the button is not tapped multiple times.

You may also describe the sequence of events that lead to this outcome and attach a sample that replicates the issue here. Also,  specify if the app is tested in the simulator, device, etc.

2. About "when a user register the ionicpopup display the username is already taken and pops up twice" - please check whether you are not calling the register function twice - the first time it will register the user, the second time the server will return an error "A user with the same username already exists." (check also in the data browser for the Users content type whether the user is created).

Looking forward for you answer.

Regards,
Martin
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Marcel
Top achievements
Rank 1
answered on 10 Mar 2016, 03:52 PM

hey Martin, 

Service.js is set up to how you referenced it

 

this is how i set it up in 
controller.js - // Perform the reset password action when the user press forgot password
    $scope.openForgotpasswd = function () {
        User.resetPassword($scope.loginData).then(function (data) {
            if (data.result) {
                //send password
                $scope.loginData.username;
                $scope.openForgotpasswd();
                $state.go("/loginmain");

                $scope.loginmodal.hide();
            } else {
                $ionicPopup.alert({
                    title: data.message,
                    template: 'Please try again!'
                });
            }
        });

    };

 

it doesn't look like I'm calling the function twice. 

W

0
Marcel
Top achievements
Rank 1
answered on 10 Mar 2016, 03:52 PM
*what do you think? 
0
Marcel
Top achievements
Rank 1
answered on 10 Mar 2016, 04:57 PM

Yes I actually did call it twice I believe in the service.js and the controller.js 

user.resetpassword($scope.loginData).then function (data) shouldn't be called since I already did it in service.js right?

i was was testing it on a device and stimulator

0
Martin
Telerik team
answered on 14 Mar 2016, 03:01 PM

Hi Marcel,

The provided resetPassword functions look OK. I was referring to the register function being called twice. You are not calling the resetPassword function twice too (based on the code you have provided).

For the resetPassword.

Could you please add console.log() to both functions so that you can track in the console how many times the functions are being called like this:

In services.js:

resetPassword: function(loginData) {
    return el.Users.resetPassword({
            "Username": loginData.username // object instead of string
        })
        .then(function(data) {
                console.log('services.js -> successCallBack resetPassword');
                return data;
            },
            function(error) {
                console.log('services.js -> errorCallBack resetPassword');
                return error;
            });
}

and in controller.js:

    $scope.openForgotpasswd = function () {
        console.log('controller.js -> calling resetPassword');
        User.resetPassword($scope.loginData).then(function (data) {
            if (data.result) {
                //send password
                $state.go("loginmain");
                $scope.loginmodal.hide();
            } else {
                $ionicPopup.alert({
                    title: data.message,
                    template: 'Please try again!'
                });
            }
        });
 
    };
})

When you click on the "Reset Password!" button each function in services.js and controller.js should be called only once.

Regards,
Martin
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
Marcel
Top achievements
Rank 1
Answers by
Martin
Telerik team
Marcel
Top achievements
Rank 1
Share this question
or