def test_env_returns_bool(self): os.environ["bool"] = "True" assert env('bool') == True os.environ["bool"] = "true" assert env('bool') == True os.environ["bool"] = "False" assert env('bool') == False os.environ["bool"] = "false" assert env('bool') == False
def test_env_returns_bool(self): os.environ["bool"] = "True" self.assertTrue(env('bool')) os.environ["bool"] = "true" self.assertTrue(env('bool')) os.environ["bool"] = "False" self.assertFalse(env('bool')) os.environ["bool"] = "false" self.assertFalse(env('bool'))
def callback(self, view: View): code = self.request.input('code') response = requests.post('https://github.com/login/oauth/access_token', json={ 'client_id': env('GITHUB_CLIENT'), 'client_secret': env('GITHUB_SECRET'), 'code': code}, headers={'Accept': 'application/json'}) self.request.session.set( 'access_token', response.json()['access_token']) return self.request.redirect('/')
def test_send_mail_sends_with_queue(self): if env('RUN_MAIL'): self.app.bind('MailSmtpDriver', MailDriver) self.assertEqual( MailManager(self.app).driver('smtp').to( '*****@*****.**').queue().send('hi'), None)
def test_send_mail_sends(self): if env('RUN_MAIL'): self.app.bind('MailSmtpDriver', MailDriver) self.assertTrue( MailManager(self.app).driver('smtp').to( '*****@*****.**').send('hi'))
def send(self, request: Request, session: Session, mail: Mail, validate: Validator): errors = request.validate(validate.required('email'), validate.email('email')) if errors: return request.back().with_errors(errors) email = request.input('email') user = AUTH['guards']['web']['model'].where('email', email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = 'Please visit {}/password/{}/reset to reset your password'.format( env('SITE', 'http://localhost:8000'), user.remember_token) mail.subject('Reset Password Instructions').to( user.email).send(message) session.flash( 'success', 'If we found that email in our system then the email has been sent. Please follow the instructions in the email to reset your password.' ) return request.redirect('/password')
def send(self, request: Request, session: Session, mail: Mail, validate: Validator): errors = request.validate(validate.required("email"), validate.email("email")) if errors: return request.back().with_errors(errors) email = request.input("email") user = AUTH["guards"]["web"]["model"].where("email", email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = "Please visit {}/password/{}/reset to reset your password".format( env("SITE", "http://localhost:8000"), user.remember_token) mail.subject("Reset Password Instructions").to( user.email).send(message) session.flash( "success", "If we found that email in our system then the email has been sent. Please follow the instructions in the email to reset your password.", ) return request.redirect("/password")
def test_mail_sends_with_queue_and_without_queue(self): if env('RUN_MAIL'): self.assertEqual( MailManager(self.app).driver('smtp').to( '*****@*****.**').send('test queue'), None) self.assertEqual( MailManager(self.app).driver('smtp').queue().to( '*****@*****.**').send('test queue'), None)
def setUp(self): from wsgi import container self.container = container self.acting_user = False self.factory = Factory() self.withoutExceptionHandling() self.withoutCsrf() if not self._transaction: self.startTransaction() if hasattr(self, 'setUpFactories'): self.setUpFactories() if self.sqlite and env('DB_CONNECTION') != 'sqlite': raise Exception("Cannot run tests without using the 'sqlite' database.") if not self.transactions and self.refreshes_database: self.refreshDatabase()
def index(self, view: View): client_id = env('GITHUB_CLIENT') access_token = self.request.session.get('access_token') response = {'client_id': client_id, 'repos': []} if access_token: g = Github(access_token) print(g.get_user().name) response['repos'] = g.get_user().get_repos() repo = g.get_repo('vaibhavmule/vetted-interview') contents = repo.get_contents("README.md") print(contents, repo) file = repo.create_file( '.github/FUNDING.yml', 'Create FUNDING.yml', '# These are supported funding model platforms \n\n custom: paypal.me/VaibhavMule \n\n # Generated by @vaibhavmule' ) print(file) return view.render('index', response)
def show(self, view: View): pageNo = self.request.input('page') sort = self.request.input('sort') if self.request.input('sort') else 0 keyword = self.request.input('keyword') if self.request.input( 'keyword') else '' if pageNo == False: return self.request.redirect( env('APP_URL') + "/hotels?page=1&sort=0&keyword=") data = ehotal.getHotels(page=int(pageNo), sort=int(sort), keyword=keyword) hotels = data['data']['hotelList'] pages = data['data']['page'] return view.render('hotelsView', { 'hotelsList': hotels, 'pages': pages, 'sort': sort })
def send(self, request: Request, session: Session, mail: Mail): email = request.input("email") user = AUTH["model"].where("email", email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = "Please visit {}/password/{}/reset to reset your password".format( env("SITE", "http://localhost:8000"), user.remember_token) mail.subject("Reset Password Instructions").to(email).send(message) session.flash( "success", "Email sent. Follow the instruction in the email to reset your password.", ) return request.redirect("/password") else: session.flash( "error", "Could not send reset email. Please enter correct email.") return request.redirect("/password")
def send(self, request: Request, session: Session, mail: Mail): email = request.input('email') user = AUTH['model'].where('email', email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = 'Please visit {}/password/{}/reset to reset your password'.format( env('SITE', 'http://localhost:8000'), user.remember_token) mail.subject('Reset Password Instructions').to(email).send(message) session.flash( 'success', 'Email sent. Follow the instruction in the email to reset your password.' ) return request.redirect('/password') else: session.flash( 'error', 'Could not send reset email. Please enter correct email.') return request.redirect('/password')
"""Mail Settings.""" from masonite import env """From Address This value will be used for the default address when sending emails from your application. """ FROM = { "address": env("MAIL_FROM_ADDRESS", "*****@*****.**"), "name": env("MAIL_FROM_NAME", "Masonite"), } """Mail Driver The default driver you will like to use for sending emails. You may add additional drivers as you need or pip install additional drivers. Supported: 'smtp', 'mailgun' """ DRIVER = env("MAIL_DRIVER", "smtp") """Mail Drivers Different drivers you can use for sending email. """ DRIVERS = { "smtp": { "host": env("MAIL_HOST", "smtp.mailtrap.io"), "port": env("MAIL_PORT", "2525"),
"""Application Settings.""" import os from masonite import env """Application Name This value is the name of your application. This value is used when the framework needs to place the application's name in a notification or any other location as required by the application or its packages. """ NAME = env("APP_NAME", "Masonite 2.1") """Application Debug Mode When your application is in debug mode, detailed error messages with stack traces will be shown on every error that occurs within your application. If disabled, a simple generic error page is shown """ DEBUG = env("APP_DEBUG", False) """Secret Key This key is used to encrypt and decrypt various values. Out of the box Masonite uses this key to encrypt or decrypt cookies so you can use it to encrypt and decrypt various values using the Masonite Sign class. Read the documentation on Encryption to find out how. """ KEY = env("KEY", None) """Application URL Sets the root URL of the application. This is primarily used for testing """
from masonite import env from app.User import User """Authentication Model Put the model here that will be used to authenticate users to your site. Currently the model must contain a password field. In the model should be an auth_column = 'column' in the Meta class. This column will be used to verify credentials in the Auth facade or any other auth classes. The auth_column will be used to change auth things like 'email' to 'user' to easily switch which column will be authenticated. @see masonite.auth.Auth """ AUTH = { 'driver': env('AUTH_DRIVER', 'cookie'), 'model': User, } DRIVERS = { 'jwt': { """Whether or not to reauthenticate with the database when the token expires.""" 'reauthentication': True, """How long the token should live for before being refreshed.""" 'lifetime': '5 minutes' } }
"""Application Settings.""" import os from masonite import env """Application Name This value is the name of your application. This value is used when the framework needs to place the application's name in a notification or any other location as required by the application or its packages. """ NAME = env('APP_NAME', 'Masonite 2.3') """Application Debug Mode When your application is in debug mode, detailed error messages with stack traces will be shown on every error that occurs within your application. If disabled, a simple generic error page is shown """ DEBUG = env('APP_DEBUG', False) """Secret Key This key is used to encrypt and decrypt various values. Out of the box Masonite uses this key to encrypt or decrypt cookies so you can use it to encrypt and decrypt various values using the Masonite Sign class. Read the documentation on Encryption to find out how. """ KEY = env('KEY', None) """Application URL Sets the root URL of the application. This is primarily used for testing """
from masonite.testing import TestCase from config.database import Model from masonite import env class User(Model): pass if env('RUN_DATABASE'): class TestDatabase(TestCase): def setUp(self): super().setUp() self.make(User, self.users_factory, 20) def users_factory(self, faker): return { 'name': faker.name(), 'email': faker.email(), 'password': '******', # == 'secret' } def test_has_records(self): self.assertGreater(User.all().count(), 0)
"""Mail Settings.""" from masonite import env import os """From Address This value will be used for the default address when sending emails from your application. """ FROM = { 'address': env('MAIL_FROM_ADDRESS', '*****@*****.**'), 'name': env('MAIL_FROM_NAME', 'Masonite') } """Mail Driver The default driver you will like to use for sending emails. You may add additional drivers as you need or pip install additional drivers. Supported: 'smtp', 'mailgun' """ DRIVER = 'mailgun' """Mail Drivers Different drivers you can use for sending email. """ DRIVERS = { 'smtp': { 'host': env('MAIL_HOST', 'smtp.mailtrap.io'), 'port': env('MAIL_PORT', '465'), 'username': env('MAIL_USERNAME', 'username'), 'password': env('MAIL_PASSWORD', 'password'),
"""Broadcast Settings.""" from masonite import env """Broadcast Driver Realtime support is critical for any modern web application. Broadcast drivers allow you to push data from your server to all your clients to show data updates to your clients in real time without having to constantly refresh the page or send constant ajax requests Supported: 'pusher', 'ably' """ DRIVER = env("BROADCAST_DRIVER", "pusher") """Broadcast Drivers Below is a dictionary of all your driver configurations. Each key in the dictionary should be the name of a driver. """ DRIVERS = { "pusher": { "app_id": env("PUSHER_APP_ID", "29382xx.."), "client": env("PUSHER_CLIENT", "shS8dxx.."), "secret": env("PUSHER_SECRET", "HDGdjss.."), }, "ably": { "secret": env("ABLY_SECRET", "api:key") }, }
"""Application Settings.""" import os from masonite import env """Application Name This value is the name of your application. This value is used when the framework needs to place the application's name in a notification or any other location as required by the application or its packages. """ NAME = env("APP_NAME", "Masonite 3.0") """Application Debug Mode When your application is in debug mode, detailed error messages with stack traces will be shown on every error that occurs within your application. If disabled, a simple generic error page is shown """ DEBUG = env("APP_DEBUG", False) """Secret Key This key is used to encrypt and decrypt various values. Out of the box Masonite uses this key to encrypt or decrypt cookies so you can use it to encrypt and decrypt various values using the Masonite Sign class. Read the documentation on Encryption to find out how. """ KEY = env("KEY", None) """Application URL Sets the root URL of the application. This is primarily used for testing """
"""Storage Settings.""" from masonite import env """Storage Driver The default driver you will like to use for storing uploads. You may add additional drivers as you need or pip install additional drivers. Supported: 'disk', 's3', 'rackspace', 'googlecloud', 'azure' """ DRIVER = env('STORAGE_DRIVER', 'disk') """Storage Drivers Different drivers you can use for storing file uploads. """ DRIVERS = { 'disk': { 'location': { 'uploading': 'uploads/' } }, 's3': { 'client': env('S3_CLIENT', 'AxJz...'), 'secret': env('S3_SECRET', 'HkZj...'), 'bucket': env('S3_BUCKET', 's3bucket'), 'location': 'http://s3.amazon.com/bucket', 'test_locations': { 'test': 'value' } }, 'rackspace': {
More information about the available backends at https://python-social-auth.readthedocs.io/en/latest/backends/index.html """ SOCIAL_AUTH_AUTHENTICATION_BACKENDS = ( "social_core.backends.amazon.AmazonOAuth2", "social_core.backends.facebook.FacebookOAuth2", "social_core.backends.google.GoogleOAuth2", "social_core.backends.github.GithubOAuth2", "social_core.backends.twitter.TwitterOAuth", "social_core.backends.linkedin.LinkedinOAuth2", ) """ Amazon """ SOCIAL_AUTH_AMAZON_KEY = env("SOCIAL_AUTH_AMAZON_KEY") SOCIAL_AUTH_AMAZON_SECRET = env("SOCIAL_AUTH_AMAZON_SECRET") SOCIAL_AUTH_AMAZON_REDIRECT_URI = env("SOCIAL_AUTH_AMAZON_REDIRECT_URI") """ FACEBOOK Configurations """ SOCIAL_AUTH_FACEBOOK_KEY = env("SOCIAL_AUTH_FACEBOOK_KEY") SOCIAL_AUTH_FACEBOOK_SECRET = env("SOCIAL_AUTH_FACEBOOK_SECRET") SOCIAL_AUTH_FACEBOOK_REDIRECT_URI = env("SOCIAL_AUTH_FACEBOOK_REDIRECT_URI") SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = { "fields": "id, name, email", } """ GOOGLE OAuth2 Configurations """
"""Cache Settings.""" from masonite import env """Cache Driver Caching is a great way to gain an instant speed boost to your application. Very often templates will not change and you can utilize caching to the best by caching your templates forever, monthly or every few seconds Supported: 'disk' """ DRIVER = env("CACHE_DRIVER", "disk") """Cache Drivers Place all your caching coniguration as a dictionary here. The keys here should correspond to the driver types supported above. Supported: 'disk' """ DRIVERS = {"disk": {"location": "bootstrap/cache"}}
"""Authentication Model Put the model here that will be used to authenticate users to your site. Currently the model must contain a password field. In the model should be an auth_column = 'column' in the Meta class. This column will be used to verify credentials in the Auth facade or any other auth classes. The auth_column will be used to change auth things like 'email' to 'user' to easily switch which column will be authenticated. @see masonite.auth.Auth """ AUTH = { 'defaults': { 'guard': env('AUTH_GUARD', 'web') }, 'guards': { 'web': { 'driver': 'cookie', 'model': User, 'drivers': { # 'cookie', 'jwt' 'jwt': { 'reauthentication': True, 'lifetime': '5 minutes' } } }, } }
''' Mail Settings ''' from masonite import env ''' |-------------------------------------------------------------------------- | From Address |-------------------------------------------------------------------------- | | This value will be used for the default address when sending emails from | your application. | ''' FROM = { 'address': env('MAIL_FROM_ADDRESS', '*****@*****.**'), 'name': env('MAIL_FROM_NAME', 'Masonite') } ''' |-------------------------------------------------------------------------- | Mail Driver |-------------------------------------------------------------------------- | | The default driver you will like to use for sending emails. You may add | additional drivers as you need or pip install additional drivers. | | Supported: 'smtp', 'mailgun' | '''
Loads in the environment variables when this page is imported. """ LoadEnvironment() """Database Settings Set connection database settings here as a dictionary. Follow the format below to create additional connection settings. Each key is a connection, not a driver. You may have as many connections as you need. Supported Drivers: 'sqlite', 'mysql', 'postgres' """ DATABASES = { "default": env("DB_CONNECTION"), "sqlite": { "driver": "sqlite", "database": env("DB_DATABASE"), "log_queries": env("DB_LOG"), }, "mysql": { "driver": "mysql", "host": env("DB_HOST"), "database": env("DB_DATABASE"), "port": env("DB_PORT"), "user": env("DB_USERNAME"), "password": env("DB_PASSWORD"), "log_queries": env("DB_LOG"), }, "postgres": {
| Loads in the environment variables when this page is imported. | ''' load_dotenv(find_dotenv()) ''' |-------------------------------------------------------------------------- | Database Settings |-------------------------------------------------------------------------- | | Set connection database settings here as a dictionary. Follow the | format below to create additional connection settings. | | @see Orator migrations documentation for more info | ''' DATABASES = { 'default': { 'driver': env('DB_DRIVER'), 'host': env('DB_HOST'), 'database': env('DB_DATABASE'), 'user': env('DB_USERNAME'), 'password': env('DB_PASSWORD'), 'prefix': '' } } DB = DatabaseManager(DATABASES) Model.set_connection_resolver(DB)
""" LoadEnvironment() """Database Settings Set connection database settings here as a dictionary. Follow the format below to create additional connection settings. Each key is a connection, not a driver. You may have as many connections as you need. Supported Drivers: 'sqlite', 'mysql', 'postgres' """ DATABASES = { 'default': env('DB_CONNECTION'), 'sqlite': { 'driver': 'sqlite', 'database': env('DB_DATABASE'), 'log_queries': env('DB_LOG'), }, 'mysql': { 'driver': 'mysql', 'host': env('DB_HOST'), 'database': env('DB_DATABASE'), 'port': env('DB_PORT'), 'user': env('DB_USERNAME'), 'password': env('DB_PASSWORD'), 'log_queries': env('DB_LOG'), }, 'postgres': {
from app.models.User import User """Authentication Model Put the model here that will be used to authenticate users to your site. Currently the model must contain a password field. In the model should be an auth_column = 'column' in the Meta class. This column will be used to verify credentials in the Auth facade or any other auth classes. The auth_column will be used to change auth things like 'email' to 'user' to easily switch which column will be authenticated. @see masonite.auth.Auth """ AUTH = { 'defaults': { 'guard': env('AUTH_GUARD', 'api') }, 'guards': { 'web': { 'driver': 'cookie', 'model': User, 'drivers': { # 'cookie', 'jwt' 'jwt': { 'reauthentication': True, 'lifetime': '30 minutes' } } }, 'api': { 'driver': 'jwt', 'model': User,