コード例 #1
0
    def boot(self, view: View, request: Request):
        """Add helper functions to Masonite."""
        builtins.view = view.render
        builtins.request = request.helper
        builtins.auth = request.user
        builtins.container = self.app.helper
        builtins.env = os.getenv
        builtins.resolve = self.app.resolve
        builtins.route = request.route
        if self.app.has(MailManager):
            builtins.mail_helper = self.app.make(MailManager).helper
        builtins.dd = DD(self.app).dump

        view.share({
            'request': request.helper,
            'auth': request.user,
            'request_method': set_request_method,
            'route': request.route,
            'back': back,
            'sign': sign,
            'unsign': unsign,
            'decrypt': decrypt,
            'encrypt': encrypt,
            'config': config,
            'optional': optional,
            'dd': builtins.dd,
            'hidden': hidden,
            'exists': view.exists,
            'cookie': request.get_cookie,
            'url':
            lambda name, params={}: request.route(name, params, full=True),
            'old': old
        })
コード例 #2
0
    def store(self, request: Request, view: View):
        """
        Generate a new token, return to chess/@token/ @show
        """
        cur_user = request.user()

        friend = request.input('friend', clean=True).strip()
        friend_email = User.where('email', friend).limit(1).first()

        if not friend_email:
            return view.render("invalid",
                               {"message": 'Username is not exists'})

        friend_email = friend_email.email
        user_email = cur_user.email

        if friend_email == user_email:
            return view.render("invalid", {"message": 'You cannot play alone'})

        token = token_hex(16)

        Table.create(
            owner=user_email,
            user_id=user_email,
            oppo_id=friend_email,
            token=token,
            completed=False,
            last_move_timestamp=current_time(),
            next_id=user_email,
            move='',
        )
        return request.redirect("/play/@token", {'token': token})
コード例 #3
0
ファイル: ConfirmController.py プロジェクト: parajdsdada/core
    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': request.app().make('Application'), 'Auth': auth})

        return view.render('auth/error', {'app': request.app().make('Application'), 'Auth': auth})
コード例 #4
0
    def show(self, view: View, request: Request):
        token = request.param('token')
        # guest = OneTimeService.where('remember_token', token).get()
        # name = guest.pluck('customer_name')[0]
        # address = guest.pluck('address')[0]
        # email = guest.pluck('email')[0]
        # cell_phone = guest.pluck('cell_phone')[0]
        # service_id = guest.pluck('id')[0]
        if request.user():
            user=request.user()
            firstname = user.firstname
            lastname = user.lastname
            address = user.address
            service_id = request.param('slug')
            token = user.remember_token
            return view.render('schedule', {"address": address, "firstname": firstname, "lastname": lastname, "service_id": service_id, 'token': token}) 
        
        elif not request.user() and not token:
            # token = request.param('token')
            # return view.render('schedule', {'token': token})
            return view.render('schedule')

            # return view.render('schedule', {'name':name, 'address':address, 'email': email, 'cell_phone':cell_phone, 'token': token})
        elif not request.user():
            token = request.param('token')
            guest = OneTimeService.where('remember_token', token).get()
            name = guest.pluck('customer_name')[0]
            address = guest.pluck('address')[0]
            email = guest.pluck('email')[0]
            cell_phone = guest.pluck('cell_phone')[0]
            return view.render('schedule', {'name':name, 'address':address, 'email': email, 'cell_phone':cell_phone, 'token': token})

        else:
            return request.redirect('/login')
コード例 #5
0
 def boot(self, view: View, event: Event):
     view.share({
         'show_if': self._show_if,
         'env': os.getenv,
         'DEBUG': application.DEBUG
     })
     event.subscribe(UserSignedUp)
コード例 #6
0
    def handle(self):
        class_name = self.argument('name')
        view = View(App())
        class_directory = '{}{}.py'.format(self.base_directory, class_name)

        if not make_directory(class_directory):
            return self.error('{0} Already Exists!'.format(self.scaffold_name))

        with open(class_directory, 'w+') as f:
            if view.exists(self.template):
                f.write(
                    view.render(self.template, {
                        'class': class_name.split('/')[-1]
                    }).rendered_template)
                self.info('{} Created Successfully!'.format(
                    self.scaffold_name))

        if self.option('migration'):
            model_name = class_name.lower() + 's'
            self.call('migration',
                      [('name', 'create_{}_table'.format(model_name)),
                       ('-c', model_name)])

        if self.option('seed'):
            seed_file = model_name
            seed_file = self.option('seed')

            self.call('seed', [('table', seed_file)])
