Example #1
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(Conf)
    print('create_app')
    # redis
    app.redis_store = redis.Redis(host=app.config["REDIS_HOST"], port=app.config["REDIS_PORT"], decode_responses=True)

    app.config['SQLALCHEMY_DATABASE_URI'] = Conf.MYSQL_INFO
    app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # Mail
    app.config['MAIL_SERVER'] = Conf.MAIL_SERVER
    app.config['MAIL_PORT'] = Conf.MAIL_PORT
    app.config['MAIL_USE_TLS'] = Conf.MAIL_USE_TLS


    # 蓝图
    from app.admin import admin_api as admin_api_blueprint
    app.register_blueprint(admin_api_blueprint, url_prefix='/api/admin')

    from app.api.v1_0_0 import api_v1_0_0 as api_1_0_blueprint
    app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0.0')

    from app.api.v1_0_1 import api_v1_0_1 as api_1_1_blueprint
    app.register_blueprint(api_1_1_blueprint, url_prefix='/api/v1.0.1')

    # init
    db.init_app(app)
    return app
Example #2
0
def test_send_email():
    mailForm= MailForm()
    if mailForm.validate_on_submit():#表单提交成功的判断
        try:
            app = Flask(__name__)
            app.config['SECRET_KEY'] = 'qiyeboy'
            #下面是SMTP服务器配置
            app.config['MAIL_SERVER'] = 'smtp.163.com' #电子邮件服务器的主机名或IP地址
            app.config['MAIL_PORT'] = '25' #电子邮件服务器的端口
            app.config['MAIL_USE_TLS'] = True #启用传输层安全
            app.config['MAIL_USERNAME'] ='13259744109@163.com' #os.environ.get('MAIL_USERNAME') #邮件账户用户名
            app.config['MAIL_PASSWORD'] = 'hywd1993'#os.environ.get('MAIL_PASSWORD') #邮件账户的密码

            mail = Mail(app)
            receiverName = mailForm.receiver.data #收件人文本框的内容
            styledata = mailForm.style.data#主题文本框的内容
            bodydata  = mailForm.body.data#正文文本框的内容
            msg = Message(styledata,sender='13259744109@163.com',recipients=[receiverName])#发件人,收件人
            msg.body = bodydata
            # send_email('2531145412@qq.com','Test email-function',)
            mail.send(msg)
            flash('邮件发送成功!')#提示信息
            return redirect(url_for('.index'))
        except:
            flash('邮件发送失败!')
            return redirect(url_for('.index'))
    return render_template('testemail.html',form=mailForm,name ='13259744109@163.com' )#渲染网页



# @main.route('/secret')
# @login_required
# def secret():
#     return 'Only authenticated users are allowed!'
Example #3
0
	def create_app():

		global db, bootstrap, mail, login_manager, moment, pagedown
		app = Flask(__name__)

		from main import main as main_blueprint
		from auth import auth as auth_blueprint
		from admin import admin as admin_blueprint

		app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://flask:gf37888676@172.17.0.25/flask'
		app.config['SQLAlCHEMY_COMMIT_ON_TEARDOWN'] = True
		app.config['FLASK_ADMIN'] = 'iamawar3player@163.com'
		app.config['FLASK_MAIL_SUBJECT_PREFIX'] = '[Flasky]'
		app.config['FLASK_MAIL_SENDER'] = 'Flasky Admin <iamawar3player@163.com>'
		app.config['MAIL_SERVER'] = 'smtp.163.com'
		app.config['MAIL_PORT'] = 25
		app.config['MAIL_USE_TLS'] = False
		app.config['MAIL_USERNAME'] = 'iamawar3player@163.com'
		app.config['MAIL_PASSWORD'] = 'fan86797121'
		app.config['DEBUG'] = True
		app.config['FLASKY_POSTS_PER_PAGE'] = 10
		app.config['SECRET_KEY'] = 'gf37888676'
		app.register_blueprint(main_blueprint)
		app.register_blueprint(auth_blueprint, url_prefix='/auth')
		app.register_blueprint(admin_blueprint, url_prefix='/admin')

		db = db.init_app(app)
		mail = mail.init_app(app)
		bootstrap = bootstrap.init_app(app)
		login_manager = login_manager.init_app(app)
		moment = moment.init_app(app)
		pagedown = pagedown.init_app(app)

		return app
Example #4
0
def create_app():
    app = Flask(__name__)
    app.config.update(
        CELERY_BROKER_URL='redis://localhost:6379/0',
        CELERY_RESULT_BACKEND='redis://localhost:6379/0'
    )
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 587
    app.config['MAIL_USE_TLS'] = True
    app.config['MAIL_USERNAME'] = admin_imap
    app.config['MAIL_PASSWORD'] = admin_pass
    app.config['MAIL_DEFAULT_SENDER'] = 'server-error@example.com'

    return app
