From e851c77e74eea6d1d56353d5e1cb20d0ddb01a42 Mon Sep 17 00:00:00 2001 From: Max Erenberg Date: Mon, 23 Aug 2021 23:36:49 +0000 Subject: [PATCH] include password in welcome email --- ceo_common/interfaces/IMailService.py | 7 +++++-- ceod/model/MailService.py | 4 ++-- ceod/model/templates/welcome_message.j2 | 9 +++++++-- ceod/transactions/members/AddMemberTransaction.py | 2 +- tests/ceod/model/test_mail.py | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ceo_common/interfaces/IMailService.py b/ceo_common/interfaces/IMailService.py index baccd1f..b2149d5 100644 --- a/ceo_common/interfaces/IMailService.py +++ b/ceo_common/interfaces/IMailService.py @@ -11,8 +11,11 @@ class IMailService(Interface): def send(_from: str, to: str, headers: Dict[str, str], content: str): """Send a message with the given headers and content.""" - def send_welcome_message_to(user: IUser): - """Send a welcome message to the new member.""" + def send_welcome_message_to(user: IUser, password: str): + """ + Send a welcome message to the new member, including their temporary + password. + """ def announce_new_user(user: IUser, operations: List[str]): """ diff --git a/ceod/model/MailService.py b/ceod/model/MailService.py index b764809..be61e2f 100644 --- a/ceod/model/MailService.py +++ b/ceod/model/MailService.py @@ -51,11 +51,11 @@ class MailService: client.send_message(msg) client.quit() - def send_welcome_message_to(self, user: IUser): + def send_welcome_message_to(self, user: IUser, password: str): template = self.jinja_env.get_template('welcome_message.j2') # TODO: store surname and givenName in LDAP first_name = user.cn.split(' ', 1)[0] - body = template.render(name=first_name, user=user.uid) + body = template.render(name=first_name, user=user.uid, password=password) self.send( f'Computer Science Club ', f'{user.cn} <{user.uid}@{self.base_domain}>', diff --git a/ceod/model/templates/welcome_message.j2 b/ceod/model/templates/welcome_message.j2 index b396494..c17aaab 100644 --- a/ceod/model/templates/welcome_message.j2 +++ b/ceod/model/templates/welcome_message.j2 @@ -2,7 +2,6 @@ Hello {{ name }}: Welcome to the Computer Science Club! We are pleased that you have chosen to join us. We welcome you to come out to our events, or just hang out in our office (MC 3036/3037). You have been automatically subscribed to our mailing list, csc-general, which we use to keep you informed of upcoming events. - Typical events include: * Talks: these mostly technical talks are given by members, faculty and distinguished guests. Past topics include randomized algorithms, video encoding, computer security and adaptable user interfaces. People of all skill levels are welcome, and snacks are often served after talks. * Code parties: late-night hackathons perfect for contributing to open source, working on personal projects, or making progress on a CS assignment you've been putting off. Refreshments provided, and both music and geek classic movies have been played in the past. @@ -19,7 +18,13 @@ You can hear about upcoming events in a number of ways: Even when events aren't being held, you are welcome to hang out in the club office (MC 3036/3037, across the hall from MathSoc). It's often open late into the evening, and sells pop and snacks at reasonable prices. If you're so inclined, you are also welcome in our IRC channel, #csc on FreeNode. -You now have a CSC user account with username "{{ user }}" and the password you supplied when you joined. You can use this account to log into almost any CSC system, including our office terminals and servers. A complete list is available at: +You now have a CSC user account with username "{{ user }}". Your temporary password is: + +{{ password }} + +You will be prompted to change your password when you login to any CSC machine for the first time. + +You can use this account to log into almost any CSC system, including our office terminals and servers. A complete list is available at: http://wiki.csclub.uwaterloo.ca/Machine_List diff --git a/ceod/transactions/members/AddMemberTransaction.py b/ceod/transactions/members/AddMemberTransaction.py index 38cf539..f472807 100644 --- a/ceod/transactions/members/AddMemberTransaction.py +++ b/ceod/transactions/members/AddMemberTransaction.py @@ -84,7 +84,7 @@ class AddMemberTransaction(AbstractTransaction): # user has already seen the email try: - self.mail_srv.send_welcome_message_to(user) + self.mail_srv.send_welcome_message_to(user, password) yield 'send_welcome_message' except Exception as err: logger.warning('send_welcome_message failed:\n' + traceback.format_exc()) diff --git a/tests/ceod/model/test_mail.py b/tests/ceod/model/test_mail.py index 75ea840..5ce0d0f 100644 --- a/tests/ceod/model/test_mail.py +++ b/tests/ceod/model/test_mail.py @@ -1,7 +1,7 @@ def test_welcome_message(cfg, mock_mail_server, mail_srv, simple_user): base_domain = cfg.get('base_domain') mock_mail_server.messages.clear() - mail_srv.send_welcome_message_to(simple_user) + mail_srv.send_welcome_message_to(simple_user, 'password') msg = mock_mail_server.messages[0] assert msg['from'] == f'exec@{base_domain}' assert msg['to'] == f'{simple_user.uid}@{base_domain}'