Browse Source

more documentation

master
Julio Biason 11 years ago
parent
commit
2921f7e9c2
  1. 63
      luncho/blueprints/users.py

63
luncho/blueprints/users.py

@ -35,8 +35,27 @@ class UsernameAlreadyExistsException(LunchoException):
@users.route('', methods=['PUT']) @users.route('', methods=['PUT'])
@ForceJSON(required=['username', 'full_name', 'password']) @ForceJSON(required=['username', 'full_name', 'password'])
def create_user(): def create_user():
"""Create a new user. Request must be: """Create a new user.
{ "username": "username", "full_name": "Full Name", "password": "hash" }"""
**Example request**
.. sourcecode:: http
{ "username": "username",
"full_name": "I'm a person",
"password": "MyPassword!" }
**Success (200)**:
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: text/json
{ "status": "OK" }
**User already exists (409)**: :py:class:`UsernameAlreadyExistsException`
"""
json = request.get_json(force=True) json = request.get_json(force=True)
try: try:
@ -53,14 +72,42 @@ def create_user():
return jsonify(status='OK') return jsonify(status='OK')
@users.route('/', methods=['POST']) @users.route('', methods=['POST'])
@ForceJSON() @ForceJSON()
@auth @auth
def update_user(): def update_user():
"""Update user information. Request can have the following fields: """*Authenticated request* Update user information. Only the fields send
{ "full_name": "Full name", "password": "hash" } with be changed.
Any other field will be ignored; only fields that need to be changed
must be send.""" **Example request**
Change everything:
.. sourcecode:: http
{ "full_name": "My New Full Name", "password": "newPassword" }
Change only the user password:
.. sourcecode:: http
{ "password": "newPassowrd" }
**Succcess (200)**:
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: text/json
{ "status": "OK" }
**Request not in JSON format (400)**: :py:class:`RequestMustBeJSONException`
**User not found (via token) (404)**: :py:class:`UserNotFoundException`
**Authorization required (412)**: :py:class:`AuthorizationRequiredException`
"""
json = request.get_json(force=True) json = request.get_json(force=True)
user = request.user user = request.user
@ -76,7 +123,7 @@ def update_user():
return jsonify(status='OK') return jsonify(status='OK')
@users.route('/', methods=['DELETE']) @users.route('', methods=['DELETE'])
@auth @auth
def delete_user(): def delete_user():
"""Delete a user. No confirmation is send.""" """Delete a user. No confirmation is send."""

Loading…
Cancel
Save