Skip to content

Commit

Permalink
Merge pull request #1365 from Scifabric/issue-1338-json-register-2
Browse files Browse the repository at this point in the history
Issue 1338 json register 2
  • Loading branch information
teleyinex committed Jan 4, 2017
2 parents 50647f6 + d1cf824 commit 0fbb3f8
Show file tree
Hide file tree
Showing 255 changed files with 1,741 additions and 1,425 deletions.
10 changes: 5 additions & 5 deletions app_context_rqworker.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# -*- coding: utf8 -*-
# This file is part of PyBossa.
# This file is part of PYBOSSA.
#
# Copyright (C) 2015 SciFabric LTD.
# Copyright (C) 2015 Scifabric LTD.
#
# PyBossa is free software: you can redistribute it and/or modify
# PYBOSSA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# PYBOSSA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa. If not, see <http://www.gnu.org/licenses/>.
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.

#!/usr/bin/env python
import sys
Expand Down
2 changes: 1 addition & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def delete_hard_bounces():

def bootstrap_avatars():
"""Download current links from user avatar and projects to real images hosted in the
PyBossa server."""
PYBOSSA server."""
import requests
import os
import time
Expand Down
75 changes: 75 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ Account index

**Endpoint: /account/page/<int:page>**

*Allowed methods*: **GET**

**GET**

It returns a JSON object with the following information:

* **accounts**: this key holds the list of accounts for the given page.
Expand Down Expand Up @@ -540,4 +544,75 @@ It returns a JSON object with the following information:
"update_feed": []
}
Account registration
~~~~~~~~~~~~~~~~~~~~
**Endpoint: /account/register**

*Allowed methods*: **GET/POST**

**GET**

It returns a JSON object with the following information:

* **form**: The form fields that need to be sent for creating an account. It contains the CSRF token for validating the POST, as well as an errors field in case that something is wrong.
* **template**: The Jinja2 template that could be rendered.
* **title**: the title of the page.

**Example output**

.. code-block:: python
{
"form": {
"confirm": null,
"csrf": "token,"
"email_addr": null,
"errors": {},
"fullname": null,
"name": null,
"password": null
},
"template": "account/register.html",
"title": "Register"
}
**POST**

To send a valid POST request you need to pass the *csrf token* in the headers. Use
the following header: "X-CSRFToken".

It returns a JSON object with the following information:

* **next**: URL that you JavaScript can follow as a redirect. It is not mandatory.

**Example output**

.. code-block:: python
{
"next":"/about"
}
If there's an error in the form fields, you will get them in the **form.errors** key:

.. code-block:: python
{
"form": {
"confirm": "daniel",
"csrf": "token",
"email_addr": "daniel",
"errors": {
"email_addr": [
"Invalid email address."
],
"name": [
"The user name is already taken"
]
},
"fullname": "daniel",
"name": "daniel",
"password": "daniel"
},
"template": "account/register.html",
"title": "Register"
}
9 changes: 9 additions & 0 deletions doc/customizing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ ITSDANGEROUSKEY_.
.. _ITSDANGEROUSKEY: https://github.com/Scifabric/pybossa/blob/master/settings_local.py.tmpl#L35
.. _`It's dangerous`: http://pythonhosted.org/itsdangerous/

CORS configuration
==================

By default PYBOSSA has the api endpoints configured with **Access-Control-Allow-Origin: ***. However, you can change it to whatever you want via the config file. Take a look into the
official documentation for `Flask-CORS` for all the available options.

.. _`Flask-CORS`: https://flask-cors.readthedocs.io/en/latest/


Modifying the Brand name
========================

Expand Down
12 changes: 6 additions & 6 deletions pybossa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf8 -*-
# This file is part of PyBossa.
# This file is part of PYBOSSA.
#
# Copyright (C) 2015 SciFabric LTD.
# Copyright (C) 2015 Scifabric LTD.
#
# PyBossa is free software: you can redistribute it and/or modify
# PYBOSSA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# PYBOSSA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa. If not, see <http://www.gnu.org/licenses/>.
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.
"""
PyBossa main module.
PYBOSSA main module.
This exports:
* auth: for authorization methods
Expand Down
22 changes: 8 additions & 14 deletions pybossa/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf8 -*-
# This file is part of PyBossa.
# This file is part of PYBOSSA.
#
# Copyright (C) 2015 SciFabric LTD.
# Copyright (C) 2015 Scifabric LTD.
#
# PyBossa is free software: you can redistribute it and/or modify
# PYBOSSA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# PYBOSSA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa. If not, see <http://www.gnu.org/licenses/>.
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.
"""
PyBossa api module for exposing domain objects via an API.
PYBOSSA api module for exposing domain objects via an API.
This package adds GET, POST, PUT and DELETE methods for:
* projects,
Expand All @@ -34,7 +34,7 @@
from flask import Blueprint, request, abort, Response, make_response
from flask.ext.login import current_user
from werkzeug.exceptions import NotFound
from pybossa.util import jsonpify, crossdomain, get_user_id_or_ip
from pybossa.util import jsonpify, get_user_id_or_ip
import pybossa.model as model
from pybossa.core import csrf, ratelimits, sentinel
from pybossa.ratelimit import ratelimit
Expand All @@ -57,17 +57,14 @@

blueprint = Blueprint('api', __name__)

cors_headers = ['Content-Type', 'Authorization']

error = ErrorStatus()


@blueprint.route('/')
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def index(): # pragma: no cover
"""Return dummy text for welcome page."""
return 'The PyBossa API'
return 'The PYBOSSA API'


def register_api(view, endpoint, url, pk='id', pk_type='int'):
Expand Down Expand Up @@ -105,7 +102,6 @@ def register_api(view, endpoint, url, pk='id', pk_type='int'):
@jsonpify
@blueprint.route('/app/<project_id>/newtask')
@blueprint.route('/project/<project_id>/newtask')
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def new_task(project_id):
"""Return a new task for a project."""
Expand Down Expand Up @@ -167,7 +163,6 @@ def _retrieve_new_task(project_id):
@blueprint.route('/project/<short_name>/userprogress')
@blueprint.route('/app/<int:project_id>/userprogress')
@blueprint.route('/project/<int:project_id>/userprogress')
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def user_progress(project_id=None, short_name=None):
"""API endpoint for user progress.
Expand Down Expand Up @@ -204,7 +199,6 @@ def user_progress(project_id=None, short_name=None):