コード例 #7
0
    def handle(self):
        view = View(App())
        class_directory = 'databases/seeds/{}_table_seeder.py'.format(
            self.argument('table'))

        if not make_directory(class_directory):
            pass
            # return self.error('{0} Seeder Already Exists!'.format(self.argument('table')))

        conn = DB.get_schema_manager().list_table_columns(
            self.argument('table'))
        # docstring = '"""Model Definition (generated with love by Masonite) \n\n'
        # for name, column in conn.items():
        #     length = '({})'.format(column._length) if column._length else ''
        #     docstring += '{}: {}{} default: {}\n'.format(
        #         name, column.get_type(), length, column.get_default())

        f = open(class_directory, 'w+')
        if view.exists('scaffold/seed'):
            f.write(
                view.render('scaffold/seed', {
                    'table': self.argument('table'),
                    'columns': conn.items(),
                }).rendered_template)
            self.info('Seeder Created Successfully!')
            return f.close()
コード例 #8
0
    def setup_method(self):
        self.app = App()

        self.app.bind('Test', object)
        self.app.bind('MailSmtpDriver', object)
        self.app.bind('MailConfig', mail)
        self.app.bind('View', View(self.app).render)
        self.app.bind('ViewClass', View(self.app))
コード例 #9
0
ファイル: SessionProvider.py プロジェクト: sanketsaurav/core
    def boot(self, request: Request, view: View, session: SessionManager):
        self.app.bind('Session',
                      session.driver(self.app.make('SessionConfig').DRIVER))
        self.app.swap(Session,
                      session.driver(self.app.make('SessionConfig').DRIVER))
        request.session = self.app.make('Session')

        view.share({'session': self.app.make('Session').helper})
コード例 #10
0
 def boot(self, manager: UploadManager, view: View):
     self.app.bind('Upload',
                   manager.driver(self.app.make('StorageConfig').DRIVER))
     self.app.swap(Upload,
                   manager.driver(self.app.make('StorageConfig').DRIVER))
     view.share({
         'static': static,
     })
コード例 #11
0
 def show(self, view: View):
     if Path('storage/static/schemas/petshop.json'
             ):  # then we have a schema
         return view.render('swagger-ui',
                            {'schema': '/static/schemas/petshop.json'})
     else:  # return petstore
         return view.render(
             'swagger-ui',
             {'schema': 'https://petstore3.swagger.io/api/v3/openapi.json'})
コード例 #12
0
    def setUp(self):
        self.app = App()
        self.app = self.app.bind('Container', self.app)

        self.app.bind('Test', object)
        self.app.bind('MailSmtpDriver', object)
        self.app.bind('MailConfig', mail)
        self.app.bind('View', View(self.app).render)
        self.app.bind('ViewClass', View(self.app))
コード例 #13
0
    def boot(self, view: View):
        """Add custom helper functions to Masonite."""

        builtins.return_with_errors = return_with_errors
        builtins.error_response = error_json_response
        builtins.success_response = success_json_response
        builtins.abort_404 = abort_404
        builtins.abort_403 = abort_403

        view.share({"mix": mix})
コード例 #14
0
    def show(self, view: View, request: Request):
        if request.user():
            return view.render('account_cancel')

        elif not request.user():
            today = date.today()
            token = request.param('token')
            decoded_token = jwt.decode(token, 'secret', algorithm='HS256')
            guest = OneTimeService.where(
                'email', decoded_token['email']).update(cancelled_on=today)

            return view.render('mail/cancel_guest', {'token': token})
コード例 #15
0
    def show(self, view: View, request: Request):
        if request.input('search'):
            users = self.__auth__.all().filter(lambda user: self.search(request.input('search'), user))
        else:
            users = self.__auth__.all()

        return view.render('{0}/management/management'.format(self.template_prefix), {'users': users})
コード例 #16
0
 def setup_method(self):
     self.app = App()
     self.app.bind('Application', ApplicationMock)
     self.app.bind('View', View(self.app).render)
     self.app.bind('Storage', StorageMock)
     self.app.bind('ExceptionHandler', ExceptionHandler(self.app))
     self.app.bind('HookHandler', Hook(self.app))
コード例 #17
0
 def setup_method(self):
     self.app = App()
     self.app.bind('Request', Request(None).load_app(self.app))
     self.app.bind('Application', MockApplicationConfig)
     self.app.bind('ViewClass', View(self.app))
     self.app.bind('View', self.app.make('ViewClass').render)
     self.hook = ServerErrorExceptionHook().load(self.app)
コード例 #18
0
    def index(self, view: View, request: Request):
        path = config('browserlog.BROWSERLOG_STORAGE_PATH')
        log_files = listdir(path)

        logs = []
        q = int(request.input('q', '0'))

        action = request.input('action')

        if action == 'clean':
            open('{0}/{1}'.format(path, log_files[q]), 'w').close()

        if action == 'download':
            return Download('{0}/{1}'.format(path, log_files[q]),
                            name=log_files[q].split('.')[0],
                            force=True)

        try:
            log_files[q]
        except IndexError:
            q = 0

        for line in open('{0}/{1}'.format(path, log_files[q]), 'r'):
            if parse_log(line):
                logs.append(parse_log(line))

        return view.render('browserlog/index.html', {
            'log_files': log_files,
            'logs': logs,
            'q': q
        })
