I have this decorator to check that the user is logged in and the account is activated.
def activation_required(func):
"""
checks if user is registered logged in and activated
"""
def decorator(request, *args, **kwargs):
if request.user and request.user.is_authenticated():
try:
user = request.user
if user.active:
return func(request, *args, **kwargs)
else:
messages.add_message(request, messages.ERROR, "not activated!")
return HttpResponseRedirect(reverse('home'))
except Exception as e:
return HttpResponseServerError(repr(e))
else:
return HttpResponseRedirect(reverse('home'))
return decorator
Instead of HttpResponseRedirect
I would like to return an ajax error with a message. Is this possible? How?
function postData(url){
var ajax_data = {
message: "",
return_val: ""
};
$.ajax({
url: url,
type: "POST",
dataType: "json",
data: ajax_data,
success:function(data){
alert('ok');
}, // success
error: function(data){
alert(data.message); // <- this should run if user is not activated
} // error
}); // ajax
}