Exemplo n.º 1
0
def show_success_pdf(request):
    """
    Given there is valid information in the session
    this view sends an encrypted mail to C3S staff with the users data set
    and returns a PDF for the user.

    It is called after visiting the verification URL/page/view in
    def success_verify_email below.
    """
    #check if user has used form or 'guessed' this URL
    if ('appstruct' in request.session):
        # we do have valid info from the form in the session
        #print("-- valid session with data found")
        # send mail to accountants // prepare a mailer
        mailer = get_mailer(request)
        # prepare mail
        appstruct = request.session['appstruct']
        message_recipient = request.registry.settings['c3smembership.mailaddr']
        appstruct['message_recipient'] = message_recipient
        the_mail = accountant_mail(appstruct)
        mailer.send(the_mail)

        return generate_pdf(request.session['appstruct'])
    # 'else': send user to the form
    #print("-- no valid session with data found")
    return HTTPFound(location=request.route_url('join'))
Exemplo n.º 2
0
def show_success_pdf(request):
    """
    Given there is valid information in the session
    this view sends an encrypted mail to C3S staff with the users data set
    and returns a PDF for the user.

    It is called after visiting the verification URL/page/view in
    def success_verify_email below.
    """
    # check if user has used form or 'guessed' this URL
    if 'appstruct' in request.session:
        # we do have valid info from the form in the session
        # print("-- valid session with data found")
        # send mail to accountants // prepare a mailer
        mailer = get_mailer(request)
        # prepare mail
        appstruct = request.session['appstruct']
        message_recipient = request.registry.settings['c3smembership.mailaddr']
        appstruct['message_recipient'] = message_recipient
        the_mail = accountant_mail(appstruct)
        if 'true' in request.registry.settings['testing.mail_to_console']:
            print(the_mail.body)
        else:
            try:
                mailer.send(the_mail)
            except:
                # if mailout fails for some reason (gnupg, whatever), we need
                # 1) a mail to staff, so we take notice and fix it
                # 2) a message to $user, so she does not worry
                staff_mail = Message(
                    subject=_("[yes][ALERT] check the logs!"),
                    sender="*****@*****.**",
                    recipients=['*****@*****.**'],
                    body="""
problems! problems!

this is {}

a user could not download her pdf, because....
maybe gnupg failed? something else?

go fix it!
                    """.format(request.registry.settings['c3smembership.url']))
                mailer.send(staff_mail)

                request.session.flash(
                    u"Oops. we hit a bug. Staff will be "
                    u"informed. We will come back to you "
                    u"once we fixed it!",
                    'message_to_user'  # msg queue f. user
                )
                return HTTPFound(request.route_url('error_page'))

        return generate_pdf(request.session['appstruct'])
    # 'else': send user to the form
    # print("-- no valid session with data found")
    return HTTPFound(location=request.route_url('join'))
Exemplo n.º 3
0
def show_success_pdf(request):
    """
    Given there is valid information in the session
    this view sends an encrypted mail to C3S staff with the users data set
    and returns a PDF for the user.

    It is called after visiting the verification URL/page/view in
    def success_verify_email below.
    """
    # check if user has used form or 'guessed' this URL
    if 'appstruct' in request.session:
        # we do have valid info from the form in the session
        # print("-- valid session with data found")
        # send mail to accountants // prepare a mailer
        mailer = get_mailer(request)
        # prepare mail
        appstruct = request.session['appstruct']
        message_recipient = request.registry.settings['c3smembership.mailaddr']
        appstruct['message_recipient'] = message_recipient
        the_mail = accountant_mail(appstruct)
        if 'true' in request.registry.settings['testing.mail_to_console']:
            print(the_mail.body)
        else:
            try:
                mailer.send(the_mail)
            except:
                # if mailout fails for some reason (gnupg, whatever), we need
                # 1) a mail to staff, so we take notice and fix it
                # 2) a message to $user, so she does not worry
                staff_mail = Message(subject=_("[yes][ALERT] check the logs!"),
                                     sender="*****@*****.**",
                                     recipients=['*****@*****.**'],
                                     body="""
problems! problems!

this is {}

a user could not download her pdf, because....
maybe gnupg failed? something else?

go fix it!
                    """.format(request.registry.settings['c3smembership.url']))
                mailer.send(staff_mail)

                request.session.flash(
                    _(u"Oops. we hit a bug. Staff will be "
                      u"informed. We will come back to you "
                      u"once we fixed it!",
                      'message_to_user')  # msg queue f. user
                )
                return HTTPFound(request.route_url('error_page'))

        return generate_pdf(request.session['appstruct'])
    # 'else': send user to the form
    # print("-- no valid session with data found")
    return HTTPFound(location=request.route_url('join'))
