Exemple #1
0
def before_request():
    """ Establish the connection to PostgreSQL before request. """
    postgres = db.connect_to_db(os.getenv("POSTGRES_DB"),
                                os.getenv("POSTGRES_USER"), "db",
                                os.getenv("POSTGRES_PASSWORD"))
    g.db = postgres
Exemple #2
0
                        help='remove selected user by username',
                        action='store_true')
    parser.add_argument('-e',
                        '--edit',
                        help='update selected user by username',
                        action='store_true')
    parser.add_argument('-u', '--username', help='user username')
    parser.add_argument('-p', '--password', help='user password')
    parser.add_argument('-n', '--new-password', help='user new password')
    parser.add_argument('-m', '--email', help='user email')
    parser.add_argument('-to', '--to', help="recipient email")
    parser.add_argument('-s', '--send', help='send email')

    args = parser.parse_args()

    connection = connect_to_db()
    if connection is None:
        print('Cannot connect to database')
        exit(-1)

    cursor = connection.cursor()

    if args.authorize == True:
        is_user_logged = UserService.login(cursor, args.username,
                                           args.password)
        if is_user_logged == True:
            print('Authorization done')
        else:
            print('Username or password invalid')

    if args.add_user == True:
Exemple #3
0
# coding=utf-8
from flask import Flask, jsonify
from utils.db import connect_to_db

app = Flask(__name__)

# Configurations
app.config.from_object('config')
# Database connection
connect_to_db(app)


@app.errorhandler(404)
def not_found(error):
    # return "Error Message: {0}".format(error)
    response = {
        'success': False,
        'message': "Error Message: {0}".format(error)
    }

    return jsonify(response), 404


# Routes Register

# register post routers
from .posts import post_routes
app.register_blueprint(post_routes)