<commit_before>#! /usr/bin/env python
#-*- coding: utf-8 -*-

# ***** BEGIN LICENSE BLOCK *****
# This file is part of Shelter Database.
# Copyright (c) 2016 Luxembourg Institute of Science and Technology.
# All rights reserved.
#
#
#
# ***** END LICENSE BLOCK *****

__author__ = "<NAME>"
__version__ = "$Revision: 0.1 $"
__date__ = "$Date: 2016/03/30$"
__revision__ = "$Date: 2016/06/12 $"
__copyright__ = "Copyright (c) "
__license__ = ""

from flask import request, flash
from flask_login import current_user
from flask_restless import ProcessingException

from web.views.common import login_user_bundle
from web.models import User

def auth_func(*args, **kw):
    if request.authorization:
        user = User.query.filter(name==request.authorization.username).first()
        if not user:
            raise ProcessingException("Couldn't authenticate your user",
                                        code=401)
        if not user.check_password(request.authorization.password):
            raise ProcessingException("Couldn't authenticate your user",
                                        code=401)
        if not user.is_active:
            raise ProcessingException("User is desactivated", code=401)
        login_user_bundle(user)
    if not current_user.is_authenticated:
        raise ProcessingException(description='Not authenticated!', code=401)

def shelter_POST_preprocessor(data=None, **kw):
    """
    POST preprocessor for the creation of shelter.
    """
    data["user_id"] = current_user.id
    if current_user.is_admin:
        data["is_active"] = True
        flash("Your shelter has been created.", 'success')
    else:
        flash("Thank you! Your shelter has been created but is not yet public." +
            " An administrator will review it. You can already edit it.",
            'success')<commit_msg>bugfix...<commit_after>#! /usr/bin/env python
#-*- coding: utf-8 -*-

# ***** BEGIN LICENSE BLOCK *****
# This file is part of Shelter Database.
# Copyright (c) 2016 Luxembourg Institute of Science and Technology.
# All rights reserved.
#
#
#
# ***** END LICENSE BLOCK *****

__author__ = "<NAME>"
__version__ = "$Revision: 0.1 $"
__date__ = "$Date: 2016/03/30$"
__revision__ = "$Date: 2016/06/12 $"
__copyright__ = "Copyright (c) "
__license__ = ""

from flask import request, flash
from flask_login import current_user
from flask_restless import ProcessingException

from web.views.common import login_user_bundle
from web.models import User

def auth_func(*args, **kw):
    if request.authorization:
        user = User.query.filter(name==request.authorization.username).first()
        if not user:
            raise ProcessingException("Couldn't authenticate your user",
                                        code=401)
        if not user.check_password(request.authorization.password):
            raise ProcessingException("Couldn't authenticate your user",
                                        code=401)
        if not user.is_active:
            raise ProcessingException("User is desactivated", code=401)
        login_user_bundle(user)
    if not current_user.is_authenticated:
        raise ProcessingException(description='Not authenticated!', code=401)

def shelter_POST_preprocessor(data=None, **kw):
    """
    POST preprocessor for the creation of shelter.
    """
    data["user_id"] = current_user.id
    if current_user.is_admin:
        data["is_published"] = True
        flash("Your shelter has been created.", 'success')
    else:
        flash("Thank you! Your shelter has been created but is not yet public." +
            " An administrator will review it. You can already edit it.",
            'success')
{'fraction_non_alphanumeric': 0.11062788801304703, 'fraction_numerical': 0.019026909486273443, 'mean_word_length': 2.8983050847457625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1954208', 'n_tokens_mistral': 1089, 'n_tokens_neox': 992, 'n_words': 305}