Пример #1
0
 def downgradedb(self):
     with app.app_context():
         downgrade(directory='migrations',
                   revision='-1',
                   sql=False,
                   tag=None)
         return "db downgraded"
Пример #2
0
def github_login():
    if not github.authorized:
        return redirect(url_for('github.login'))
    else:
        account_info = github.get('/user')
        if account_info.ok:
            account_info_json = account_info.json()
            print("account info json", account_info_json)
            with app.app_context():
                user = {
                    "username": "******",
                    "email": "*****@*****.**",
                    "login": account_info_json['login'],
                    "location": account_info_json['location'],
                    "roleid": ""
                }

                db = database.createUser(user)
                print("user in db is...", db)
                if db:
                    role = database.getRole(db['roleid'])
                    if role:
                        # token=generate_token.generateToken(account_info_json['name'],role['role'])
                        token = generate_token.generateToken(
                            db['username'], role['role'])
                        print("token is...", token)
                        session['bearerToken'] = token
                        session['username'] = account_info_json['login']
                        rendered = render_template('blog.html', \
                                                   session=session)
                        return rendered
            # return '<h1>Your Github name is {}'.format(account_info_json['login'])

    return '<h1>Request failed!</h1>'
Пример #3
0
def sendMail(feedbackResponse):
    if feedbackResponse and feedbackResponse.get('notification').get(
            'status') == 'Success':
        mail = Mail(app)
        with app.app_context():
            with mail.connect() as conn:
                feedback = feedbackResponse.get('data').get('comments')[0].get(
                    'feedback')
                customerName = feedbackResponse.get('data').get('customerName')
                temp = {
                    'feedbackId':
                    feedbackResponse.get('data').get('comments')[0].get(
                        'feedbackId'),
                    'feedback':
                    feedback,
                    'customerName':
                    customerName
                }
                token = safeTimed.dumps(temp)
                link = 'http://127.0.0.1:5000/ic/approve/' + token
                modifyLink = 'http://127.0.0.1:5000/ic/modify/' + token
                msg = Message(subject='Feedback Approval',
                              recipients=['*****@*****.**'],
                              sender='*****@*****.**')
                msg.html = render_template('test.html',
                                           feedback=feedback,
                                           token=token,
                                           link=link,
                                           modifyLink=modifyLink,
                                           customerName=customerName)
                conn.send(msg)
Пример #4
0
 def wrapper(*args, **kw):
     try:
         return func(*args, **kw)
     except Exception as e:
         i('sql alchemy ctx error??? %s' % e)
         with app.app_context():
             return func(*args, **kw)
Пример #5
0
def send_mail(recipients: list,
              title,
              content_txt: str = None,
              content_html=None):
    from config import app
    if app.config['SEND_MAIL']:
        print('DEBUG状态,邮件被禁止发送了 \r\n \t%s \r\n \t%s \r\n \t%s' %
              (recipients, title,
               content_txt if content_html is None else content_html))
        return
    from flask_mail import Message
    from config import mail

    msg = Message(title,
                  sender=('oneself - service', app.config['MAIL_USERNAME']),
                  recipients=recipients)
    msg.body = content_txt
    msg.html = content_html
    try:
        mail.send(msg)
    except Exception:
        try:
            with app.app_context():
                mail.send(msg)
        except Exception as e:
            import traceback
            i('邮件发送失败%s' % traceback.format_exc())
Пример #6
0
 def upgradedb(self):
     with app.app_context():
         upgrade(directory='migrations',
                 revision='head',
                 sql=False,
                 tag=None)
         return "db upgraded"
Пример #7
0
def registerUser():
    try:
        userDetails = request.get_json()
    except BadRequest as badRequest:
        badRequest.message
    else:
        from controllers.controllers import AuthenticationController
        response = AuthenticationController().registerUser(userDetails)
        if response:
            mail = Mail(app)
            with app.app_context():
                with mail.connect() as conn:
                    email = response.get('data').get('email')
                    temp = {
                        'id': response.get('data').get('id'),
                        'user': '******'
                    }
                    token = safeTimed.dumps(temp)
                    link = 'http://127.0.0.1:5000/ic/verifyemail/' + token
                    msg = Message(subject='verification link',
                                  recipients=[email],
                                  sender='*****@*****.**')
                    msg.html = '<a href=' + link + '> Click here to verify your email with Indian Cuisinier</a>'
                    conn.send(msg)

        return jsonify(response)
Пример #8
0
 def sendAsyncMail(self, subject, senders, receivers, body, details):
     with app.app_context():
         with self.mail.connect() as conn:
             msg = Message(subject=subject,
                           recipients=receivers,
                           sender=senders)
             msg.html = render_template(body, details=details)
             conn.send(msg)
Пример #9
0
 def migratedb(self):
     with app.app_context():
         _migrate(directory='migrations',
                  message=None,
                  sql=False,
                  head='head',
                  splice=False,
                  branch_label=None,
                  version_path=None,
                  rev_id=None)
         return "created an script"
Пример #10
0
 def send_mail_confirmation_to_user(cls, email, confirm_url):
     with app.app_context():
         msg = Message(subject="Xác thực tài khoản Tranh Việt",
                       sender=app.config.get("MAIL_USERNAME"),
                       recipients=[email])
         msg.html = render_template('email_confirmation.html',
                                    confirm_url=confirm_url)
         try:
             mail.send(msg)
         except:
             return False
