Exemple #1
0
    def __init__(self):
        super(MyApp, self).__init__()
        self.setupUi(self)
        self.tableWidget.setColumnWidth(0, 200)
        self.tableWidget.setColumnWidth(1, 200)
        self.tableWidget.setColumnWidth(2, 199)
        self.tableWidget.setColumnWidth(3, 180)
        self.tableWidget.verticalHeader().setVisible(False)
        self.tableWidget.horizontalHeader().setResizeMode(
            1, QtGui.QHeaderView.Stretch)
        self.tableWidget.setSelectionBehavior(
            QtGui.QAbstractItemView.SelectRows)
        self.tableWidget.setSelectionMode(
            QtGui.QAbstractItemView.SingleSelection)
        self.tableWidget.cellDoubleClicked.connect(self.showSensorInfo)

        self.refreshData()

        self.auth = Auth()
        self.auth.show()

        self.refreshTimer = QtCore.QTimer()
        self.refreshTimer.timeout.connect(self.refreshData)
        self.refreshTimer.start(5000)

        self.auth.authSuccessfull.connect(self.authenticationFinished)
        self.auth.authAdminSuccessfull.connect(
            self.authenticationAdminFinished)
Exemple #2
0
def create_app():
    """
    Flask Application Factory that takes configuration settings and returns
    a Flask application.
    """
    # initalize instance of Flask application
    app = Flask(__name__)

    app.config.from_object(Config)

    mongo.init_app(app)

    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers[
                'Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
        return response

    from app.auth import Auth
    auth = Auth()
    jwt = JWT(app, auth.authenticate, auth.identity)

    @jwt.auth_response_handler
    def response_handler(access_token, identity):
        data = {
            "result": "y",
            "msg": "",
            "data": {
                "token": access_token.decode('utf-8'),
                "is_admin": identity.is_admin,
                "userid": identity.id,
                "username": identity.username,
                "avatar": identity.avatar
            }
        }
        return jsonify(data)

    app.config['UPLOADED_AVATAR_DEST'] = os.path.dirname(
        os.path.abspath(__file__)) + "/_upload/avatars/"
    app.config['UPLOADED_TMPFILE_DEST'] = os.path.dirname(
        os.path.abspath(__file__)) + "/_upload/temps/"
    app.config['UPLOADED_AVATAR_ALLOW'] = IMAGES
    configure_uploads(app, avatars)
    configure_uploads(app, tmpfiles)

    from .api import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/_api')
    # register 'main' blueprint with Flask application
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)
    # register 'auth' blueprint with Flask application
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/auth')

    return app
Exemple #3
0
def logout():
    auth = Auth()
    token = request.headers.get("token")
    token = auth.logout(token=token)
    result = json.dumps({"token": token, "message": "logout"})
    resp = flask.Response(result)
    resp.headers['Access-Control-Allow-Origin'] = '*'
    return resp
Exemple #4
0
def login():
    content = request.json
    auth = Auth()
    result = auth.autenticate(email=content["email"],
                              password=content["password"])
    if result is None:
        result = json.dumps({"message": "email ou password invalid"})
    resp = flask.Response(result)
    resp.headers['Access-Control-Allow-Origin'] = '*'
    return resp, 200
Exemple #5
0
 def __init__(self,
              streamer_uid,
              n_followers=100,
              n_followings=100,
              num_suggestions=10):
     if streamer_uid and isinstance(streamer_uid, str):
         self.auth = Auth()
         self.bear_token = self.auth.bear_token
         self.sess = requests.Session()
         self.streamer = self.Streamer(streamer_uid, 'to_id')
         self.followers_list = None
         self.followings_count = None
         self.n_followings = n_followings
         self.n_followers = n_followers if n_followers else self.get_total_follows_count(
             streamer_uid)
         self.num_suggestions = num_suggestions
     else:
         raise ValueError(
             'Supplied streamer_uid was invalid.  Supplied value must be a string.'
         )
 def __init__(self,
              streamer_uid,
              n_followers=100,
              n_followings=50,
              num_suggestions=10):
     if streamer_uid and isinstance(streamer_uid, str):
         self.auth = Auth()
         self.bear_token = self.auth.bear_token
         self.sess = requests.Session()
         self.streamer = self.Streamer(streamer_uid, 'to_id')
         self.followers_list = None
         self.followings_count = None
         self.n_followings = n_followings
         self.n_followers = n_followers if n_followers else self.get_total_follows_count(
             streamer_uid)
         self.num_suggestions = num_suggestions
         self.num_skipped = 0
     else:
         raise ValueError(
             'Streamer id supplied to TwitchClient() was invalid; probably not found on Twitch'
         )
def get_userinfo(given_name: str, bear_token=None) -> dict:
    """ Fetches userinfo (e.g., a uid ) for a given username.
    :return: A dictionary containing information about the given username or None if given name was not found.
    """
    if not bear_token:
        bear_token = Auth().bear_token

    base_url = 'https://api.twitch.tv/helix/users'
    result = None
    with requests.get(base_url,
                      params={'login': given_name.lower()},
                      headers=bear_token) as req:
        if req.ok and req.json()['data']:
            resp = req.json()['data'][0]
            result = {
                'name': resp['display_name'],
                'uid': resp['id'],
                'profile_img_url': resp['profile_image_url'],
                'broadcaster_type': resp['broadcaster_type']
            }
        else:
            raise ValueError('Supplied User name was not found on Twitch.')
    return result
Exemple #8
0
 def setUp(self):
     auth_args = {
         'client_id': settings.TWITCH_CLIENT_ID,
         'client_secret': settings.TWITCH_CLIENT_SECRET
     }
     self.test_auth = Auth(**auth_args)
Exemple #9
0
import logging
from app import settings
import requests
from app.auth import Auth
from abc import ABC

module_logger = logging.getLogger(__name__ + '.py')
auth_args = {
    'client_id': settings.TWITCH_CLIENT_ID,
    'client_secret': settings.TWITCH_CLIENT_SECRET
}
auth_token = Auth(**auth_args)


def validate_name(given_name: str) -> dict:
    """
    This function validates a given_name using Twitch's API and returns a dictionary.  No authorization token is
    required for this request (only a valid client_id, read from `settings.py`)
    
    :param str given_name: a streamer's name to be validated
    :return: a dictionary containing key-value pairs as: 'profile_img_url', 'display_name', 'login_name', 'twitch_uid',
    'broadcaster_type', and 'valid' (boolean value)
    :rtype: dict
    """
    if given_name is None:
        err_msg = "'given_name' supplied to validate_name() was 'None' type."
        module_logger.info("err_msg")
        raise ValueError(err_msg)

    if given_name == "":
        err_msg = "'given_name' supplied to validate_name() was empty: ('{}')".format(
Exemple #10
0
 def setUp(self):
     self.auth = Auth()
Exemple #11
0
 def setUp(self):
     self.test_auth = Auth()