예제 #1
0
def user():
    """ Info on the currently logged in user. """
    if current_user.is_anonymous():
        raise ApiException(401, "not authenticated")

    user = serializers.to_dict(current_user)
    user['authentication_token'] = current_user.get_auth_token()

    return send_api_response({'current_user': user})
예제 #2
0
def zupc():
    if request.method != "GET":
        abort(405, message="method now allowed")
    if request_wants_json():
        abort(400, message="bad format")
    roles_accepted = set(['admin', 'mairie', 'prefecture', 'operateur'])
    if  current_user.is_anonymous() or\
            len(roles_accepted.intersection(current_user.roles)) == 0:
        abort(403)
    page = int(request.args.get('page')) if 'page' in request.args else 1
    return render_template('lists/zupc.html',
        zupc_list=administrative_models.ZUPC.query.paginate(page))
예제 #3
0
def api_resource(resource_id, base_query):
    try:
        resource = base_query.filter_by(id=resource_id).one()
    except NoResultFound:
        raise ApiException(404, "Not found")

    status_code = 200
    if resource == "committee-meeting":
        if not resource.check_permission():
            if current_user.is_anonymous():
                status_code = 401  # Unauthorized, i.e. authentication is required
            else:
                status_code = 403  # Forbidden, i.e. the user is not subscribed

    return send_api_response(serializers.queryset_to_json(resource),
                             status_code=status_code)
예제 #4
0
def inject_user():
    if current_user.is_anonymous():
        return dict(SERIALIZED_USER='******')
    return dict(SERIALIZED_USER=CurrentUser().dumps(current_user).data)
예제 #5
0
def inject_user():
    if current_user.is_anonymous():
        return dict(SERIALIZED_USER='******')
    return dict(SERIALIZED_USER=CurrentUser().dumps(current_user).data)
예제 #6
0
 def _handle_view(self, name, **kwargs):
     if not self.is_accessible() and current_user.is_anonymous():
         return redirect(url_for_security('login', next=url_for(".%s" % name)))
     if not self.is_accessible() and current_user.is_authenticated():
         abort(403) 
예제 #7
0
파일: site.py 프로젝트: crestify/crestify
def index():
    """The Main page"""
    if current_user.is_anonymous():
        return render_template("site/index.html")
    else:
        return redirect("/manager/bookmark")
예제 #8
0
 def forbidden(error):
     if not current_user.is_anonymous():
         logger.fatal("reject user [%s]" % current_user)
     logger.fatal("reject host [%s]" % request.remote_addr)
     return "forbidden. you ip address is %s" % request.remote_addr, 403
예제 #9
0
def load_identity_from_weird_usecase():
    if current_user.is_anonymous():
        return AnonymousIdentity()
    else:
        return Identity(current_user.get_id())
예제 #10
0
파일: site.py 프로젝트: tholen/crestify
def index():
    '''The Main page'''
    if current_user.is_anonymous():
        return render_template("site/index.html")
    else:
        return redirect("/manager/bookmark")
예제 #11
0
 def forbidden(error):
     if not current_user.is_anonymous():
         logger.fatal("reject user [%s]" % current_user)
     logger.fatal("reject host [%s]" % request.remote_addr)
     return "forbidden. you ip address is %s" % request.remote_addr, 403