def password_forgotten(email: str): # retrieve the user user = find_user(email) # generate a password reset code user.reset_code = get_random_string(16) # send a password reset message send_email( user.name, user.email, "Reset your password", f"To reset your password, use this very secure code: {user.reset_code}.\nRegards, The DevNotes team" ) # write server log log(f"User with email address {user.email} requested a password reset")
def register_new_user(name: str, password: str, email: str): # create an entry in the database user = create_user(name, password, email) # post a Slack message to sales department post_slack_message( "sales", f"{user.name} has registered with email address {user.email}. Please spam this person incessantly." ) # send a welcome email send_email( user.name, user.email, "Welcome", f"Thanks for registering, {user.name}!\nRegards, The DevNotes team") # write server log log(f"User registered with email address {user.email}")
def upgrade_plan(email: str): # find the user user = find_user(email) # upgrade the plan user.plan = "paid" # post a Slack message to sales department post_slack_message("sales", f"{user.name} has upgraded their plan.") # send a thank you email send_email( user.name, user.email, "Thank you", f"Thanks for upgrading, {user.name}! You're gonna love it. \nRegards, The DevNotes team" ) # write server log log(f"User with email address {user.email} has upgraded their plan")
def post_verification_form(): if not discord.authorized: return redirect(url_for('discord.login')) user = discord.get('/api/users/@me').json() if check_user_verified(user['id']): return 'You are already verified, please contact us if you want to change your details.' data = validate_form(request.form) code = str(uuid.uuid4()) # TODO: validation with open(f'data/{user["id"]}', 'w') as f: f.write(json.dumps({ **data, 'verified': False, 'code': code, 'discord_id': user['id'], 'discord_name': f'{user["username"]}#{user["discriminator"]}' })) if data['automated']: send_email(data['email'], f'{config.APP_SERVER_NAME} Discord Verification', EMAIL_TEMPLATE_AUTO.format( name=data['name'], server_name=config.APP_SERVER_NAME, contact_email=config.APP_CONTACT_EMAIL, verification_url=f'{config.APP_BASE_URL}/verification/link/{user["id"]}/{code}' )) else: send_email(data['email'], f'Manual {config.APP_SERVER_NAME} Discord Verification', EMAIL_TEMPLATE_NOAUTO.format( name=data['name'], server_name=config.APP_SERVER_NAME, contact_email=config.APP_CONTACT_EMAIL, ), config.APP_CONTACT_EMAIL) return 'Please check your email for an activation link.'
def handle_user_registered_event(user): # send a welcome email send_email( user.name, user.email, "Welcome", f"Thanks for registering, {user.name}!\nRegards, The DevNotes team")
def handle_user_upgrade_plan_event(user): # send a thank you email send_email( user.name, user.email, "Thank you", f"Thanks for upgrading, {user.name}! You're gonna love it. \nRegards, The DevNotes team" )
def handle_user_password_forgotten_event(user): # send a password reset message send_email( user.name, user.email, "Reset your password", f"To reset your password, use this very secure code: {user.reset_code}.\nRegards, The DevNotes team" )
from purpleair.sensor import Sensor from lib import aqi, email, message, sensor_data ALAMO_SQUARE = 65759 LYON_STREET = 17951 UPPER_HAIGHT = 17763 USF_STADIUM = 38725 SENSORS_NEAR_ME = [ALAMO_SQUARE, LYON_STREET, UPPER_HAIGHT, USF_STADIUM] raw_sensors = [Sensor(id) for id in SENSORS_NEAR_ME] sensors = [ sensor_data.convert_to_sensor_data(Sensor(id)) for id in SENSORS_NEAR_ME ] sorted_sensors = sorted(sensors, key=lambda s: s.aqi) recipients = ['*****@*****.**'] message, subject = message.get_text(sorted_sensors) email.send_email(message, subject, recipients)