Beispiel #1
0
def create_app():
	env = DotEnv()
	app = Flask(__name__)
	env.init_app(app)
	env.eval(keys={
		'DEBUG': bool,
		'TESTING': bool
	})
	mail = Mail(app)
	mail.init_app(app)

	@app.route("/", methods=['GET', 'POST'])
	def index():
		"""
			Render the view of index page.
		"""
		form = FeedbackForm()
		return render_template('index.html', title='Tri Sinergi Mitra', current_page='TSM', form=form)

	@app.route("/send_feedback", methods=['POST'])
	def send_feedback():
		"""
			Do action with python form
		"""
		if request.method == 'POST' :
			#result = request.form
			result = request.form['email']
			msg_subject = "You got an email from {} / {} - {}".format(request.form['email'], request.form['full_name'], request.form['subject'])
			msg_body = request.form['body']
			send_email(msg_subject,'*****@*****.**', ['*****@*****.**'], msg_body)
			return redirect(url_for('index'))
		else:
			flash('The message has not been sent due to unknown failure')
			return redirect(url_for('index'))

	def send_email(subject, sender, recipients, text_body):
		msg = Message(subject, sender=sender, recipients=recipients)
		msg.body = text_body
		mail.send(msg)
		return

	@app.errorhandler(404)
	def page_not_found_error(err):
		"""
		Render the view of error 404 page
		"""
		return render_template('404.html', title='TSM not found', current_page='404')

	@app.errorhandler(500)
	def internal_server_error(err):
		"""
		Render the view of error 500 page
		"""
		return render_template('500.html', title='TSM internal server error', current_page='500')


	return app
 def init_app(cls, app: Flask, env_files: List):
     """ .env file load """
     env = DotEnv()
     config_py_path = os.path.realpath(__file__)
     app_path = os.path.dirname(config_py_path)
     project_root_path = os.path.dirname(app_path)
     app.config['ROOT_DIR'] = project_root_path
     for env_file in env_files:
         env_file = project_root_path + env_file
         env.init_app(app, env_file=env_file, verbose_mode=cls.DEBUG)
     env.eval(keys={
         "MYSQL_PORT": int,
         "PORT": int,
     })
     app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI.format(
         USER=app.config['MYSQL_DATABASE_USERNAME'],
         PASSWORD=app.config['MYSQL_ROOT_PASSWORD'],
         ADDR=app.config['MYSQL_DATABASE_HOST'],
         PORT=app.config['MYSQL_PORT'],
         NAME=app.config['MYSQL_DATABASE'])
Beispiel #3
0
from flask import stream_with_context
from flask import url_for
from flask_dotenv import DotEnv
from smartcard.System import readers
from beaker.middleware import SessionMiddleware
from smartcard.Exceptions import NoCardException
from smartcard.System import readers
from smartcard.util import toHexString
from binascii import unhexlify, b2a_base64
import time

app = Flask(__name__)
env = DotEnv()
env.init_app(app)
env.eval(keys={
	'DEBUG': bool,
	'TESTING': bool
})
app.logger.setLevel(app.config['LOG_LEVEL'])

url = './data/'

@app.route("/")
def index():
	import time
	import os
	"""
		Render the view of index page.
	"""
	write_data_to_file("is_at_index", 'data_exist')
	app.logger.debug('Accessing main page of raspberry application!')
	r = readers()