implement user welcome emails
emails trigger when they're marked as reviewedpull/5/head
parent
1a111be0d5
commit
ba05ec340c
|
@ -10,8 +10,16 @@ admin.site.unregister(Group)
|
|||
class PubkeyInline(admin.TabularInline):
|
||||
model = Pubkey
|
||||
|
||||
def bulk_review(madmin, req, qs):
|
||||
for townie in qs:
|
||||
townie.reviewed = True
|
||||
townie.save()
|
||||
|
||||
bulk_review.short_description = 'mark selected townies as reviewed'
|
||||
|
||||
@admin.register(Townie)
|
||||
class TownieAdmin(admin.ModelAdmin):
|
||||
inlines = [PubkeyInline]
|
||||
list_display = ('reviewed', 'username', 'email')
|
||||
ordering = ('reviewed',)
|
||||
actions = (bulk_review,)
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import re
|
||||
|
||||
from django.db.models import Model
|
||||
from django.db.models.signals import post_save
|
||||
from django.db.models.signals import pre_save
|
||||
from django.dispatch import receiver
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import TextField, BooleanField, CharField, ForeignKey
|
||||
from django.template.loader import get_template
|
||||
|
||||
from common.mailing import send_email
|
||||
from help.models import Ticket
|
||||
|
||||
SSH_TYPE_CHOICES = (
|
||||
('ssh-rsa', 'ssh-rsa',),
|
||||
|
@ -24,14 +27,22 @@ class Townie(User):
|
|||
reasons = TextField(blank=True, null=False, default='')
|
||||
displayname = CharField(max_length=100, blank=False, null=False)
|
||||
|
||||
# TODO consider a generic ensure method that syncs this model with the
|
||||
# system. there will likely be things besides shell that we want to keep
|
||||
# track of in the DB.
|
||||
def ensure_shell(self):
|
||||
"""Runs chsh for the user to set their shell to whatever self.shell
|
||||
is."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def send_welcome_email(self, admin_name='vilmibm'):
|
||||
welcome_tmpl = get_template('users/welcome_email.txt')
|
||||
context = {
|
||||
'username': self.username,
|
||||
'admin_name': admin_name,
|
||||
}
|
||||
text = welcome_tmpl.render(context)
|
||||
from_address = '{}@tilde.town'.format(admin_name)
|
||||
success = send_email(self.email, text, subject='tilde.town!', frum=from_address)
|
||||
if not success:
|
||||
Ticket.objects.create(name='system',
|
||||
email='root@tilde.town',
|
||||
issue_type='other',
|
||||
issue_text='was not able to send welcome email to {} ({})'.format(
|
||||
self.username,
|
||||
self.email))
|
||||
|
||||
class Pubkey(Model):
|
||||
key_type = CharField(max_length=50,
|
||||
|
@ -43,11 +54,11 @@ class Pubkey(Model):
|
|||
townie = ForeignKey(Townie)
|
||||
|
||||
|
||||
@receiver(post_save, sender=Townie)
|
||||
def sync_system_state(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
print('TODO would create new user on system')
|
||||
else:
|
||||
print('TODO would update existing user on system')
|
||||
|
||||
@receiver(pre_save, sender=Townie)
|
||||
def on_townie_pre_save(sender, instance, **kwargs):
|
||||
existing = Townie.objects.filter(username=instance.username)
|
||||
if not existing: # we're making a new user
|
||||
return
|
||||
|
||||
if not existing[0].reviewed and instance.reviewed == True:
|
||||
instance.send_welcome_email()
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
Welcome to tilde.town, ~{{username}}!
|
||||
|
||||
Please take a moment to review our code of conduct: https://tilde.town/~wiki/conduct.html
|
||||
|
||||
and login with:
|
||||
|
||||
ssh -i /path/to/private/key {{username}}@tilde.town
|
||||
|
||||
File a help ticket if you have problems logging in (or other issues): https://cgi.tilde.town/help/tickets
|
||||
|
||||
See you on the server!!
|
||||
|
||||
~{{admin_name}}
|
Loading…
Reference in New Issue