コード例 #19
0
    def index(self, view: View):
        projects = Project.all()

        return view.render('projects', {
            'name': 'Joe',
            'projects': projects,
        })
コード例 #20
0
    def cancel(self, view: View, request: Request, auth: Auth):
        today_date = date.today()
        id = request.param('slug')

        cancelled_date = Schedule.where(
            'id', request.param('slug')).get().pluck('cancelled_on')

        if cancelled_date[0] is not None:
            auth.logout()
            return view.render('pool_appointment_cancel',
                               {'cancelled_date': cancelled_date})

        else:
            Schedule.find(id).update(cancelled_on=today_date)
            auth.logout()
            return view.render('pool_appointment_cancel')
コード例 #21
0
 def show(self, request: Request, view: View):
     if not Auth(request).user():
         request.redirect('/login')
     return view.render('auth/home', {
         'app': request.app().make('Application'),
         'Auth': Auth(request)
     })
コード例 #22
0
    def show(self, view: View, request: Request):
        project = Project.find(request.param('id'))

        return view.render('projects', {
            'name': 'Joe',
            'project': project,
        })
コード例 #23
0
    def setUp(self):
        self.app = App()
        self.app.bind('Environ', generate_wsgi())
        self.app.bind('Application', application)
        self.app.make('Environ')
        self.app.bind('StatusCode', None)
        self.app.bind('Request',
                      Request(self.app.make('Environ')).load_app(self.app))
        self.app.simple(Response(self.app))
        self.app.bind('Csrf', Csrf(self.app.make('Request')))
        self.app.bind('Route', Route(self.app.make('Environ')))

        self.app.bind('ViewClass', View(self.app))

        self.app.bind(
            'WebRoutes',
            [Get().route('/', 'TestController@show').middleware('test')])

        self.app.bind('HttpMiddleware', [MiddlewareHttpTest])

        self.app.bind('RouteMiddleware', {
            'test': MiddlewareTest,
            'throttle:1,2': MiddlewareValueTest
        })

        self.provider = RouteProvider()
        self.provider.app = self.app
コード例 #24
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},
         )
コード例 #25
0
 def show(self, view: View, request: Request):
     user = request.user()
     customer_schedules = Schedule.where('schedule_id', user.id).get()
     address = user.address
     return view.render('pool_appointments', {
         'customer_schedules': customer_schedules,
         'address': address
     })
コード例 #26
0
    def setup_method(self):
        self.app = App()

        self.app.bind('Test', object)
        self.app.bind('MailConfig', mail)
        self.app.bind('MailLogDriver', MailLogDriver)
        self.app.bind('MailTerminalDriver', MailTerminalDriver)
        self.app.bind('View', View(self.app))
コード例 #27
0
        def setup_method(self):
            self.app = App()

            self.app.bind('Test', object)
            self.app.bind('MailConfig', mail)
            self.app.bind('MailSmtpDriver', MailDriver)
            self.app.bind('MailMailgunDriver', Mailgun)
            self.app.bind('View', View(self.app))
コード例 #28
0
 def show(self, view: View):
     hotelId = self.request.param('hotelId')
     hotelDiv = ehotal.getHotel(hotelId)
     return view.render(
         'hotelView', {
             'hotelIntroduce': hotelDiv['hotelIntroduce'],
             'hotelInfo': hotelDiv['hotelInfo']
         })
コード例 #29
0
    def handle(self):
        class_name = self.argument('name') + self.postfix
        view = View(App())
        class_directory = '{}{}{}{}'.format(
            self.base_directory, class_name, self.suffix, self.file_extension)

        if not make_directory(class_directory):
            return self.error('{0} Already Exists!'.format(self.scaffold_name))

        f = open(class_directory, 'w+')
        if view.exists(self.template):
            f.write(
                view.render(self.template, {
                            'class': class_name.split('/')[-1]}).rendered_template
            )
            self.info('{} Created Successfully!'.format(self.scaffold_name))
            return f.close()
コード例 #30
0
 def setup_method(self):
     self.app = App()
     self.app.bind('StatusCode', '404 Not Found')
     self.app.bind('Request', Request(None).load_app(self.app))
     self.app.bind('ViewClass', View(self.app))
     self.app.bind('View', self.app.make('ViewClass').render)
     self.provider = StatusCodeProvider().load_app(self.app).boot(
         self.app.make('StatusCode'), self.app.make('Request'))