Exemple #1
0
def reset_password():
    if not g.config('password-reset', 'enabled'):
        abort(404)
    data = parse_request_data(allowed=_RESET_SCHEMA)
    user = _find_user(data)
    if user is None:
        return make_json_response(None, status_code=204)
    token = ResetTokensDAO.create(user.id, user.email)
    send_reset_password(user.email, token.code, user.name,
                        link_template=data.get('link-template'),
                        greeting=getattr(user, 'fullname', ''))
    return make_json_response(None, status_code=204)
Exemple #2
0
def reset_password():
    if not g.config('password-reset', 'enabled'):
        abort(404)
    data = parse_request_data(allowed=_RESET_SCHEMA)
    user = _find_user(data)
    if user is None:
        return make_json_response(None, status_code=204)
    token = ResetTokensDAO.create(user.id, user.email)
    send_reset_password(user.email,
                        token.code,
                        user.name,
                        link_template=data.get('link-template'),
                        greeting=getattr(user, 'fullname', ''))
    return make_json_response(None, status_code=204)
Exemple #3
0
    def test_send_reset_password_works(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertTrue(
                        message.subject.startswith('Password reset for'))
                self.assertTrue('https://localhost/?code=THE_CODE'
                                in message.body)
                self.assertTrue('THE_USERNAME' in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            mail.send_reset_password(
                '*****@*****.**', 'THE_CODE', 'THE_USERNAME',
                link_template='https://localhost/?code={{code}}',
                greeting='User Userowich')
Exemple #4
0
    def test_send_reset_password_works(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertTrue(
                    message.subject.startswith('Password reset for'))
                self.assertTrue(
                    'https://localhost/?code=THE_CODE' in message.body)
                self.assertTrue('THE_USERNAME' in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            mail.send_reset_password(
                '*****@*****.**',
                'THE_CODE',
                'THE_USERNAME',
                link_template='https://localhost/?code={{code}}',
                greeting='User Userowich')