def send_bulk_password_reset_links(users_csv): """ Send bulk password reset links for the included emails. Argument is a CSV, which will be read for an email column. """ for row in csv_reader(os.path.join('/noi', users_csv)): # TODO filter users we don't have in the DB # TODO Make sure we only send bulk password resets to inactive users # who have never confirmed their email (even better would be to add an # auto-added flag and only send to those, then mark that we've sent # them a reset link) # TODO specialize the email sent so it's not "reset your password" but # "Claim your NoI account" or somesuch, upon which password is set. user = User.query_in_deployment().filter_by(email=row['email']).one() send_reset_password_instructions(user)
def add_fake_users(users_csv): """ Add a bunch of fake users from a CSV. Will set bogus passwords for them. """ # TODO make sure each fake user is pre- confirmed, otherwise the password # reset link we send them will require an email confirmation after the fact, # confusing # TODO add an auto-added flag (source) for row in csv_reader(os.path.join("/noi", users_csv)): row["password"] = "".join(choice(string.letters + string.digits) for _ in range(20)) row["active"] = False # TODO is this OK? user = User(**row) db.session.add(user) try: db.session.commit() except IntegrityError: db.session.rollback() app.logger.warn('Could not add user with email "%s", as they are ' "already in the database.", row["email"])
def add_fake_users(users_csv): """ Add a bunch of fake users from a CSV. Will set bogus passwords for them. """ # TODO make sure each fake user is pre- confirmed, otherwise the password # reset link we send them will require an email confirmation after the fact, # confusing # TODO add an auto-added flag (source) for row in csv_reader(os.path.join('/noi', users_csv)): row['password'] = ''.join( choice(string.letters + string.digits) for _ in range(20)) row['active'] = False # TODO is this OK? user = User(**row) db.session.add(user) try: db.session.commit() except IntegrityError: db.session.rollback() app.logger.warn( 'Could not add user with email "%s", as they are ' 'already in the database.', row['email'])