Beispiel #1
0
    def test_request_gets_input_from_container(self):
        container = App()
        container.bind('WSGI', object)
        container.bind('Environ', wsgi_request)

        for provider in config('providers.providers'):
            provider().load_app(container).register()

        container.bind('Response', 'test')
        container.bind('WebRoutes', [
            Get().route('url', 'TestController@show'),
            Get().route('url/', 'TestController@show'),
            Get().route('url/@firstname', 'TestController@show'),
        ])

        container.bind('Response', 'Route not found. Error 404')

        for provider in config('providers.providers'):
            located_provider = provider().load_app(container)

            container.resolve(located_provider.boot)

        self.assertEqual(container.make('Request').input('application'), 'Masonite')
        self.assertEqual(container.make('Request').all(), {'application': 'Masonite'})
        container.make('Request').environ['REQUEST_METHOD'] = 'POST'
        self.assertEqual(container.make('Request').environ['REQUEST_METHOD'], 'POST')
        self.assertEqual(container.make('Request').input('application'), 'Masonite')
Beispiel #2
0
    def confirm_email(self, request: Request, view: View, auth: Auth):
        """Confirm User email and show the correct response.

        Arguments:
            request {masonite.request.request} -- The Masonite request class.
            request {masonite.view.view} -- The Masonite view class.
            request {masonite.auth.auth} -- The Masonite Auth class.

        Returns:
            [type] -- [description]
        """
        sign = Sign()
        token = sign.unsign(request.param('id'))

        if token is not None:
            tokenParts = token.split("::")
            if len(tokenParts) > 1:
                user = auth.auth_model.find(tokenParts[0])

                if user.verified_at is None:
                    timestamp = datetime.datetime.fromtimestamp(
                        float(tokenParts[1]))
                    now = datetime.datetime.now()
                    timestamp_plus_10 = timestamp + datetime.timedelta(
                        minutes=10)

                    if now < timestamp_plus_10:
                        user.verified_at = datetime.datetime.now()
                        user.save()

                        return view.render('auth/confirm', {
                            'app': config('application'),
                            'Auth': auth
                        })

        return view.render('auth/error', {
            'app': config('application'),
            'Auth': auth
        })
Beispiel #3
0
    def verify_show(self, view: View, auth: Auth):
        """Show the Verify Email page for unverified users.

        Arguments:
            request {masonite.request.request} -- The Masonite request class.
            request {masonite.view.view} -- The Masonite view class.
            request {masonite.auth.auth} -- The Masonite Auth class.

        Returns:
            [type] -- [description]
        """
        return view.render('auth/verify', {
            'app': config('application'),
            'Auth': auth
        })
Beispiel #4
0
    def setUp(self):
        self.app = App()

        self.app.bind('QueueAsyncDriver', QueueAsyncDriver)
        self.app.bind('QueueAmqpDriver', QueueAmqpDriver)
        self.app.bind('QueueDatabaseDriver', QueueDatabaseDriver)
        self.app.bind('Queueable', Queueable)
        self.app.bind('Container', self.app)
        self.app.bind('QueueManager', QueueManager(self.app))
        self.app.bind('Queue', QueueManager(self.app).driver(config('queue.driver')))
        self.drivers = ['async']
        self.modes = ['threading', 'multiprocess']

        if env('RUN_AMQP'):
            self.drivers.append('amqp')
        if env('RUN_QUEUE_DATABASE'):
            self.drivers.append('database')
Beispiel #5
0
container = App()

container.bind('WSGI', app)
container.bind('Container', container)

container.bind('Providers', [])
container.bind('WSGIProviders', [])
"""Bind all service providers
Let's register everything into the Service Container. Once everything is
in the container we can run through all the boot methods. For reasons
some providers don't need to execute with every request and should
only run once when the server is started. Providers will be ran
once if the wsgi attribute on a provider is False.
"""

for provider in config('providers.providers'):
    located_provider = provider()
    located_provider.load_app(container).register()
    if located_provider.wsgi:
        container.make('WSGIProviders').append(located_provider)
    else:
        container.make('Providers').append(located_provider)

for provider in container.make('Providers'):
    container.resolve(provider.boot)
"""Get the application from the container
Some providers may change the WSGI Server like wrapping the WSGI server
in a Whitenoise container for an example. Let's get a WSGI instance
from the container and pass it to the application variable. This
will allow WSGI servers to pick it up from the command line
"""