Exemplo n.º 4
0
def show_success_pdf(request):
    """
    This view just returns a PDF, given there is valid info in session
    """
    #check if user has used form or 'guessed' this URL
    if ('appstruct' in request.session):
        # we do have valid info from the form in the session
        #print("-- valid session with data found")
        # send mail to accountants // prepare a mailer
        mailer = get_mailer(request)
        # prepare mail
        appstruct = request.session['appstruct']
        the_mail = accountant_mail(appstruct)
        mailer.send(the_mail)

        return generate_pdf(request.session['appstruct'])
    # 'else': send user to the form
    #print("-- no valid session with data found")
    return HTTPFound(location=request.route_url('join'))
Exemplo n.º 5
0
    def test_accountant_mail(self):
        """
        test creation of email Message object
        """
        from c3smembership.utils import accountant_mail
        import datetime
        my_appstruct = {
            'firstname': u'Jöhn test_accountant_mail',
            'lastname': u'Doe',
            'email': u'*****@*****.**',
            'email_confirm_code': 'ABCDEFGH',
            'address1': 'address part one',
            'address2': 'address part two',
            'postcode': 'POSTCODE',
            'city': u'Town',
            'country': u'af',
            'date_of_birth': datetime.date(1987, 6, 5),
            'membership_type': u'normal',
            'member_of_colsoc': u'yes',
            'name_of_colsoc': u'Foo Colsoc',
            'num_shares': 7,
            # hä?
            'message_recipient': '*****@*****.**',
            'date_of_submission': datetime.datetime.now(),
        }
        result = accountant_mail(my_appstruct)
        print result.body

        from pyramid_mailer.message import Message

        self.assertTrue(isinstance(result, Message))
        self.assertTrue('*****@*****.**' in result.recipients)
        self.failUnless('-BEGIN PGP MESSAGE-' in result.body,
                        'something missing in the mail body!')
        self.failUnless('-END PGP MESSAGE-' in result.body,
                        'something missing in the mail body!')
        print result.subject
        self.failUnless(
            '[C3S] Yes! a new member' in result.subject,
            'something missing in the mail subject!')
        self.failUnless('*****@*****.**' == result.sender,
                        'something missing in the mail body!')
Exemplo n.º 6
0
    def test_accountant_mail(self):
        """
        test creation of email Message object
        """
        from c3smembership.utils import accountant_mail
        import datetime
        my_appstruct = {
            'firstname': u'Jöhn test_accountant_mail',
            'lastname': u'Doe',
            'email': u'*****@*****.**',
            'email_confirm_code': 'ABCDEFGH',
            'address1': 'address part one',
            'address2': 'address part two',
            'postcode': 'POSTCODE',
            'city': u'Town',
            'country': u'af',
            'date_of_birth': datetime.date(1987, 6, 5),
            'membership_type': u'normal',
            'member_of_colsoc': u'yes',
            'name_of_colsoc': u'Foo Colsoc',
            'num_shares': 7,
            # hä?
            'message_recipient': '*****@*****.**',
            'date_of_submission': datetime.datetime.now(),
        }
        result = accountant_mail(my_appstruct)
        print result.body

        from pyramid_mailer.message import Message

        self.assertTrue(isinstance(result, Message))
        self.assertTrue('*****@*****.**' in result.recipients)
        self.failUnless('-BEGIN PGP MESSAGE-' in result.body,
                        'something missing in the mail body!')
        self.failUnless('-END PGP MESSAGE-' in result.body,
                        'something missing in the mail body!')
        print result.subject
        self.failUnless('[C3S] Yes! a new member' in result.subject,
                        'something missing in the mail subject!')
        self.failUnless('*****@*****.**' == result.sender,
                        'something missing in the mail body!')
Exemplo n.º 7
0
def show_success_pdf(request):
    """
    Given there is valid information in the session
    this view sends an encrypted mail to C3S staff with the users data set
    and returns a PDF for the user.
    """
    #check if user has used form or 'guessed' this URL
    if ('appstruct' in request.session):
        # we do have valid info from the form in the session
        #print("-- valid session with data found")
        # send mail to accountants // prepare a mailer
        mailer = get_mailer(request)
        # prepare mail
        appstruct = request.session['appstruct']
        message_recipient = request.registry.settings['c3smembership.mailaddr']
        appstruct['message_recipient'] = message_recipient
        the_mail = accountant_mail(appstruct)
        mailer.send(the_mail)

        return generate_pdf(request.session['appstruct'])
    # 'else': send user to the form
    #print("-- no valid session with data found")
    return HTTPFound(location=request.route_url('join'))