@jsonpify
@blueprint.route('/auth/project/<short_name>/token')
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def auth_jwt_project(short_name):
"""Create a JWT for a project via its secret KEY."""
Expand Down
23 changes: 8 additions & 15 deletions pybossa/api/api_base.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf8 -*-
# This file is part of PyBossa.
# This file is part of PYBOSSA.
#
# Copyright (C) 2015 SciFabric LTD.
# Copyright (C) 2015 Scifabric LTD.
#
# PyBossa is free software: you can redistribute it and/or modify
# PYBOSSA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# PYBOSSA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa. If not, see <http://www.gnu.org/licenses/>.
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.
"""
PyBossa api module for exposing domain objects via an API.
PYBOSSA api module for exposing domain objects via an API.
This package adds GET, POST, PUT and DELETE methods for any class:
* projects,
Expand All @@ -31,7 +31,7 @@
from flask.ext.login import current_user
from flask.views import MethodView
from werkzeug.exceptions import NotFound, Unauthorized, Forbidden
from pybossa.util import jsonpify, crossdomain
from pybossa.util import jsonpify
from pybossa.core import ratelimits
from pybossa.auth import ensure_authorized_to
from pybossa.hateoas import Hateoas
Expand All @@ -58,8 +58,6 @@
}


cors_headers = ['Content-Type', 'Authorization']

error = ErrorStatus()


Expand All @@ -75,13 +73,11 @@ def valid_args(self):
if k not in ['api_key']:
getattr(self.__class__, k)

@crossdomain(origin='*', headers=cors_headers)
def options(self): # pragma: no cover
def options(self, **kwargs): # pragma: no cover
"""Return '' for Options method."""
return ''

@jsonpify
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def get(self, oid):
"""Get an object.
Expand Down Expand Up @@ -193,7 +189,6 @@ def _set_limit_and_offset(self):
return limit, offset

@jsonpify
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def post(self):
"""Post an item to the DB with the request.data JSON object.
Expand Down Expand Up @@ -227,7 +222,6 @@ def _create_instance_from_request(self, data):
return inst

@jsonpify
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def delete(self, oid):
"""Delete a single item from the DB.
Expand Down Expand Up @@ -263,7 +257,6 @@ def _delete_instance(self, oid):
return inst

@jsonpify
@crossdomain(origin='*', headers=cors_headers)
@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER'))
def put(self, oid):
"""Update a single item in the DB.
Expand Down
12 changes: 6 additions & 6 deletions pybossa/api/app.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf8 -*-
# This file is part of PyBossa.
# This file is part of PYBOSSA.
#
# Copyright (C) 2015 SciFabric LTD.
# Copyright (C) 2015 Scifabric LTD.
#
# PyBossa is free software: you can redistribute it and/or modify
# PYBOSSA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# PYBOSSA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa. If not, see <http://www.gnu.org/licenses/>.
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.
"""
PyBossa api module for domain object APP via an API.
PYBOSSA api module for domain object APP via an API.
This package adds GET, POST, PUT and DELETE methods for:
* projects,
Expand Down
12 changes: 6 additions & 6 deletions pybossa/api/category.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf8 -*-
# This file is part of PyBossa.
# This file is part of PYBOSSA.
#
# Copyright (C) 2015 SciFabric LTD.
# Copyright (C) 2015 Scifabric LTD.
#
# PyBossa is free software: you can redistribute it and/or modify
# PYBOSSA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# PYBOSSA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa. If not, see <http://www.gnu.org/licenses/>.
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.
"""
PyBossa api module for domain object Category via an API.
PYBOSSA api module for domain object Category via an API.
This package adds GET, POST, PUT and DELETE methods for:
* categories
Expand Down

0 comments on commit 0fbb3f8

Please sign in to comment.