def push(self, *objects, args=(), kwargs={}, **options):
        """Push objects onto the async stack.

        Arguments:
            objects {*args of objects} - This can be several objects as parameters into this method.
            options {**kwargs of options} - Additional options for async driver
        """

        # Initialize Extra Options
        callback = options.get('callback', 'handle')
        mode = options.get('mode',
                           config('queue.drivers.async.mode', 'threading'))
        workers = options.get('workers', None)

        # Set processor to either use threads or processes
        processor = self._get_processor(mode=mode, max_workers=workers)
        is_blocking = config('queue.drivers.async.blocking', False)

        ran = []
        for obj in objects:
            obj = self.container.resolve(obj) if inspect.isclass(obj) else obj
            try:
                future = processor.submit(getattr(obj, callback), *args,
                                          **kwargs)
            except AttributeError:
                # Could be wanting to call only a method asyncronously
                future = processor.submit(fn=obj, *args, **kwargs)

            ran.append(future)

        if is_blocking:
            for job in as_completed(ran):
                self.info("Job Ran: {}".format(job))
示例#2
0
 def __init__(self, driver=None, path=None):
     path = path or config('logging.channels.daily.path')
     path = os.path.join(path, self.get_time().to_date_string() + '.log')
     self.max_level = config('logging.channels.daily.level')
     make_directory(path)
     self.driver = DriverFactory.make(
         driver or config('logging.channels.daily.driver'))(
             path=path, max_level=self.max_level)
示例#3
0
 def __init__(self, container):
     self.container = container
     self.view = self.container.make("View")
     self.root_view = config("inertia.root_view")
     self.shared_props = {}
     self.rendered_template = ""
     # parameters
     self.include_flash_messages = config("inertia.include_flash_messages")
     self.include_routes = config("inertia.include_routes")
     if self.include_routes:
         self._load_routes()
示例#4
0
 def __init__(self,
              app: App,
              request: Request,
              driver=None,
              auth_model=None):
     self.app = app
     self.request = request
     self._once = False
     self.auth_model = auth_model or config('auth.auth.guards.api.model')
     self.driver = self.make(driver
                             or config('auth.auth.guards.api.driver'))
示例#5
0
def mix(filename):
    manifest = config("resources.public_path") + "/mix-manifest.json"

    with open(manifest) as file:
        data = json.load(file)

    return "/static" + data[filename]
示例#6
0
    def push(self, *objects, args=(), kwargs={}, **options):
        """Push objects onto the async stack.

        Arguments:
            objects {*args of objects} - This can be several objects as parameters into this method.
            options {**kwargs of options} - Additional options for async driver
        """

        # Initialize Extra Options
        callback = options.get('callback', 'handle')
        mode = options.get('mode', config('queue.drivers.async.mode', 'threading'))
        workers = options.get('workers', None)

        # Set processor to either use threads or processes
        processsor = self._get_processor(mode=mode, max_workers=workers)

        with processsor as executor:
            for obj in objects:
                obj = self.container.resolve(obj) if inspect.isclass(obj) else obj
                try:
                    executor.submit(
                        fn=getattr(obj, callback), args=args, kwargs=kwargs)
                except AttributeError:
                    # Could be wanting to call only a method asyncronously
                    executor.submit(fn=obj, args=args, kwargs=kwargs)
示例#7
0
    def boot(self, request: Request, response: Response):
        """Boots services required by the container."""
        headers = config('middleware.cors') or {}
        request.header(headers)

        if request.get_request_method().lower() == 'options':
            response.view('preflight')
