Example #1
0
def notify_new_order_to_admin_by_email(order_state, request):
    admin_email = Config.get_string_value('config.admin_email')
    if admin_email != None and admin_email != '':
        localizer = get_localizer(request)

        # Create the body of the message (a plain-text and an HTML version).
        text_ts = _('plain_new_order_admin_mail',
            mapping={'name': order_state.order.user.name,
                     'login': order_state.order.user.login,
                     'units': order_state.order.units,
                     'address': order_state.order.address,
                     'url': request.route_url('orders'),
                     'state': _('order_state_0',
                                domain='Ondestán')},
            domain='Ondestan')
        html_ts = _('html_new_order_admin_mail',
            mapping={'name': order_state.order.user.name,
                     'login': order_state.order.user.login,
                     'units': order_state.order.units,
                     'address': order_state.order.address,
                     'url': request.route_url('orders'),
                     'state': _('order_state_0',
                                domain='Ondestán')},
            domain='Ondestan')
        subject_ts = _('subject_new_order_admin_mail', domain='Ondestan')

        text = localizer.translate(text_ts)
        html = localizer.translate(html_ts)
        subject = localizer.translate(subject_ts)

        send_mail(html, text, subject, admin_email)
Example #2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings,
                          root_factory='ondestan.models.RootFactory')
    Config.init_settings(settings)

    from ondestan.services import user_service
    from ondestan.utils.db import Db

    Db.instance()
    logger = logging.getLogger('ondestan')
    authn_policy = AuthTktAuthenticationPolicy(
        'ondestan', callback=user_service.group_finder
    )
    authz_policy = ACLAuthorizationPolicy()
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.add_translation_dirs('ondestan:locale')
    config.add_route('default', '/')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('reminder', '/reminder')
    config.add_route('password_reset', '/password_reset/{loginhash}')
    config.add_route('signup', '/signup')
    config.add_route('signup_success', '/signup_success')
    config.add_route('update_profile', '/update_profile')
    config.add_route('activate_user', '/activate/{loginhash}')
    config.add_route('gps_update', '/gps_update')

    config.add_route('check_login', '/check_login')
    config.add_route('check_email', '/check_email')

    config.add_route('orders', '/orders')
    config.add_route('order_state_history', '/orders/history/{order_id}')

    config.add_route('map', '/map')
    config.add_route('json_animals', '/json/animals.json')
    config.add_route('json_plots', '/json/plots.json')
    config.scan()

    logger.info('Application initialized')

    return config.make_wsgi_app()
Example #3
0
    def __init__(self):
        host = expandvars(Config.get_string_value('db.host'))
        port = expandvars(Config.get_string_value('db.port'))
        db = expandvars(Config.get_string_value('db.dbname'))
        user = expandvars(Config.get_string_value('db.user'))
        password = expandvars(Config.get_string_value('db.password'))

        conn_str = 'postgresql+psycopg2://' + user + ':' + password + \
                         '@' + host + ':' + port + '/' + db
        self.engine = create_engine(
            conn_str,
            echo=True
        )

        Session = sessionmaker(bind=self.engine)

        self.session = Session()

        ## Create all Tables

        Base.metadata.create_all(self.engine)
Example #4
0
def send_mail(html, text, subject, destination):

    smtp_server = Config.get_string_value('smtp.server')
    smtp_port = Config.get_int_value('smtp.port')
    smtp_mail = Config.get_string_value('smtp.mail')
    smtp_password = Config.get_string_value('smtp.password')

    # Create message container - the correct MIME type is multipart/alternative
    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = smtp_mail
    msg['To'] = destination

    # Record the MIME types of both parts - text/plain and text/html.
    part1 = MIMEText(text, 'plain', 'UTF-8')
    part2 = MIMEText(html, 'html', 'UTF-8')

    # Attach parts into message container.
    # According to RFC 2046, the last part of a multipart message, in this case
    # the HTML message, is best and preferred.
    msg.attach(part1)
    msg.attach(part2)

    server = SMTP(smtp_server, smtp_port)
    server.starttls()

    #Next, log in to the server
    server.login(smtp_mail, smtp_password)

    #Send the mail
    # sendmail function takes 3 arguments:
    # sender's address
    # recipient's address
    # and message to send - here it is sent as one string.
    server.sendmail(smtp_mail, destination, msg.as_string())
    server.quit()