def inner(request, *args, **kwargs): if user_utils.is_superuser(request.user.username): return func(request, *args, **kwargs) else: messages.error("Permission denied") return HttpResponseRedirect(self.redirect)
except server.ServerRequestError, err: logger.warning("Login failure for %s: %s" % (username, err[1])) return None except Exception, err: logger.warning(traceback.format_exc()) return None # we got the user data above with a direct UserAPI call so # that we could catch errors and tell if the login was # successful. now let's get better data using user_utils udata = user_utils.get_user(username) user, created = User.objects.get_or_create(username=username) if created: logger.info("Created new user object for %s", username) user.set_unusable_password() user.is_superuser = user_utils.is_superuser(username) user.first_name = udata['name'].split()[0] user.last_name = " ".join(udata['name'].split()[1:]) user.save() return user def get_user(self, user_id): """ get a user object representing a user """ try: return User.objects.get(pk=user_id) except User.DoesNotExist: return None