Example #1
0
def create_new_user(
    email,
    can_enter_data,
    can_delete_data,
    can_import_data,
    can_edit_parents,
    can_access_data,
    can_change_formats,
    can_use_api_key,
    can_admin,
):
    """Create and persist a new user, sending account info by email in process.

    @param email: The email address of the user to create an account for.
    @type email: str
    @param can_enter_data: Indicates if the user can add new data to the lab
        dataset.
    @type can_enter_data: bool
    @param can_delete_data: Indicates if the user can delete data from the lab
        dataset.
    @type can_delete_data: bool
    @param can_enter_data: Indicates if the user can add new data to the lab
        dataset by importing a CSV file.
    @type can_enter_data: bool
    @param can_access_data: Indicates if the user can access existing lab data.
    @type can_access_data: bool
    @param can_change_formats: Indicates if the user can edit MCDI forms,
        presentation formats, and percentile data tables.
    @type can_change_formats: bool
    @param can_use_api_key: Indicates if this user can use an API key.
    @type can_use_api_key: bool
    @param can_admin: Indicates if the user can administer user accounts and
        user access control.
    @type can_admin: bool
    """
    email = email.lower()
    password = generate_password()
    pass_hash = werkzeug.generate_password_hash(password, method="sha512")
    user = models.User(
        -1,
        email,
        pass_hash,
        can_enter_data,
        can_delete_data,
        can_import_data,
        can_edit_parents,
        can_access_data,
        can_change_formats,
        can_use_api_key,
        can_admin,
    )
    db_util.create_user_model(user)

    mail_util.send_msg(email, "Your DaxlabBase Account", SIGN_UP_MSG % (email, password))
Example #2
0
    def test_send_mail_with_keeper(self):
        self.mox.StubOutWithMock(mail_util, 'get_mail_keeper')
        mail_util.get_mail_keeper().AndReturn(TEST_MAIL_KEEPER)
        self.mox.ReplayAll()

        mail_util.send_msg('test address', 'test subject', 'test message')

        last_message = TEST_MAIL_INSTANCE.last_message
        self.assertEqual(last_message.subject, 'test subject')
        self.assertEqual(last_message.sender, 'from addr')
        self.assertEqual(last_message.body, 'test message')
        self.assertEqual(last_message.recipients, ['testaddress'])
Example #3
0
def reset_password(email, pass_len=10):
    """Set user's password to random string and send email with new credentials.

    @param email: The email of the user whose account password needs to be
        reset.
    @type email: str
    @keyword pass_len: The length in characters of the new password to generate.
    @type pass_len: int
    """
    email = email.lower()
    new_pass = generate_password(pass_len)
    change_user_password(email, new_pass)

    mail_util.send_msg(email, "Your DaxlabBase Account", RESET_PASSWORD_MSG % (email, new_pass))
def send_mcdi_email(parent_form):
    """Send an email with parent MCDI form information.

    Sends an email to a parent with a link that the parent can follow to fill
    out an MCDI form for thier child.

    @param parent_form: The form to send an email for.
    @type parent_form: models.ParentForm
    """
    form_url = URL_TEMPLATE % parent_form.form_id
    mail_util.send_msg(
        parent_form.parent_email,
        MCDI_EMAIL_SUBJECT,
        MCDI_EMAIL_TEMPLATE % (parent_form.child_name, form_url)
    )
    def test_send_mcdi_email(self):
        self.mox.StubOutWithMock(mail_util, 'send_msg')

        form_url = parent_account_util.URL_TEMPLATE % 'url'
        msg = parent_account_util.MCDI_EMAIL_TEMPLATE % ('child', form_url)

        mail_util.send_msg(
            'test email',
            parent_account_util.MCDI_EMAIL_SUBJECT,
            msg
        )

        self.mox.ReplayAll()

        test_form = TEST_PARENT_FORM('child', 'url', 'test email')
        parent_account_util.send_mcdi_email(test_form)
Example #6
0
    def test_send_mail_no_keeper(self):
        self.mox.StubOutWithMock(mail_util, 'get_mail_keeper')
        mail_util.get_mail_keeper().AndReturn(None)
        self.mox.ReplayAll()

        mail_util.send_msg('test address', 'test subject', 'test message')