Beispiel #1
0
def init_security(app):
    global user_datastore
    user_datastore = SQLAlchemySessionUserDatastore(loadSession(), models.UserAccount, models.UserRole)
    global security
    security = Security(app, user_datastore)
    user_datastore.remove_role_from_user(user='******', role='user')
    user_datastore.commit()

    log.info('Init security')
Beispiel #2
0
def timed_job():
    payload = {
        'module': 'account',
        'action': 'txlist',
        'address': cf.ACCOUNT_ADDRESS,
        'startblock': startblock,
        'sort': 'asc',
        'apikey': cf.ETHERSCAN_API_KEY
    }
    r = requests.get('http://ropsten.etherscan.io/api', params=payload)
    lastBlock = 0
    json_data = json.loads(r.text)
    try:
        session = loadSession()
        for result in json_data['result']:
            block_number = result['blockNumber']
            timestamp = result['timeStamp']
            tx_hash = result['hash']
            block_hash = result['blockHash']
            org = result['from']
            cert = json.loads(
                codecs.decode(result['input'][2:], "hex").decode('utf-8'))
            certificate = models.Certificate(
                block_number=block_number,
                tx_timestamp=datetime.fromtimestamp(int(timestamp)),
                block_hash=block_hash,
                tx_hash=tx_hash,
                organisation_ethereum_wallet=org,
                personal_document_type_code=cert[
                    'personal_document_type_code'],
                personal_document_id=cert['personal_document_id'],
                certificate_type_code=cert['certificate_type_code'],
                certificate_id=cert['certificate_id'],
                course_name=cert['course_name'],
                certificate_date=dateutil.parser.parse(
                    cert['certificate_date']),
                course_length=int(cert['course_length']),
                average_grade=int(cert['average_grade']),
                course_start_date=dateutil.parser.parse(
                    cert['course_start_date']),
                course_end_date=dateutil.parser.parse(cert['course_end_date']))
            if (session.query(models.Certificate.tx_hash).filter_by(
                    tx_hash=certificate.tx_hash).scalar() is None):
                session.add(certificate)
                session.flush()
                session.commit()
    except AttributeError:
        print("Unexpected error:", sys.exc_info()[0])
        return  #expected behavior, some jsons will be rubbish

    except Exception:
        raise
Beispiel #3
0
def user_dashboard():
    session = loadSession()
    if (not current_user.is_authenticated):
        abort(500)

    user_id = current_user.id
    documents = session.query(models.NationalDocument).filter_by(user_id=user_id).all()
    certificates = []
    for doc in documents:
        certificates.extend(session.query(models.Certificate).filter_by(personal_document_id=doc.document_number,
                                                                        personal_document_type_code=doc.document_type_code).all())
    for cert in certificates:
        cert.org_name = session.query(models.Organisation).filter_by(
            ethereum_wallet=cert.organisation_ethereum_wallet).first().name

    return render_template("user_dashboard.html", certificates=certificates)
Beispiel #4
0
from flask import Flask, render_template, request, redirect, abort, flash, session, url_for
from flask_script import Manager
import settings
from database import loadSession, Gateways, Address, InboundMapping, OutboundRoutes, dSIPFusionPBXDB
import os
import subprocess
import json

app = Flask(__name__, static_folder="./static", static_url_path="/static")
app.debug = settings.DEBUG
#app.add_template_filter()
db = loadSession()


@app.route('/')
def index():
    if not session.get('logged_in'):
        return render_template('index.html', version=settings.VERSION)
    else:
        action = request.args.get('action')
        return render_template('dashboard.html',
                               show_add_onload=action,
                               version=settings.VERSION)


@app.route('/login', methods=['POST'])
def login():
    if request.form['password'] == settings.PASSWORD and request.form[
            'username'] == settings.USERNAME:
        session['logged_in'] = True
        session['username'] = request.form['username']
Beispiel #5
0
        if not ':' in itemNumber:
            itemNumber = itemNumber + ':1'
        itemNumber = "itemNumber=\"%s\"" % itemNumber
        query = {
            u'x-api': u'test',
            u'method': u'search',
            u'recordSchema': u'xml',
            u'fields': u'itemId',
            u'query': itemNumber.encode('utf-8')
        }
        try:
            url = urllib2.urlopen(u'http://kulturarvsdata.se/ksamsok/api?%s' %
                                  urllib.urlencode(query))
            xml = etree.parse(url)
            root = xml.getroot()
            identifier = root.findall('.//field')[0]
            url.close()
        except:
            1
    return getattr(identifier, 'text', None)


if __name__ == "__main__":
    session = database.loadSession()
    from optparse import OptionParser
    oparser = OptionParser()
    oparser.add_option('-d', '--debug', action='store_true', default=False)
    opts, args = oparser.parse_args()
    app.debug = opts.debug
    app.run(host='0.0.0.0')
Beispiel #6
0
# import flask.scaffold
# flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
from flask_restful import Api, Resource, reqparse, abort
from tables import *
from database import loadSession
import sqlalchemy
from queries import *
from pprint import pprint
from sqlalchemy import func

db_session = loadSession()


class AlcoholicAPI(Resource):
    parser = reqparse.RequestParser()
    parser.add_argument("id_alc",
                        type=int,
                        help="Id of the alcoholic is required")
    parser.add_argument("fname", type=str, help="First name")
    parser.add_argument("lname", type=str, help="Last name")

    def get(self, id_alc):
        args = self.parser.parse_args()
        if args['fname'] and args['lname']:
            q_res = db_session.query(Alcoholic).filter(
                Alcoholic.fname == args['fname']
                and Alcoholic.lname == args['lname']).all()
        else:
            q_res = db_session.query(Alcoholic).filter(
                Alcoholic.id_alc == id_alc).all()
        if q_res:
Beispiel #7
0
def loadSession(id):
    data = db.loadSession(id)
    user = User(id)
    user.importSession(data)
    return user
Beispiel #8
0
    if itemNumber:
        if not ':' in itemNumber:
            itemNumber = itemNumber + ':1'
        itemNumber = "itemNumber=\"%s\"" % itemNumber
        query = {
            u'x-api': u'test',
            u'method': u'search',
            u'recordSchema': u'xml',
            u'fields': u'itemId',
            u'query': itemNumber.encode('utf-8')
        }
        try:
            url = urllib2.urlopen(u'http://kulturarvsdata.se/ksamsok/api?%s' % urllib.urlencode(query))
            xml = etree.parse(url)
            root = xml.getroot()
            identifier = root.findall('.//field')[0]
            url.close()
        except:
            1
    return getattr(identifier, 'text', None)


if __name__ == "__main__":
    session = database.loadSession()
    from optparse import OptionParser
    oparser = OptionParser()
    oparser.add_option('-d', '--debug', action='store_true', default=False)
    opts, args = oparser.parse_args()
    app.debug = opts.debug
    app.run(host='0.0.0.0')