Esempio n. 1
0
def launch():
    FlaskApp().app.logger.info('adding resource...')
    FlaskApp().api.add_resource(EPToken, '/token')
    FlaskApp().api.add_resource(Home, "/")
    FlaskApp().debug_mode()
    try:
        port = int(os.environ.get('SERVER_PORT', PORT_))
    except ValueError:
        port = PORT_
    FlaskApp().start(port)
Esempio n. 2
0
 def enroll_on_subject(self, subject_id):
     edition = self.get_current_edition(subject_id)
     if edition is not None:
         try:
             TSubjectEdition2Student.save(edition, g.user['id'])
         except Exception as e:
             FlaskApp().app.logger.error('Cannot enroll user on subject edition %s: %s', edition, e)
             raise e
Esempio n. 3
0
 def verify_auth_token(token):
     s = Serializer(FlaskApp().app.config['SECRET_KEY'])
     try:
         data = s.loads(token)
     except SignatureExpired:
         return None
     except BadSignature:
         return None
     return g.session.query(TUser).get(data['id'])
Esempio n. 4
0
def lazy_reflection():
    if not getattr(lazy_reflection, 'reflected', False):
        try:
            DeferredReflection.prepare(engine)
            setattr(lazy_reflection, 'reflected', True)
        except OperationalError as ex:
            FlaskApp().app.logger.error(
                'Cannot connect with database {}'.format(ex.args))
            return False
    return True
Esempio n. 5
0
def verify_password(token, password):
    s = Serializer(FlaskApp().app.config['SECRET_KEY'])
    try:
        data = s.loads(token)
        g.user = data
    except SignatureExpired:
        return False
    except BadSignature:
        return False
    return True
Esempio n. 6
0
 def get_current_edition(self, subject_id):
     try:
         return TSubjectEdition.get_current_edition(subject_id)
     except AttributeError as e:
         FlaskApp().app.logger.error('No current edition of subject %s: %s', subject_id, e)
     return -1 
Esempio n. 7
0
 def generate_auth_token(self, expiration=3600 * 30):
     s = TimedJSONWebSignatureSerializer(
         FlaskApp().app.config['SECRET_KEY'], expires_in=expiration)
     return s.dumps({'id': self.uzytkownik_id,
                     'login': self.login})\
         .decode('utf-8')
Esempio n. 8
0
#!/usr/bin/env python
from flask import jsonify, g
from common.app import FlaskApp

__app__ = FlaskApp().app


@__app__.errorhandler(404)
def page_not_found(error):
    __app__.logger.warn('Page not found')
    return jsonify({'error': 'Sorry. Page Not Found'}), 404


@__app__.teardown_request
def teardown_request(exception=None):
    if hasattr(g, 'session'):
        if g.session is not None:
            g.session.close()
            delattr(g, 'session')