add sending welcome message
parent
0dbaf7f916
commit
a274cf296e
|
@ -88,10 +88,20 @@ def main():
|
||||||
else:
|
else:
|
||||||
address = ldap.get_email_address(user)
|
address = ldap.get_email_address(user)
|
||||||
|
|
||||||
|
if isinstance(address, bytes):
|
||||||
|
address = address.decode()
|
||||||
|
|
||||||
|
assert isinstance(address, str)
|
||||||
|
|
||||||
if args.show_password:
|
if args.show_password:
|
||||||
print(f'password: "{password}"')
|
print(f'password: "{password}"')
|
||||||
|
|
||||||
action = 'reset' if p is not None else 'create'
|
action = 'reset' if p is not None else 'create'
|
||||||
|
|
||||||
|
# TODO use separate command for password/welcome combo
|
||||||
|
if action is 'create':
|
||||||
|
logging.info("No existing pasword entry. Welcome email will be sent")
|
||||||
|
|
||||||
i = input(
|
i = input(
|
||||||
f"Type yes to {action} {user}'s password and send email to {address!r}\n"
|
f"Type yes to {action} {user}'s password and send email to {address!r}\n"
|
||||||
).strip()
|
).strip()
|
||||||
|
@ -106,7 +116,13 @@ def main():
|
||||||
p.change_password(password)
|
p.change_password(password)
|
||||||
print("password changed")
|
print("password changed")
|
||||||
|
|
||||||
send_mail(args.admin, admin_pass, password, user, address)
|
messages = []
|
||||||
|
if action == 'create':
|
||||||
|
messages.append(prepare_welcome_msg(args.admin, user, address))
|
||||||
|
|
||||||
|
messages.append(prepare_passwd_msg(args.admin, password, user, address))
|
||||||
|
|
||||||
|
send_mail(args.admin, admin_pass, messages)
|
||||||
print("email sent")
|
print("email sent")
|
||||||
|
|
||||||
ldap.force_sasl(user)
|
ldap.force_sasl(user)
|
||||||
|
@ -154,10 +170,10 @@ class HsLdap:
|
||||||
raise Exception("too many responses")
|
raise Exception("too many responses")
|
||||||
address = c.entries[0]["mailRoutingAddress"]
|
address = c.entries[0]["mailRoutingAddress"]
|
||||||
logging.debug(f"got mail address from LDAP: {address}")
|
logging.debug(f"got mail address from LDAP: {address}")
|
||||||
return address
|
return address.value
|
||||||
|
|
||||||
|
|
||||||
def send_mail(admin, admin_password, password, user, address):
|
def prepare_passwd_msg(admin, password, user, address):
|
||||||
mail_template = Template(
|
mail_template = Template(
|
||||||
resource_string(__name__, "password_reset.jinja2").decode()
|
resource_string(__name__, "password_reset.jinja2").decode()
|
||||||
)
|
)
|
||||||
|
@ -166,9 +182,24 @@ def send_mail(admin, admin_password, password, user, address):
|
||||||
msg.set_content(mail_template.render(config))
|
msg.set_content(mail_template.render(config))
|
||||||
msg["Subject"] = f"Password reset for {user}@hackerspace.pl"
|
msg["Subject"] = f"Password reset for {user}@hackerspace.pl"
|
||||||
msg["From"] = f"{admin}@hackerspace.pl"
|
msg["From"] = f"{admin}@hackerspace.pl"
|
||||||
msg["To"] = address.decode() if isinstance(address, bytes) else address
|
msg["To"] = address
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_welcome_msg(admin, user, address):
|
||||||
|
msg = EmailMessage()
|
||||||
|
msg.set_content(resource_string(__name__, 'welcome.txt').decode())
|
||||||
|
msg["Subject"] = f"Witamy! Welcome to the Warsaw Hackerspace!"
|
||||||
|
msg["From"] = f"{admin}@hackerspace.pl"
|
||||||
|
msg["Bcc"] = f"{admin}@hackerspace.pl"
|
||||||
|
msg["To"] = ', '.join(set([address, f'{user}@hackerspace.pl']))
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def send_mail(admin, admin_password, messages):
|
||||||
with smtplib.SMTP_SSL("mail.hackerspace.pl") as s:
|
with smtplib.SMTP_SSL("mail.hackerspace.pl") as s:
|
||||||
s.login(admin, admin_password)
|
s.login(admin, admin_password)
|
||||||
s.send_message(msg)
|
|
||||||
|
logging.debug(f"Sending {len(messages)} messages via SMTP")
|
||||||
|
for msg in messages:
|
||||||
|
s.send_message(msg)
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
Witamy w Warszawskim Hackerspacie!
|
||||||
|
Welcome to the Warsaw Hackerspace!
|
||||||
|
|
||||||
|
Powinieneś/powinnaś mieć teraz dostęp do wszyskich wewnętrznych usług dla członków. Tym samym hasłem uwierzytelnisz się wszędzie.
|
||||||
|
You should now have access to all of our internal, member-exclusive systems. You can use the same password to log in everywhwere.
|
||||||
|
|
||||||
|
Przeczytaj naszą wyprawkę żeby dowiedzieć się najważniejszych związanych z Twoim członkostwem, naszym spejsem i wewnętrznymi usługami: https://wiki.hackerspace.pl/members:wyprawka
|
||||||
|
Please read our new member handbook to learn more about your membership, our hackerspace and internal services: https://wiki.hackerspace.pl/members:wyprawka
|
||||||
|
|
||||||
|
Aby zmienić hasło, wejdź na: https://profile.hackerspace.pl
|
||||||
|
To change your password, go to: https://profile.hackerspace.pl
|
||||||
|
|
||||||
|
Aby zobaczyć stan swoich składek, wejdź na: https://kasownik.hackerspace.pl
|
||||||
|
To see your membership fee status, go to: https://kasownik.hackerspace.pl
|
||||||
|
|
||||||
|
W przypadku jakichkolwiek pytań lub wątpliwości, napisz nam mejla na bofh@hackerspace.pl albo porozmawiaj z osobą która Cię zarekomendowała. Jesteśmy mili!
|
||||||
|
In case of any questions or issues, send us an email to bofh@hackerspace.pl or talk to the person that recommened you to the space. We'll be glad to help!
|
||||||
|
|
||||||
|
Happy hacking!
|
2
setup.py
2
setup.py
|
@ -14,7 +14,7 @@ setup(
|
||||||
packages=["hsadmin"],
|
packages=["hsadmin"],
|
||||||
python_requires=">=3.8,",
|
python_requires=">=3.8,",
|
||||||
install_requires=["kadmin", "setuptools", "jinja2", "ldap3"],
|
install_requires=["kadmin", "setuptools", "jinja2", "ldap3"],
|
||||||
package_data={"hsadmin": ["krb5.conf", "password_reset.jinja2"]},
|
package_data={"hsadmin": ["krb5.conf", "password_reset.jinja2", "welcome.txt"]},
|
||||||
entry_points={
|
entry_points={
|
||||||
"console_scripts": [
|
"console_scripts": [
|
||||||
"hs-admin=hsadmin.cmd:main",
|
"hs-admin=hsadmin.cmd:main",
|
||||||
|
|
Loading…
Reference in New Issue