def create(request):

    data = request.DATA

    if getattr(request, 'ignore_csrf_checks', False):
        return {'code': 'no_access'}, 404, False

    if data is False:
        return {'code': 'no_data'}, 404, False

    data = helpers.set_null_values_if_not_exist(data, resource.get_fields())

    if data['password'] is None:
        return {'code': 'account/no_password'}, 404, False

    if data['email'] is None:
        return {'code': 'account/not_email'}, 404, False

    data['email'] = data['email'].lower()

    try:
        validate_email(data['email'])
    except ValidationError:
        return {'code': 'account/wrong_email'}, 404, False

    user = resource.get_item_by_email(request, data['email'])

    if user:
        return {'code': 'account/exists', 'values': [data['email']]}, 404, False

    return {'code': 'ok'}, 200, True
def login(request):
    data = request.DATA

    if data is False:
        return {'code': 'no_data'}, 404, False

    data = helpers.set_null_values_if_not_exist(data, resource.get_fields())

    if data['password'] is None:
        return {'code': 'account/no_password'}, 404, False

    if data['email'] is None:
        return {'code': 'account/not_email'}, 404, False

    data['email'] = data['email'].lower()

    try:
        validate_email(data['email'])
    except ValidationError:
        return {'code': 'account/wrong_email'}, 404, False

    user = resource.get_item_by_email(request, data['email'])

    if not user:
        return {'code': 'account/user_not_found', 'values': [data['email']]}, 404, False

    return {'code': 'ok'}, 200, True
def recovery(request):
    """Recovery action"""

    if request.user.is_authenticated():
        return {'code': 'no_access'}, 404, False

    data = request.DATA

    if data is False:
        return {'code': 'no_data'}, 404, False

    data = helpers.set_null_values_if_not_exist(data, resource.get_fields())

    if data['email'] is None:
        return {'code': 'account/not_email'}, 404, False

    data['email'] = data['email'].lower()

    try:
        validate_email(data['email'])
    except ValidationError:
        return {'code': 'account/wrong_email'}, 404, False

    user = resource.get_item_by_email(request, data['email'])

    if not user:
        return {'code': 'account/user_not_found', 'values': [data['email']]}, 404, False

    return {'code': 'ok'}, 200, True