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))
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)
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()
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'))
def mix(filename): manifest = config("resources.public_path") + "/mix-manifest.json" with open(manifest) as file: data = json.load(file) return "/static" + data[filename]
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)
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')
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("/")
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 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 })
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)
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")
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')