Example #5
0
from wtforms import StringField, SubmitField
from wtforms.validators import Required
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.mail import Mail, Message

basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess string'
app.config['SQLALCHEMY_DATABASE_URI'] =\
    'sqlite:///' + os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['MAIL_SERVER'] = 'smtp.googlemail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME')
app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD')
app.config['FLASKY_MAIL_SUBJECT_PREFIX'] = '[Flasky]'
app.config['FLASKY_MAIL_SENDER'] = 'Flasky Admin <flasky@example.com>'
app.config['FLASKY_ADMIN'] = os.environ.get('FLASKY_ADMIN')

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
mail = Mail(app)


class Role(db.Model):
Example #6
0
import os 
from flask import Flask, render_template, request, redirect, url_for
from flask_mail import Mail, Message as MailMessage
import json 
import requests 

app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = ''
app.config['MAIL_PASSWORD'] = ''
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)

@app.route('/')
def get_malimo_home():

	workFilePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static/media/work_experience.json') 
	with open(workFilePath, 'r') as work_file:
		content = work_file.read()
		workData = json.loads(content)
		work_file.close()

	return render_template('index.html', work_data=workData) 



@app.route('/sendMessage', methods=['POST']) 
def messenger():
	inquirerName = request.form['name']
Example #7
0
        user = super(GitHugAuth, self).build_user(data)
        user.avatar_url = data['user']['avatar_url']
        user.email = data['user'].get('email', '').strip() or None
        return user


#
# Setup
#
import requests

app = Flask(__name__)
app.secret_key = os.environ['SECRET']
app.config['MAIL_SERVER'] = os.environ.get('MAIL_SERVER', 'localhost')
app.config['MAIL_PORT'] = int(os.environ.get('MAIL_PORT', 25))
app.config['MAIL_USE_TLS'] = bool(os.environ.get('MAIL_USE_TLS', False))
app.config['MAIL_USE_SSL'] = bool(os.environ.get('MAIL_USE_SSL', False))
app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME', None)
app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD', None)
app.config['DEFAULT_MAIL_SENDER'] = 'hugs@githugs.org'
app.local = os.environ.get('LOCAL', None) is not None
app.debug = bool(app.local)
heroku = Heroku(app)
if app.config.get('SENTRY_DSN'):
    sentry = Sentry(app)
db = connect(
    app.config['MONGODB_DB'],
    host=app.config['MONGODB_HOST'],
    port=app.config['MONGODB_PORT'],
    username=app.config['MONGODB_USER'],
    password=app.config['MONGODB_PASSWORD'])
Example #8
0
# services
SERVICE_POD = "pod"
SERVICE_TLP = "tlp"
SERVICES = [SERVICE_POD, SERVICE_TLP]

# models
MODELS_POD_OCR = "ocr"
MODELS_POD_BAYES_SPAM = "bayes_spam"
MODELS_POD_FACE_DETECT = "face_detect"
MODELS = [MODELS_POD_OCR, MODELS_POD_BAYES_SPAM, MODELS_POD_FACE_DETECT]


# mail settings
PRAXYK_API_APP.config['MAIL_SERVER']   = 'smtp.googlemail.com'
PRAXYK_API_APP.config['MAIL_PORT']     = 587
PRAXYK_API_APP.config['MAIL_USE_TLS']  = True
PRAXYK_API_APP.config['MAIL_USE_SSL']  = False
# gmail authentication
PRAXYK_API_APP.config['MAIL_USERNAME'] = apiconf['email']
PRAXYK_API_APP.config['MAIL_PASSWORD'] = apiconf['emailpassword']

mail = Mail(PRAXYK_API_APP)

# mail accounts
PRAXYK_API_APP.config['MAIL_DEFAULT_SENDER'] = 'from@example.com'

# default access token expiration time (24 hours)
TOKEN_EXPIRATION = apiconf['token_expiration']


from models.sql.user import User, Role, Transaction, Token, Payment_Info
Example #9
0
app = Flask(__name__)

manager = Manager(app)
mail = Mail(app)
login_manager.init_app(app)
bootstrap = Bootstrap(app)
app.config['SECRET_KEY'] = cfg.get("Secret", "wtf_secret_key")

# app.config['SERVER_NAME'] = "www.circl.lu:443"
# app.config['APPLICATION_ROOT'] = '/cve-portal'
# app.config['WTF_CSRF_ENABLED'] = True

