Пример #1
0
def _notify_password_change(username, comment=None):
    """Send email about a password change.

    :param username:
    :param comment: a string to include indicating how/why the password was
                    reset

    >>> _notify_password_change('ckuehl', comment='Your password was reset in the lab.')
    """

    name = search.user_attrs(username)['cn'][0]
    body = """Howdy there {name},

Just a quick heads up that your Open Computing Facility account password was
just reset, hopefully by you.
{comment_line}
As a reminder, your OCF username is: {username}

If you're not sure why this happened, please reply to this email ASAP.

{signature}""".format(
        name=name,
        username=username,
        signature=mail.MAIL_SIGNATURE,
        comment_line=('\n' + comment + '\n') if comment else '',
    )

    mail.send_mail_user(username, '[OCF] Account password changed', body)
Пример #2
0
def send_mass_mail(target_log, dry_run):
    username_site_pairs = []
    contact_list = []
    with open(target_log) as t_l:
        for line in t_l:
            contact_list.append(line.strip('\n'))

    vhosts = get_vhosts()
    for vhost_url in vhosts.keys():
        site = 'http://' + vhost_url
        if site in contact_list:
            username_site_pairs.append((vhosts[vhost_url]['username'],
                                        vhost_url))

    # Sanity check
    assert len(username_site_pairs) == len(contact_list)

    if not dry_run:
        print('Emailing...')
        for user, site in username_site_pairs:
            name = search.user_attrs(user)['cn'][0]
            try:
                print(user)
                mail.send_mail_user(user, subject.format(user=user),
                                    email_body.format(user=user, name=name, site=site))
            except Exception as e:
                print((name, user, site, e))
    else:
        print("Actual run would've emailed the following:")
        for user, site in username_site_pairs:
            print(user)
Пример #3
0
def _notify_password_change(username, comment=None):
    """Send email about a password change.

    :param username:
    :param comment: a string to include indicating how/why the password was
                    reset

    >>> _notify_password_change('ckuehl', comment='Your password was reset in the lab.')
    """

    name = search.user_attrs(username)['cn'][0]
    body = """Howdy there {name},

Just a quick heads up that your Open Computing Facility account password was
just reset, hopefully by you.
{comment_line}
As a a reminder, your OCF username is: {username}

If you're not sure why this happened, please reply to this email ASAP.

{signature}""".format(
        name=name,
        username=username,
        signature=constants.MAIL_SIGNATURE,
        comment_line=('\n' + comment + '\n') if comment else '',
    )

    mail.send_mail_user(username, '[OCF] Account password changed', body)
Пример #4
0
    def test_send_mail_user(self, mock_popen):
        send_mail_user(
            'ckuehl',
            'hello world',
            'this is a body',
            sender='ocflib <*****@*****.**>',
        )

        msg = self.get_message(mock_popen)
        assert msg['Subject'] == 'hello world'
        assert msg['From'] == 'ocflib <*****@*****.**>'
        assert msg['To'] == '*****@*****.**'
        assert msg.get_payload() == 'this is a body'
Пример #5
0
def _notify_password_change(username):
    """Send email about a password change."""

    name = search.user_attrs(username)['cn'][0]
    body = """Howdy there {name},

Just a quick heads up that your Open Computing Facility account password was
just reset, hopefully by you.

As a a reminder, your OCF username is: {username}

If you're not sure why this happened, please reply to this email ASAP.

{signature}""".format(name=name,
                      username=username,
                      signature=constants.MAIL_SIGNATURE)

    mail.send_mail_user(username, '[OCF] Account password changed', body)
Пример #6
0
def email_reset(request):
    error = None
    # Validate that the email is legitimate

    if request.method == 'POST':
        # Submitted a username to reset.
        form = EmailAccountForm(request.POST)

        if form.is_valid():
            account = form.cleaned_data['ocf_account']

            try:
                # TODO: Use account real name instead?
                reset_link = 'https://ocf.berkeley.edu/account/reset/continue?token={}'.format(
                    'asdfasdf')
                send_mail_user(
                    account,
                    '[OCF] Link to reset your password',
                    reset_message.format(username=account,
                                         reset_link=reset_link),
                )
            except ValueError as ex:
                error = str(ex)
            else:
                return render(
                    request,
                    'account/resetpass/sent.html',
                    {
                        'account': account,
                        'title': 'Password Reset Email Sent',
                    },
                )
    else:
        form = EmailAccountForm()

    return render(
        request,
        'account/resetpass/index.html',
        {
            'error': error,
            'form': form,
            'title': 'Reset Password',
        },
    )