nicolaiarocci/eve — pull request #27 by tsileo (2013-04-01 20:38:13+00:00)
Title: Added custom_data and where_extra support

First, eve is awesome ! I wish I discovered it earlier !

I wanted that an authenticated user can only retrieve resources he created, this mean, I need to add a user key on insert ( **custom_data** ), and override wheres query ( **where_extra** ) so a user can only retrieve its own resources.

I'm not sure about the name of these functions, but here how it works for me:

```python
# -*- coding: utf-8 -*-
from eve import Eve
from eve.auth import TokenAuth
from flask import request

class TokenAuth(TokenAuth):
def check_auth(self, token, allowed_roles):
"""For the purpose of this example the implementation is as simple as
possible. A 'real' token should probably contain a hash of the
username/password combo, which sould then validated against the account
data stored on the DB.
"""
# use Eve's own db driver; no additional connections/resources are used
accounts = app.data.driver.db['accounts']
return accounts.find_one({'token': token})

def custom_data():
return {"user": request.authorization.username}
where_extra = custom_data

if __name__ == '__main__':
app = Eve(auth=TokenAuth, custom_data=custom_data, where_extra=where_extra)
app.debug = True
app.run(host='0.0.0.0', port=8000)
```

Let me know if you want me to write tests (if you consider merging these changes), or if you have any feedback.

Thanks !