2009-10-11 12:47:39 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
2010-01-26 13:55:01 +00:00
|
|
|
from django.contrib.auth.decorators import wraps
|
|
|
|
from shortcuts import render_to_json_response
|
2009-10-11 12:47:39 +00:00
|
|
|
|
|
|
|
def login_required_json(function=None):
|
|
|
|
"""
|
|
|
|
Decorator for views that checks that the user is logged in
|
|
|
|
return json error if not logged in.
|
|
|
|
"""
|
2010-01-26 13:55:01 +00:00
|
|
|
|
|
|
|
def _wrapped_view(request, *args, **kwargs):
|
|
|
|
if request.user.is_authenticated():
|
|
|
|
return function(request, *args, **kwargs)
|
2010-02-08 15:05:08 +00:00
|
|
|
return render_to_json_response({'status': {'code': 401, 'text': 'login required'}})
|
2010-01-26 13:55:01 +00:00
|
|
|
return wraps(function)(_wrapped_view)
|
2009-10-11 12:47:39 +00:00
|
|
|
|