Пример #11
0
 def revisiondb(self):
     with app.app_context():
         revision(directory='migrations',
                  message=None,
                  autogenerate=False,
                  sql=False,
                  head='head',
                  splice=False,
                  branch_label=None,
                  version_path=None,
                  rev_id=None)
         return "created empty script"
Пример #12
0
Файл: DB.py Проект: bjarkig/holo
def query(query, singlets=False, only=False, args=()):
        with app.app_context(): 
                db = get()
                cur = db.execute(query, args)
                db.commit()
                rv = cur.fetchall()
                cur.close()

                if singlets:
                        rv = [r[0] for r in rv]

                return (rv[0] if rv else None) if only else rv
Пример #13
0
 def sendAsyncMailWithToken(self,
                            subject,
                            sender,
                            receivers,
                            link,
                            message,
                            body=None):
     print link
     with app.app_context():
         with self.mail.connect() as conn:
             msg = Message(subject=subject,
                           recipients=[receivers],
                           sender=sender)
             msg.html = render_template(body, link=link, message=message)
             conn.send(msg)
Пример #14
0
 def custom_migratdb(self):
     with app.app_context():
         _migrate(directory='migrations',
                  message=None,
                  sql=False,
                  head='head',
                  splice=False,
                  branch_label=None,
                  version_path=None,
                  rev_id=None)
         upgrade(directory='migrations',
                 revision='head',
                 sql=True,
                 tag=None)
         return "db upgraded"
Пример #15
0
def sendAsyncEmail(message, subject, users):
    mail = Mail(app)
    with app.app_context():
        with mail.connect() as conn:
            for email in users:
                token = safeTimed.dumps(email)
                # link = url_for('unsubscribe', token=token, _external=True)
                link = 'http://127.0.0.1:5000/ic/admin/unsubscribe/' + token
                msg = Message(subject=subject,
                              recipients=[email],
                              body=message,
                              sender='*****@*****.**')
                #msg.html = '<a href='+ link +'> Unsubscribed</a>'
                msg.html = render_template('test.html')
                conn.send(msg)
    return 'message sent'
Пример #16
0
def flask_plain_email(recipient, subject, content, cc, bcc):
    with app.app_context():
        #Instantiate a new message
        msg = Message(recipients=[recipient, cc, bcc],
                      subject=subject,
                      body=content)
        try:
            res = mail.send(msg)
            response = {
                'status': 'success',
                'data': {
                    'message': 'Mail sent successfully'
                }
            }
            # return print(res)
            return make_response(jsonify(response), 201)
        except Exception:
            response = {
                'status': 'error',
                'data': {
                    'message': 'Error: Mail was not sent.'
                }
            }
            return make_response(jsonify(response), 500)
Пример #17
0
 def initializedb(self):
     with app.app_context():
         init(directory='migrations', multidb=False)
         return "db initialised"
Пример #18
0
def send_async_email(message):
	with app.app_context():
		mail.send(message)
 def setUp(self):
     self.app_context = app.app_context()
     self.app_context.push()
Пример #20
0
def async_send_mail(app, msg):
    with app.app_context():
        mail.send(msg)
Пример #21
0
                    f'{refresh_token_cookie}; SameSite=Lax; HttpOnly'
                }
        else:
            return jsonify(status='wrong_pass')


@app.route('/basicuserinfo', methods=['GET'])
@jwt_required
def get_basic_user_info():
    # Access the identity of the current user with get_jwt_identity
    current_user = get_jwt_identity()
    print(f"Current User is {current_user}")
    # Query the database for the user info
    user_object = db.session.query(User).get(current_user)
    user_list = user_object.to_list()
    return ({
        'fname': user_list[1],
        'lname': user_list[2],
    }), 200


if len(sys.argv) > 1:
    if sys.argv[1].lower() == 'migrate' or sys.argv[1].lower() == 'm':
        with app.app_context():
            db.create_all()
    elif sys.argv[1].lower == 'demigrate' or sys.argv[1].lower() == 'd':
        with app.app_context():
            db.drop_all()
else:
    app.run(debug=True)
Пример #22
0

from models import User, Role
from config import app, db
from flask_security.utils import encrypt_password
from flask_security import Security, SQLAlchemyUserDatastore, \
    UserMixin, RoleMixin, login_required, current_user


db.drop_all()
db.create_all()

user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore)

with app.app_context():
    user_role = Role(name='user')
    super_user_role = Role(name='superuser')
    db.session.add(user_role)
    db.session.add(super_user_role)
    db.session.commit()

    test_user = user_datastore.create_user(
        username='******',
        password=encrypt_password('admin'),
        active=True,
        roles=[user_role, super_user_role],
    )

    db.session.commit()
Пример #23
0
import os
from Models.Model_Roles import Roles
from Models.Model_Users import Users
from Models.Model_Views import Views
from Models.Model_Permissions import Permissions
from Models.Model_Reset_Password_Logs import Resetpasswordlogs
from Models.Model_Global_Settings import Globalsettings
from Models.Model_Login_History import Loginhistories

from flask_restful import Api
from config import db, app
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

migrate = Migrate(app, db)

app.app_context().push()

db.init_app(app)
db.create_all(app=app)
db.session.commit()

manager = Manager(app)
manager.add_command('db', MigrateCommand)

if __name__ == "__main__":
    manager.run()
 def setUp(self):
     self.app_context = app.app_context()
     self.app_context.push()