# SMTP email config #
app.config['MAIL_SERVER'] = cfg.get('SMTP', 'server')
app.config['MAIL_PORT'] = cfg.get('SMTP', 'port')
app.config['MAIL_USE_TLS'] = cfg.get('SMTP', 'tls')
app.config['DEFAULT_MAIL_SENDER'] = cfg.get('SMTP', 'sender')

# Super Admin #
app.config['PORTAL_ADMIN'] = cfg.get('ADMIN', 'mail')

#  REDIS CONNECTION  #
r = redis.StrictRedis(host=cfg.get('REDIS', 'host'),
                      port=cfg.get('REDIS', 'port'),
                      db=cfg.get('REDIS', 'db'))

#  MONGO  #
app.config['MONGO_DBNAME'] = cfg.get('MONGO', 'dbname')
m = PyMongo(app)

# GPG #
Example #10
0
# encoding:utf-8
from flask import Flask,render_template,session,redirect,url_for,flash,request
from flask.ext.bootstrap import Bootstrap
from flask.ext.moment import Moment
from datetime import datetime
from flask.ext.wtf import Form
from wtforms import SubmitField,StringField
from wtforms.validators import required
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.mail import Mail
from flask.ext.mail import Message
from threading import Thread
import RealIP
import dbconfig

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
#初始化Flask 实例,添加秘钥,数据库参数配置,邮箱配置
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess string'
app.config['SQLALCHEMY_DATABASE_URI'] = dbconfig.SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = dbconfig.SQLALCHEMY_COMMIT_ON_TEARDOWN
app.config['MAIL_SERVER'] = 'smtp.139.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = '18898761417@139.com'
app.config['MAIL_PASSWORD'] = '***************'
app.config['FLASKY_MAIL_SUBJECT_PREFIX'] = '[Flasky]'
app.config['FLASKY_MAIL_SENDER'] = 'Flasky Admin <18898761417@139.com>'
Example #11
0
app = Flask(__name__)

app.secret_key = CryptoUtil.decrypt(config.ENCRYPTED_SESSION_KEY,ENCRYPTION_KEY)

app.config['STRIPE_TOKEN'] = CryptoUtil.decrypt(config.ENCRYPTED_STRIPE_TOKEN, ENCRYPTION_KEY)
app.config['DATABASE_PASSWORD'] = CryptoUtil.decrypt(config.ENCRYPTED_DATABASE_PASSWORD, ENCRYPTION_KEY)
app.config['STRIPE_CACHE_REFRESH_MINUTES'] = config.STRIPE_CACHE_REFRESH_MINUTES
app.config['STRIPE_CACHE_REBUILD_MINUTES'] = config.STRIPE_CACHE_REBUILD_MINUTES
app.config['STRIPE_CACHE_REFRESH_BACKREACH_MIN'] = config.STRIPE_CACHE_REFRESH_BACKREACH_MIN
app.config['ACCESS_CONTROL_HOSTNAME'] = config.ACCESS_CONTROL_HOSTNAME
app.config['ACCESS_CONTROL_SSH_PORT'] = config.ACCESS_CONTROL_SSH_PORT

app.config['MAIL_SERVER'] = config.MAIL_SERVER
app.config['MAIL_PORT'] = config.MAIL_PORT
app.config['MAIL_USE_TLS'] = config.MAIL_USE_TLS
app.config['MAIL_USE_SSL'] = config.MAIL_USE_SSL
app.config['MAIL_USERNAME'] = CryptoUtil.decrypt(config.ENCRYPTED_MAIL_USERNAME,ENCRYPTION_KEY)
app.config['MAIL_PASSWORD'] = CryptoUtil.decrypt(config.ENCRYPTED_MAIL_PASSWORD,ENCRYPTION_KEY)
app.config['ADMIN_PASSPHRASE'] = CryptoUtil.decrypt(config.ENCRYPTED_ADMIN_PASSPHRASE,ENCRYPTION_KEY)
app.config['LOG_FILE'] = config.LOG_FILE

# Logging
file_handler = logging.FileHandler(app.config['LOG_FILE'])
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s: %(message)s'))
file_handler.setLevel(logging.INFO)
app.logger.setLevel(logging.INFO)
app.logger.addHandler(file_handler)

