def __init__(self, controller):
        self.controller = controller
        self.__uploads = None
        self.process_uploads = False
        self.upload_actions = ('add', 'edit')
        self.cloud_storage_bucket = controller.Meta.cloud_storage_bucket if hasattr(controller.Meta, 'cloud_storage_bucket') else None

        if not self.cloud_storage_bucket and settings.get('upload').get('use_cloud_storage'):
            self.cloud_storage_bucket = settings.get('upload', {}).get('bucket') or app_identity.get_default_gcs_bucket_name()

        controller.events.before_startup += self.on_before_startup
        controller.events.scaffold_before_apply += self.on_scaffold_before_apply
        controller.events.after_dispatch += self.on_after_dispatch
Exemple #2
0
    def logout(self):
        get_auth().unset_session()

        next = self.request.params.get('next', None)
        if not next:
            next = settings.get('db_login')['logout_dest_url']
        return self.redirect(next)
Exemple #3
0
    def login(self):
        form = LoginForm()
        self.parse_request(container=form)

        if self.request.method != 'GET' and form.validate():
            email = str(form.email.data)
            password = str(form.password.data)
            try:
                db_user = get_auth().get_user_by_password(email,
                                                          password,
                                                          remember=True,
                                                          save_session=True)

                logging.info("Login succeeded for user %s", email)
                self._flash('Login succeded!', 'success')

                next = str(form.next.data)
                if not next:
                    next = settings.get('db_login')['login_dest_url']
                return self.redirect(next)

            except (InvalidAuthIdError, InvalidPasswordError) as e:
                logging.info('Login failed for user %s because of %s', email,
                             type(e))
                self._flash(
                    'Login failed. Check your credentials and try again.',
                    'error')

        self.context['form'] = form
def send(recipient, subject, body, text_body=None, sender=None, reply_to=None, **kwargs):
    """
    Sends an html email to ``recipient`` with the given ``subject`` and ``body``.

    If ``sender`` is none, it's automatically set to ``app_config['email']['sender']``.

    If ``text_body`` is not specified, then ``body`` is used.

    Any additionally arguments are passed to ``mail.send_mail``, such as headers.
    """
    sender = sender if sender else settings.get('email')['sender']
    if not sender:
        sender = "noreply@%s.appspotmail.com" % app_identity.get_application_id()
        logging.info("No sender configured, using the default one: %s" % sender)

    if not text_body:
        text_body = body

    res = mail.send_mail(
        sender=sender,
        to=recipient,
        subject=subject,
        body=text_body,
        html=body,
        reply_to=reply_to if reply_to else sender,
        **kwargs)
    logging.info('Email sent to %s by %s with subject %s and result %s' % (recipient, sender, subject, res))
    return res
Exemple #5
0
 def logout(self):
     get_auth().unset_session()
     
     next = self.request.params.get('next', None)
     if not next:
         next = settings.get('db_login')['logout_dest_url']
     return self.redirect(next)
Exemple #6
0
def require_auth_domain(controller):
    user = controller.user
    if user:
        domain = user.email().split('@').pop()
        allowed_domains = settings.get('app_config')['allowed_auth_domains']
        if domain not in allowed_domains:
            message = "Your domain, %s, does not have access to this application" % domain
            return False, message

    return True
Exemple #7
0
def send(recipient, subject, body, sender=None, reply_to=None, **kwargs):
    """
    Sends an html email to ``recipient`` with the given ``subject`` and ``body``.

    If sender is none, it's automatically set to ``app_config['email']['sender']``.

    Any additionally arguments are passed to ``mail.send_mail``, such as headers.
    """
    sender = sender if sender else settings.get('email')['sender']
    if not sender:
        raise ValueError('No sender configured in settings')
    res = mail.send_mail(
        sender=sender,
        to=recipient,
        subject=subject,
        body=body,
        html=body,
        reply_to=reply_to if reply_to else sender,
        **kwargs)
    logging.info('Email sent to %s by %s with subject %s and result %s' % (recipient, sender, subject, res))
    return res
Exemple #8
0
def send(recipient, subject, body, sender=None, reply_to=None, **kwargs):
    """
    Sends an html email to ``recipient`` with the given ``subject`` and ``body``.

    If sender is none, it's automatically set to ``app_config['email']['sender']``.

    Any additionally arguments are passed to ``mail.send_mail``, such as headers.
    """
    sender = sender if sender else settings.get('email')['sender']
    if not sender:
        raise ValueError('No sender configured in settings')
    res = mail.send_mail(sender=sender,
                         to=recipient,
                         subject=subject,
                         body=body,
                         html=body,
                         reply_to=reply_to if reply_to else sender,
                         **kwargs)
    logging.info('Email sent to %s by %s with subject %s and result %s' %
                 (recipient, sender, subject, res))
    return res
    def start(self, session):
        config = settings.get('oauth2')

        session = ndb.Key(urlsafe=session).get()
        callback_uri = self.uri(action='callback', _full=True)

        flow = OAuth2WebServerFlow(client_id=config['client_id'],
                                   client_secret=config['client_secret'],
                                   scope=session.scopes,
                                   redirect_uri=callback_uri)

        flow.params['state'] = session.key.urlsafe()

        if session.admin or session.force_prompt:
            flow.params['approval_prompt'] = 'force'

        uri = flow.step1_get_authorize_url()

        session.flow = flow
        session.put()

        return self.redirect(uri)
    def start(self, session):
        config = settings.get('oauth2')

        session = ndb.Key(urlsafe=session).get()
        callback_uri = self.uri(action='callback', _full=True)

        flow = OAuth2WebServerFlow(
            client_id=config['client_id'],
            client_secret=config['client_secret'],
            scope=session.scopes,
            redirect_uri=callback_uri)

        flow.params['state'] = session.key.urlsafe()

        if session.admin or session.force_prompt:
            flow.params['approval_prompt'] = 'force'

        uri = flow.step1_get_authorize_url()

        session.flow = flow
        session.put()

        return self.redirect(uri)
Exemple #11
0
    def login(self):
        form = LoginForm()
        self.parse_request(container=form)
        
        if self.request.method != 'GET' and form.validate():
            email = str(form.email.data)
            password = str(form.password.data)
            try:
                db_user = get_auth().get_user_by_password(email, password,
                    remember=True, save_session=True)

                logging.info("Login succeeded for user %s", email)
                self._flash('Login succeded!', 'success')
                
                next = str(form.next.data)
                if not next:
                    next = settings.get('db_login')['login_dest_url']
                return self.redirect(next)
                
            except (InvalidAuthIdError, InvalidPasswordError) as e:
                logging.info('Login failed for user %s because of %s', email, type(e))
                self._flash('Login failed. Check your credentials and try again.', 'error')
                
        self.context['form'] = form
Exemple #12
0
def send(recipient,
         subject,
         body,
         text_body=None,
         sender=None,
         reply_to=None,
         **kwargs):
    """
    Sends an html email to ``recipient`` with the given ``subject`` and ``body``.

    If ``sender`` is none, it's automatically set to ``app_config['email']['sender']``.

    If ``text_body`` is not specified, then ``body`` is used.

    Any additionally arguments are passed to ``mail.send_mail``, such as headers.
    """
    sender = sender if sender else settings.get('email')['sender']
    if not sender:
        sender = "noreply@%s.appspotmail.com" % app_identity.get_application_id(
        )
        logging.info("No sender configured, using the default one: %s" %
                     sender)

    if not text_body:
        text_body = body

    res = mail.send_mail(sender=sender,
                         to=recipient,
                         subject=subject,
                         body=text_body,
                         html=body,
                         reply_to=reply_to if reply_to else sender,
                         **kwargs)
    logging.info('Email sent to %s by %s with subject %s and result %s' %
                 (recipient, sender, subject, res))
    return res
Exemple #13
0
import httplib2, logging, urllib2
from apiclient.discovery import build
from apiclient import errors
from ferris import retries
from plugins import service_account
from ferris.core import settings

scopes = ('https://www.googleapis.com/auth/calendar')

DEVELOPER_KEY = settings.get('oauth2_service_account')['developer_key']


def build_client(user):
    logging.info('calendar: build_client')
    try:
        http = httplib2.Http()
        credentials = service_account.build_credentials(scopes, user)
        credentials.authorize(http)
        calendar = build('calendar',
                         'v3',
                         http=http,
                         developerKey=DEVELOPER_KEY)
        return calendar
    except urllib2.HTTPError, err:
        logging.info('build_client HTTPError!')
        logging.info(str(err))
        return build_client(user)