示例#8
0
    def store(
        self,
        request: Request,
        mail_manager: MailManager,
        auth: Auth,
        validate: Validator,
    ):

        errors = request.validate(
            validate.required(["name", "email", "password"]),
            validate.email("email"),
            validate.not_in_database(
                "email",
                table="users",
                column="email",
                messages={"email": "This email address is already registered"},
            ),
            validate.confirmed("password"),
            validate.length(
                "password",
                min=config("auth.password_min_length"),
                max=config("auth.password_max_length"),
            ),
        )

        if errors:
            return return_with_errors(errors)

        auth.register({
            "name": request.input("name"),
            "password": request.input("password"),
            "email": request.input("email"),
        })

        user = User.where("email", request.input("email")).first()

        if isinstance(user, MustVerifyEmail):
            user.verify_email(mail_manager, request)

        # Login the user
        if auth.login(user.email, request.input("password")):
            request.session.flash(
                "success",
                "Your account has been successfully created. Check your email to verify your email address.",
            )
            return request.redirect("/")
示例#9
0
 def reset(self, view: View, request: Request, auth: Auth):
     token = request.param("token")
     user = AUTH["guards"]["web"]["model"].where("remember_token", token).first()
     if user:
         return view.render(
             "auth/reset",
             {"token": token, "app": config("application"), "Auth": auth},
         )
示例#10
0
 def reset(self, view: View, request: Request, auth: Auth):
     token = request.param('token')
     user = AUTH['guards']['web']['model'].where('remember_token',
                                                 token).first()
     if user:
         return view.render('auth/reset', {
             'token': token,
             'app': config('application'),
             'Auth': auth
         })
    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
        })
示例#12
0
    def register(self):
        from routes import web
        self.app.bind('HookHandler', Hook(self.app))
        self.app.bind('WebRoutes', flatten_routes(web.ROUTES))
        self.app.bind('Storage', config('storage'))
        self.app.bind('Route', Route())
        self.app.bind('Request', Request())
        self.app.simple(Response(self.app))
        self.app.bind('Container', self.app)
        self.app.bind('ExceptionHandler', ExceptionHandler(self.app))
        self.app.bind('ExceptionDumpExceptionHandler', DumpHandler)
        self.app.bind('AuthCookieDriver', AuthCookieDriver)
        self.app.bind('AuthJwtDriver', AuthJwtDriver)
        self.app.bind('AuthManager', AuthManager(self.app).driver('cookie'))
        self.app.bind('RouteMiddleware', config('middleware.route_middleware'))
        self.app.bind('HttpMiddleware', config('middleware.http_middleware'))
        self.app.bind('Auth', Auth)

        # Insert Commands
        self._load_commands()

        self._autoload(config('application.autoload'))
    def verify_show(self, view: View, auth: Auth):
        """Show the Verify Email page for unverified users.

        Arguments:
            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
        })
 def __init__(self, driver=None, path=None):
     token = config('logging.channels.slack.token')
     channel = config('logging.channels.slack.channel')
     emoji = config('logging.channels.slack.emoji')
     username = config('logging.channels.slack.username')
     self.max_level = config('logging.channels.slack.level')
     self.driver = DriverFactory.make(
         driver
         or config('logging.channels.slack.driver'))(emoji=emoji,
                                                     username=username,
                                                     token=token,
                                                     channel=channel)
示例#15
0
    def __init__(self,
                 validations,
                 table,
                 column,
                 connection="",
                 messages={},
                 raises={}):
        """

        :param validations: From parent class
        :param table:   The table name
        :param column:  The column name
        :param connection:  The connection
        """
        super().__init__(validations, messages, raises)
        self.table = table
        self.column = column
        self.connection = connection or config("database.databases.default")
示例#16
0
    def __init__(self, app: App, auth_model=None):
        """Auth constructor.

        Arguments:
            request {masonite.request.Request} -- The Request object.

        Keyword Arguments:
            auth_model {object} -- The model you want to authenticate with (default: {None})
        """
        self.request = app.make('Request')

        if auth_model:
            self.auth_model = auth_model
        else:
            from config import auth
            self.auth_model = auth.AUTH['model']

        self.driver = config('auth.auth.driver', 'cookie')