def edit(request): if request.method == "POST": form = PreferencesForm(request.POST, instance=request.user) if form.is_valid(): user = form.save() if "email" in form.changed_data: user.email_confirmed = False user.save() UserConfirmationKey.objects.filter(subject=user, type="E").delete() key = UserConfirmationKey.objects.create(subject=user, type="E") key.send(*get_siteinfo(request)) if "jid" in form.changed_data: user.jid_confirmed = False user.save() UserConfirmationKey.objects.filter(subject=user, type="J").delete() key = UserConfirmationKey.objects.create(subject=user, type="J") key.send(*get_siteinfo(request)) return redirect("account") else: form = PreferencesForm(instance=request.user) return render(request, "account/edit.html", {"user_form": form})
def edit(request): if request.method == 'POST': form = PreferencesForm(request.POST, instance=request.user) if form.is_valid(): user = form.save() if 'email' in form.changed_data: user.email_confirmed = False user.save() UserConfirmationKey.objects.filter(subject=user, type='E').delete() key = UserConfirmationKey.objects.create(subject=user, type='E') key.send(*get_siteinfo(request)) if 'jid' in form.changed_data: user.jid_confirmed = False user.save() UserConfirmationKey.objects.filter(subject=user, type='J').delete() key = UserConfirmationKey.objects.create(subject=user, type='J') key.send(*get_siteinfo(request)) return redirect('account') else: form = PreferencesForm(instance=request.user) return render(request, 'account/edit.html', { 'user_form': form, })
def resend_confirmation(request): if not request.user.email_confirmed: key = UserConfirmationKey.objects.create(subject=request.user, type="E") key.send(*get_siteinfo(request)) if not request.user.jid_confirmed: key = UserConfirmationKey.objects.create(subject=request.user, type="J") key.send(*get_siteinfo(request)) return render(request, "account/resend_confirmation.html", {"jid": settings.XMPP["default"]["jid"]})
def resend_confirmation(request): if not request.user.email_confirmed: key = UserConfirmationKey.objects.create(subject=request.user, type='E') key.send(*get_siteinfo(request)) if not request.user.jid_confirmed: key = UserConfirmationKey.objects.create(subject=request.user, type='J') key.send(*get_siteinfo(request)) return render(request, 'account/resend_confirmation.html', {'jid': settings.XMPP['default']['jid']})
def handle(self, *args, **options): perm = Permission.objects.get(codename='moderate') query = Q(groups__permissions=perm) | Q(user_permissions=perm) users = User.objects.filter(query | Q(is_superuser=True)).distinct() protocol, domain = get_siteinfo() servers = Server.objects.for_moderation() if not servers: return subject = '[%s] %s servers awaiting moderation' % ( settings.SITENAME, len(servers) ) t = loader.get_template('mail/moderationmail.html') for user in users: c = Context({ 'servers': servers, 'user': user, 'sitename': settings.SITENAME, 'protocol': protocol, 'domain': domain, }) body = t.render(c) send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)
def siteinfo(request): protocol, domain = get_siteinfo(request) return { 'domain': domain, 'protocol': protocol, 'siteurl': '%s://%s' % (protocol, domain), }
def send(self): # build context protocol, domain = get_siteinfo() context = {'domain': domain, 'key': self, 'protocol': protocol} subject_format = { 'addr_type': self.address_type, 'domain': domain, 'protocol': protocol, } context.update(self.add_context()) subject_format.update(self.add_context()) # build subject and message-text subject = self.message_subject % subject_format message = render_to_string(self.message_template, context) # send message if self.type == 'E': self.send_mail(self.recipient, subject, message) elif self.type == 'J': self.send_jid(self.recipient, subject, message) else: raise RuntimeError( "Confirmation messages can only be sent to JIDs or email addresses" )
def siteinfo(request): protocol, domain = get_siteinfo() if request.is_secure(): protocol = 'https' return { 'domain': domain, 'protocol': protocol, 'siteurl': '%s://%s' % (protocol, domain), }
def do_contact_verification(self, request): typ = self.contact_type # Set contact_verified if it sthe same as your email or JID: if self.autoconfirmed(typ, self.contact): self.contact_verified = True elif typ in ['J', 'E']: key = self.confirmations.create(subject=self, type=self.contact_type) protocol, domain = get_siteinfo(request) key.send(protocol, domain)
def create(request): if request.method == "POST": form = CreationForm(request.POST, prefix="user") if form.is_valid(): # create user user = form.save() # create confirmations: ekey = UserConfirmationKey.objects.create(subject=user, type="E") ekey.send(*get_siteinfo(request)) jkey = UserConfirmationKey.objects.create(subject=user, type="J") jkey.send(*get_siteinfo(request)) user.backend = "django.contrib.auth.backends.ModelBackend" login(request, user) return redirect("account") else: form = CreationForm(prefix="user") return render(request, "account/create.html", {"user_form": form})
def create(request): if request.method == 'POST': form = CreationForm(request.POST, prefix='user') if form.is_valid(): # create user user = form.save() # create confirmations: ekey = UserConfirmationKey.objects.create(subject=user, type='E') ekey.send(*get_siteinfo(request)) jkey = UserConfirmationKey.objects.create(subject=user, type='J') jkey.send(*get_siteinfo(request)) user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) return redirect('account') else: form = CreationForm(prefix='user') return render(request, 'account/create.html', { 'user_form': form, })
def send(self): # build context protocol, domain = get_siteinfo() context = {'domain': domain, 'key': self, 'protocol': protocol} subject_format = { 'addr_type': self.address_type, 'domain': domain, 'protocol': protocol, } context.update(self.add_context()) subject_format.update(self.add_context()) # build subject and message-text subject = self.message_subject % subject_format message = render_to_string(self.message_template, context) # send message if self.type == 'E': self.send_mail(self.recipient, subject, message) elif self.type == 'J': self.send_jid(self.recipient, subject, message) else: raise RuntimeError("Confirmation messages can only be sent to JIDs or email addresses")
def form_valid(self, form): key = UserPasswordResetKey.objects.create(subject=form.user) key.send(*get_siteinfo(self.request)) return super(ResetPassword, self).form_valid(form)