def post(self, request): user = get_object_or_404(BotUser, username=request.user.username) data = Status(user=user, alert=True, success=False, message="Error sending message to channel!") if not getattr(user, self.restr, None): data.update({"success": False, "alert": True, "message": "You have no authorization to %s!" % self.action}) return render(request, self.template, data) channel = request.POST.get("channel", None) message = request.POST.get("message", None) if not channel or not message: data.update({"success": False, "alert": True, "message": "Faulty input"}) return render(request, self.template, data) try: token = SocketUser.objects.get(user__username=user.username) command = settings.SOCKET_COMMANDS[self.action] % (channel, message) except SocketUser.DoesNotExist: return render(request, self.template, data) try: send_2_socket(username=user.username, token=token, command=command) except SocketSenderError as e: data.update({"success": False, "alert": True, "message": e}) return render(request, self.template, data) data.update({"success": True, "alert": True, "message": "Message send by bot!"}) return render(request, self.template, data)
def post(self, request): user = get_object_or_404(BotUser, username=request.user.username) data = Status(user=user, alert=True, success=False, message='Error sending message to channel!') if not getattr(user, self.restr, None): data.update({'success': False, 'alert': True, 'message': 'You have no authorization to %s!' % self.action}) return render(request, self.template, data) channel = request.POST.get('channel', None) message = request.POST.get('message', None) if not channel or not message: data.update({'success': False, 'alert': True, 'message': "Faulty input"}) return render(request, self.template, data) try: token = SocketUser.objects.get(user__username=user.username) command = settings.SOCKET_COMMANDS[self.action] % (channel, message) except SocketUser.DoesNotExist: return render(request, self.template, data) try: send_2_socket(username=user.username, token=token, command=command) except SocketSenderError as e: data.update({'success': False, 'alert': True, 'message': e}) return render(request, self.template, data) data.update({'success': True, 'alert': True, 'message': 'Message send by bot!'}) return render(request, self.template, data)
def post(self, request, pk): item = get_object_or_404(InfoItem, pk=pk) user = get_object_or_404(BotUser, username=request.user.username) items = InfoItem.objects.all() data = Status(user=user, alert=True, success=False, message='Error sending to channel!', items=items) if not getattr(user, self.restr, None): data.update({ 'success': False, 'alert': True, 'message': 'You have no authorization to %s!' % self.action}) return render(request, self.template, data) channel = request.POST.get('channel', None) if not channel: data.update({'success': False, 'alert': True, 'message': "Faulty input"}) return render(request, self.template, data) try: token = SocketUser.objects.get(user__username=user.username) command = settings.SOCKET_COMMANDS[self.action] % (channel, item.item, item.text) except (SocketUser.DoesNotExist, KeyError, TypeError): return render(request, self.template, data) try: send_2_socket(username=user.username, token=token, command=command) except SocketSenderError as e: data.update({'success': False, 'alert': True, 'message': 'Error: %s' % e}) return render(request, self.template, data) data.update({'success': True, 'alert': True, 'message': 'Message send by bot!'}) return render(request, self.template, data)
def post(self, request): user = get_object_or_404(BotUser, username=request.user.username) data = Status(user=user, alert=True, success=False, message='Invalid input for %s!' % self.action) try: action, value = request.POST.get(self.action).split('=') except AttributeError: return render(request, self.template, data) if action and action == self.action: if value == 'true': user.registration_token = None user.save() data.update({'success': True, 'alert': True, 'message': 'Registration token regenerated!'}) return render(request, self.template, data) return render(request, self.template, data)
def post(self, request): form = EditProfileForm(request.POST) user = get_object_or_404(BotUser, id=request.user.id) data = Status(form=form, alert=True, success=False, message='Error updating profile!') if form.is_valid(): user.first_name = form.clean()['first_name'] user.last_name = form.clean()['last_name'] user.email = form.clean()['email'] user.nick = form.clean()['nick'] user.host = form.clean()['host'] user.about = form.clean()['about'] user.save(force_update=True) data.update({'form': form, 'success': True, 'alert': True, 'message': 'User profile updated!'}) return render(request, "profile/profile_overview.html", data) return render(request, self.template, data)
def post(self, request): user = get_object_or_404(BotUser, username=request.user.username) data = Status(user=user, alert=True, success=False, message="Invalid input for %s!" % self.action) try: action, value = request.POST.get(self.action).split("=") except AttributeError: return render(request, self.template, data) if action and action == self.action: if value == "true": user.registration_token = None user.save() data.update({"success": True, "alert": True, "message": "Registration token regenerated!"}) return render(request, self.template, data) return render(request, self.template, data)
def post(self, request, pk): item = get_object_or_404(InfoItem, pk=pk) user = get_object_or_404(BotUser, username=request.user.username) items = InfoItem.objects.all() data = Status(user=user, alert=True, success=False, message='Error sending to channel!', items=items) if not getattr(user, self.restr, None): data.update({ 'success': False, 'alert': True, 'message': 'You have no authorization to %s!' % self.action }) return render(request, self.template, data) channel = request.POST.get('channel', None) if not channel: data.update({ 'success': False, 'alert': True, 'message': "Faulty input" }) return render(request, self.template, data) try: token = SocketUser.objects.get(user__username=user.username) command = settings.SOCKET_COMMANDS[self.action] % ( channel, item.item, item.text) except (SocketUser.DoesNotExist, KeyError, TypeError): return render(request, self.template, data) try: send_2_socket(username=user.username, token=token, command=command) except SocketSenderError as e: data.update({ 'success': False, 'alert': True, 'message': 'Error: %s' % e }) return render(request, self.template, data) data.update({ 'success': True, 'alert': True, 'message': 'Message send by bot!' }) return render(request, self.template, data)
def post(self, request): data = Status(user=request.user, alert=True, success=False, message='Error updating profile!') if request.POST.get("delete", None) == "0": data.update({ "message": "Deletion canceled!", "alert": True, "success": False }) return render(request, "profile/profile_overview.html", data) elif request.POST.get("delete", None) == "1": if request.user.is_superuser: data.update({ "message": "Superusers can't delete themselves in the profile editor!", "alert": True, "success": False }) return render(request, self.template, data) SocketUser.objects.get(user=request.user).delete() request.user.delete() data.update({ 'success': True, 'alert': True, 'message': 'User profile deleted!' }) return render(request, "auth/login.html", data) return render(request, self.template, data)
def post(self, request): data = Status(user=request.user, alert=True, success=False, message='Error updating profile!') if request.POST.get("delete", None) == "0": data.update({"message": "Deletion canceled!", "alert": True, "success": False}) return render(request, "profile/profile_overview.html", data) elif request.POST.get("delete", None) == "1": if request.user.is_superuser: data.update({ "message": "Superusers can't delete themselves in the profile editor!", "alert": True, "success": False}) return render(request, self.template, data) SocketUser.objects.get(user=request.user).delete() request.user.delete() data.update({'success': True, 'alert': True, 'message': 'User profile deleted!'}) return render(request, "auth/login.html", data) return render(request, self.template, data)