kill user processes during rename and send email about it
parent
7fc039559e
commit
8be382da87
|
@ -10,6 +10,12 @@ def rename_user(old_username, new_username):
|
||||||
"""Given an old and a new username, renames user on disk with usermod.
|
"""Given an old and a new username, renames user on disk with usermod.
|
||||||
Raises if the usermod call fails."""
|
Raises if the usermod call fails."""
|
||||||
|
|
||||||
|
args = [
|
||||||
|
'pkill',
|
||||||
|
'-u',
|
||||||
|
old_username]
|
||||||
|
subprocess.run(args, check=True)
|
||||||
|
|
||||||
# Rename user
|
# Rename user
|
||||||
args = [
|
args = [
|
||||||
'usermod',
|
'usermod',
|
||||||
|
|
|
@ -6,15 +6,15 @@ from django.conf import settings
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
FROM='root@tilde.town'
|
EXTERNAL_FROM='tildetown@protonmail.ch'
|
||||||
|
|
||||||
def send_email(to, body, subject='a message from tilde.town', frum=FROM,):
|
def send_email(to, body, subject='a message from tilde.town'):
|
||||||
"""Sends an email using mailgun. Logs on failure."""
|
"""Sends an email using mailgun. Logs on failure."""
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
settings.MAILGUN_URL,
|
settings.MAILGUN_URL,
|
||||||
auth=('api', settings.MAILGUN_KEY),
|
auth=('api', settings.MAILGUN_KEY),
|
||||||
data={
|
data={
|
||||||
'from': frum,
|
'from': EXTERNAL_FROM,
|
||||||
'to': to,
|
'to': to,
|
||||||
'subject': subject,
|
'subject': subject,
|
||||||
'text': body
|
'text': body
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.contrib.auth.models import User
|
||||||
from django.db.models import TextField, BooleanField, CharField, ForeignKey
|
from django.db.models import TextField, BooleanField, CharField, ForeignKey
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
|
|
||||||
from common.mailing import send_email
|
from common.mailing import send_email, ADMIN_NAME
|
||||||
from help.models import Ticket
|
from help.models import Ticket
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
@ -51,16 +51,14 @@ class Townie(User):
|
||||||
def home(self):
|
def home(self):
|
||||||
return os.path.join('/home', self.username)
|
return os.path.join('/home', self.username)
|
||||||
|
|
||||||
def send_welcome_email(self, admin_name='vilmibm'):
|
def send_welcome_email(self):
|
||||||
welcome_tmpl = get_template('users/welcome_email.txt')
|
welcome_tmpl = get_template('users/welcome_email.txt')
|
||||||
context = {
|
context = {
|
||||||
'username': self.username,
|
'username': self.username,
|
||||||
'admin_name': admin_name,
|
'admin_name': ADMIN_NAME,
|
||||||
}
|
}
|
||||||
text = welcome_tmpl.render(context)
|
text = welcome_tmpl.render(context)
|
||||||
from_address = '{}@tilde.town'.format(admin_name)
|
success = send_email(self.email, text, subject='tilde.town!')
|
||||||
success = send_email(self.email, text, subject='tilde.town!',
|
|
||||||
frum=from_address)
|
|
||||||
if not success:
|
if not success:
|
||||||
Ticket.objects.create(name='system',
|
Ticket.objects.create(name='system',
|
||||||
email='root@tilde.town',
|
email='root@tilde.town',
|
||||||
|
@ -167,6 +165,23 @@ class Townie(User):
|
||||||
return
|
return
|
||||||
logger.info('Renamed {} to {}'.format(old_username, self.username))
|
logger.info('Renamed {} to {}'.format(old_username, self.username))
|
||||||
|
|
||||||
|
# send user an email
|
||||||
|
|
||||||
|
rename_tmpl = get_template('users/rename_email.txt')
|
||||||
|
context = {
|
||||||
|
'old_username': old_username,
|
||||||
|
'new_username': self.username
|
||||||
|
}
|
||||||
|
text = rename_tmpl.render(context)
|
||||||
|
success = send_email(self.email, text, subject='Your tilde.town user has been renamed!')
|
||||||
|
if not success:
|
||||||
|
Ticket.objects.create(name='system',
|
||||||
|
email='root@tilde.town',
|
||||||
|
issue_type='other',
|
||||||
|
issue_text='was not able to send rename email to {} ({})'.format(
|
||||||
|
self.username,
|
||||||
|
self.email))
|
||||||
|
|
||||||
|
|
||||||
class Pubkey(Model):
|
class Pubkey(Model):
|
||||||
key_type = CharField(max_length=50,
|
key_type = CharField(max_length=50,
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
hi!
|
||||||
|
|
||||||
|
you requested a new username on tilde.town. This process required logging you
|
||||||
|
out and killing any active processes you had running. sorry if this caused any
|
||||||
|
confusion or inconvenience.
|
||||||
|
|
||||||
|
old username: {{old_username}}
|
||||||
|
new username: {{new_username}}
|
||||||
|
|
||||||
|
you'll use this when ssh'ing into the town.
|
||||||
|
|
||||||
|
best,
|
||||||
|
~vilmibm
|
Loading…
Reference in New Issue