def get_all_events(email,
                   selectedEmail,
from ferris import fix_imports
(fix_imports)

# Import the application

import ferris
import ferris.app
import ferris.deferred_app
import ferris.routes
import app.routes
import app.listeners
from ferris.core import settings
(app)

main_app = ferris.app.app  # Main application
deferred_app = ferris.deferred_app.app  # Deferred application

settings.load_settings()
appstats_settings = settings.get('appstats', {})

if (appstats_settings.get('enabled', False) and ferris.app.debug) or appstats_settings.get('enabled_live', True):
    from google.appengine.ext.appstats import recording
    main_app = recording.appstats_wsgi_middleware(main_app)
Exemple #15
0
from ferris import fix_imports
(fix_imports)

# Import the application

import ferris
import ferris.app
import ferris.deferred_app
import ferris.routes
import app.routes
import app.listeners
from ferris.core import settings
(app)

main_app = ferris.app.app  # Main application
deferred_app = ferris.deferred_app.app  # Deferred application

settings.load_settings()
appstats_settings = settings.get('appstats', {})

if (appstats_settings.get('enabled', False)
        and ferris.app.debug) or appstats_settings.get('enabled_live', True):
    from google.appengine.ext.appstats import recording
    main_app = recording.appstats_wsgi_middleware(main_app)
Exemple #16
0
"""
The App module provides the main WSGI app for ferris.
See /settings.py to configure the app. See app/routes.py
to configure routing
"""

from ferris.core.wsgi import WSGIApp
from ferris.core import settings

# Entry point
app = WSGIApp(debug=True, config=settings.get('app_config'))

from ferris.controllers import errors
app.error_handlers[400] = errors.handle_400
app.error_handlers[401] = errors.handle_401
app.error_handlers[403] = errors.handle_403
app.error_handlers[404] = errors.handle_404
app.error_handlers[500] = errors.handle_500
"""
The App module provides the main WSGI app for ferris.
See /settings.py to configure the app. See app/routes.py
to configure routing
"""

import os
from webapp2 import WSGIApplication
from ferris.core import settings

# Only enable debug mode locally.
debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev')

# Here's the main application, loads the config from the Ferris
# Settings API.
app = WSGIApplication(
    debug=debug,
    config=settings.get('app_config'))

# Custom Error Handlers
from ferris.controllers import errors
app.error_handlers[400] = errors.handle_400
app.error_handlers[401] = errors.handle_401
app.error_handlers[403] = errors.handle_403
app.error_handlers[404] = errors.handle_404
app.error_handlers[500] = errors.handle_500
Exemple #18
0
import httplib2, logging, urllib2
from apiclient.discovery import build
from apiclient import errors
from ferris import retries
from plugins import service_account
from ferris.core import settings

scopes = (
    'https://www.googleapis.com/auth/calendar'
    )

DEVELOPER_KEY = settings.get('oauth2_service_account')['developer_key']


def build_client(user):
    logging.info('calendar: build_client')
    try:
        http = httplib2.Http()
        credentials = service_account.build_credentials(scopes, user)
        credentials.authorize(http)
        calendar = build('calendar', 'v3', http=http, developerKey=DEVELOPER_KEY)
        return calendar
    except urllib2.HTTPError, err:
        logging.info('build_client HTTPError!')
        logging.info(str(err))
        return build_client(user)


def get_all_events(email, selectedEmail, singleEvents=False, page_token=None, iCalUID=None):
    logging.info('calendar: get_all_events')
    response = None
Exemple #19
0
"""
The App module provides the main WSGI app for ferris.
See /settings.py to configure the app. See app/routes.py
to configure routing
"""

import os
from webapp2 import WSGIApplication
from ferris.core import settings

# Only enable debug mode locally.
debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev')

# Here's the main application, loads the config from the Ferris
# Settings API.
app = WSGIApplication(debug=debug, config=settings.get('app_config'))

# Custom Error Handlers
from ferris.controllers import errors

app.error_handlers[400] = errors.handle_400
app.error_handlers[401] = errors.handle_401
app.error_handlers[403] = errors.handle_403
app.error_handlers[404] = errors.handle_404
app.error_handlers[500] = errors.handle_500