app.logger.info("------------------------------")
app.logger.info("SYN Shop Identifyer Started...")
Example #12
0
app.config['MAIL_SERVER'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.host']
logging.debug("Configuring SMTP properties for %s", app.config['MAIL_SERVER'])

# Set the correct server port for encrypted vs unencrypted communications
if app.config['CLOUD_SESSION_PROPERTIES']['mail.port'] is None:
    if app.config['CLOUD_SESSION_PROPERTIES']['mail.tls']:
        app.config['MAIL_PORT'] = 587
    else:
        app.config['MAIL_PORT'] = 25

    logging.info("Email server default port set to port %s", app.config['MAIL_PORT'])
else:
    app.config['MAIL_PORT'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.port']

app.config['MAIL_USE_TLS'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.tls']
app.config['MAIL_USE_SSL'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.ssl']
app.config['MAIL_DEBUG'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.debug']
app.config['MAIL_USERNAME'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.user']
app.config['MAIL_PASSWORD'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.password']
app.config['DEFAULT_MAIL_SENDER'] = app.config['CLOUD_SESSION_PROPERTIES']['mail.from']


logging.info("Initializing mail")
logging.info("SMTP port: %s", app.config['MAIL_PORT'])
logging.info("TLS: %s", app.config['MAIL_USE_TLS'])
logging.info("SSL: %s", app.config['MAIL_USE_SSL'])
logging.info("Sender: %s", app.config['DEFAULT_MAIL_SENDER'])

mail = Mail(app)
Example #13
0
File: app.py Project: Fize/cvpn
migrate = Migrate(app, db)


def parser(field, key):
    a = Parser(os.path.join(basedir, 'config.ini'))
    return a.get(field, key)


#config
app.config['SECRET_KEY'] = parser('secret', 'key')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' + parser('cvpn', 'data_path')
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['MAIL_SERVER'] = parser('mail', 'smtp_server')
app.config['MAIL_PORT'] = int(parser('mail', 'smtp_port'))
app.config['MAIL_USE_TLS'] = parser('mail', 'mail_tls')
app.config['MAIL_USE_SSL'] = parser('mail', 'mail_ssl')
app.config['MAIL_USERNAME'] = parser('mail', 'mail_user')
app.config['MAIL_PASSWORD'] = parser('mail', 'mail_password')
app.config['FLASK_MAIL_SUBJECT_PREFIX'] = parser('mail', 'prefix')
app.config['FLASK_MAIL_SENDER'] = 'cvpn admin<%s>' % app.config['MAIL_USERNAME']


mail = Mail(app)


def send_email(to, subject, template, **kwargs):
    msg = Message(app.config['FLASK_MAIL_SUBJECT_PREFIX'] + subject,
                  sender=app.config['FLASK_MAIL_SENDER'], recipients=[to])
    msg.body = render_template(template + '.txt', **kwargs)
    msg.html = render_template(template + '.html', **kwargs)
Example #14
0
oid = OpenID(app, os.path.join(settings.BASE_DIR, 'tmp'))

# Configure database
app.config['SQLALCHEMY_DATABASE_URI'] = settings.DATABASE_URI
db = SQLAlchemy(app)
migrate = Migrate(app, db)

# Configure Flask-Script
manager = Manager(app)
manager.add_command('runserver', Server(host=settings.APP_HOST, port=settings.APP_PORT))
manager.add_command('db', MigrateCommand)

# Configure Flask-Mail
app.config['MAIL_SERVER'] = settings.MAIL_SERVER
app.config['MAIL_PORT'] = settings.MAIL_PORT
app.config['MAIL_USE_TLS'] = settings.MAIL_USE_TLS
app.config['MAIL_USERNAME'] = settings.MAIL_USERNAME
app.config['MAIL_PASSWORD'] = settings.MAIL_PASSWORD
mail = Mail(app)

# Configure Flask-Cache
app.config['CACHE_TYPE'] = settings.CACHE_BACKEND
cache = Cache(app)

# Configure Babel
babel = Babel(app)


# Configure Flask-Assets
assets = Environment(app)
app.config['ASSETS_DEBUG'] = settings.ASSETS_DEBUG
Example #15
0
#Security Features
app.config['SECURITY_REGISTERABLE'] = user_enable_registration
app.config['SECURITY_TRACKABLE'] = user_enable_tracking
app.config['SECURITY_EMAIL_SENDER'] = user_from_email
app.config['SECURITY_PASSWORD_HASH'] = pwhash
app.config['SECURITY_PASSWORD_SALT'] = salt
app.config['SECURITY_CONFIRMABLE'] = True
app.config['SECURITY_EMAIL_SUBJECT_REGISTER'] = user_register_email_subject

# Email
app.config['MAIL_SERVER'] = mail_url
app.config['DEBUG'] = False
app.config['MAIL_PORT'] = mail_port
app.config['MAIL_USE_SSL'] = mail_SSL
app.config['MAIL_USE_TLS'] = mail_TLS
app.config['MAIL_USERNAME'] = mail_user
app.config['MAIL_PASSWORD'] = mail_pass 
app.config['MAIL_SUPPRESS_SEND'] = False


# Create database connection object
db = MongoEngine(app)
#Bootstrap
Bootstrap(app)
#Setup Mail
mail = Mail(app)
mail.init_app(app)

    # mail test
with mail.record_messages() as outbox: