def send_password_reset(requesting_user, userid): user_to_update = User.create_user(userid) if not requesting_user.can_administrate(user_to_update): return AUTHORIZATION_DENIED verify_code = helpers.create_verify_code(user_to_update.username, requesting_user.username) ppr = PendingPasswordReset(user_to_update.username) ppr.requestor_username = requesting_user.username ppr.verify_code = verify_code ppr.save() log_action('sending password reset', ppr) url = url_for('reset_password', username=user_to_update.username, code=verify_code, _external=True) ppr.send_reset_email( user_to_update.email, user_to_update.first_name, url, "{0} {1}".format(requesting_user.first_name, requesting_user.last_name), ) return "{}", 202
def test_properties(): ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.verify_code = 'bibble' assert ppr.username == 'abc' assert ppr.requestor_username == 'dave' assert ppr.verify_code == 'bibble'
def test_clear_old_password_resets(self): ppr = PendingPasswordReset('old') ppr.requestor_username = '******' ppr.verify_code = 'bibble-old' ppr.save() self._make_old('password_resets', 'old') ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.verify_code = 'bibble-new' ppr.save() helpers.clear_old_password_resets() ppr = PendingPasswordReset('old') assert not ppr.in_db ppr = PendingPasswordReset('abc') assert ppr.in_db
def test_creation(): ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.verify_code = 'bibble' ppr.save() assert ppr.in_db ppr = PendingPasswordReset('abc') assert ppr.in_db assert ppr.username == 'abc' assert ppr.requestor_username == 'dave' assert ppr.verify_code == 'bibble' age = ppr.age assert age > timedelta() assert age < timedelta(minutes=1)
def test_creation(): ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.verify_code = 'bibble' ppr.save() assert ppr.in_db ppr = PendingPasswordReset('abc') assert ppr.in_db assert ppr.username == 'abc' assert ppr.requestor_username == 'dave' assert ppr.verify_code == 'bibble' age = ppr.age assert age > timedelta() assert age < timedelta(minutes = 1)
def test_send_email(): first_name = 'jim' verification_url = 'https://verify' email = '*****@*****.**' requestor_name = 'Dave Smith' ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.send_reset_email(email, first_name, verification_url, requestor_name) ps = test_helpers.last_email() vars = ps.template_vars assert first_name == vars['name'] assert verification_url == vars['password_reset_url'] assert requestor_name == vars['requestor_name'] toaddr = ps.toaddr assert email == toaddr template = ps.template_name assert template == 'password_reset' test_helpers.assert_load_template(template, vars)
def test_send_email(): first_name = 'jim' verification_url = 'http://verify' email = '*****@*****.**' requestor_name = 'Dave Smith' ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.send_reset_email(email, first_name, verification_url, requestor_name) ps = test_helpers.last_email() vars = ps.template_vars assert first_name == vars['name'] assert verification_url == vars['password_reset_url'] assert requestor_name == vars['requestor_name'] toaddr = ps.toaddr assert email == toaddr template = ps.template_name assert template == 'password_reset' test_helpers.assert_load_template(template, vars)
def setup_password_reset(for_user, verify_code): ppr = PendingPasswordReset(for_user) ppr.requestor_username = '******' ppr.verify_code = verify_code ppr.save()