Invalid body request

11 posts, 0 answers
  1. Marcel
    Marcel avatar
    25 posts
    Member since:
    Mar 2015

    Posted 07 Mar Link to this post

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

     

    Could someone help me.

     

    Thank you 

  2. Martin
    Admin
    Martin avatar
    67 posts

    Posted 08 Mar Link to this post

    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.
     
  3. Marcel
    Marcel avatar
    25 posts
    Member since:
    Mar 2015

    Posted 08 Mar in reply to Martin Link to this post

    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!'
                    });
                }
            });

        };

  4. Martin
    Admin
    Martin avatar
    67 posts

    Posted 09 Mar Link to this post

    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.
     
  5. Marcel
    Marcel avatar
    25 posts
    Member since:
    Mar 2015

    Posted 09 Mar in reply to Martin Link to this post

    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?
  6. Marcel
    Marcel avatar
    25 posts
    Member since:
    Mar 2015

    Posted 09 Mar Link to this post

    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?

  7. Martin
    Admin
    Martin avatar
    67 posts

    Posted 10 Mar Link to this post

    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.
     
  8. Marcel
    Marcel avatar
    25 posts
    Member since:
    Mar 2015

    Posted 10 Mar in reply to Martin Link to this post

    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

  9. Marcel
    Marcel avatar
    25 posts
    Member since:
    Mar 2015

    Posted 10 Mar in reply to Marcel Link to this post

    *what do you think? 
  10. Marcel
    Marcel avatar
    25 posts
    Member since:
    Mar 2015

    Posted 10 Mar Link to this post

    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

  11. Martin
    Admin
    Martin avatar
    67 posts

    Posted 14 Mar Link to this post

    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.
     
Back to Top