colymba / silverstripe-restfulapi

SilverStripe RESTful API with a default JSON serializer.
BSD 3-Clause "New" or "Revised" License
64 stars 33 forks source link

Update RESTfulAPI_TokenAuthenticator.php #63

Closed michelsteege closed 8 years ago

michelsteege commented 8 years ago

I needed to add some more data to the response for my application, it would be nice to have this option in the module

colymba commented 8 years ago

So is the alterLoginSuccessResponse a custom method you have on your member object? Just wondering what is the purpose of it to see if it should be in the core?

michelsteege commented 8 years ago

Yes it is a custom method in a member extension, it would be better to check if the method exists instead of a try catch but i am not sure if that works with extensions.

In am building an application with silverstripe as the backend a angular app as the frontend this module as the api, but i want to do the login action and then display the name of the user without doing a second call to get the member data so that is why i added the custom method

colymba commented 8 years ago

I guess avoiding extra api request is not a bad thing.

I am not in favour of including method calls that are specific to a use case. But that said, I had rather see the Member object added directly to the response, like $response['member'] = $member. Then it gets serialised etc. as normal.

michelsteege commented 8 years ago

That would be great because my custom method looks like this:

public function alterLoginSuccessResponse($response){
                $response['Member'] = $this->owner->toMap();
                return $response;
        }

I've added the custom method instead of the member object because i wasn't sure if there was a reason it isn't in the code already (since there is a MemberID) but either way it would work great for me! :+1:

Very useful module btw!