Beispiel #1
0
        def attempt_login(usrname=None, psswd_stored=None):
            self.root.title("WINstagramDM - Logging in")

            if usrname and psswd_stored:
                self.usr = api.User(usrname, psswd_stored)
            else:
                self.usr_name = usr_login.get()
                password = psswd.get()
                self.usr = api.User(usr_login.get(), psswd.get())
                #disable editing while logging in
                usr_login.config(state="disabled")
                psswd.config(state="disabled")
                login.config(state="disabled")

            if self.usr.api.login():
                try:
                    self.password = psswd.get()
                except NameError:
                    pass  #Autologin attempted

                self.usr.api.searchUsername(self.usr_name)
                self.usr_pk = self.usr.api.LastJson["user"]["pk"]
                self.root.quit()
                self.logged_in = True
                return True

            else:

                if json.loads(json.dumps(self.usr.api.LastJson)
                              )["message"] == "challenge_required":
                    webbrowser.open(json.loads(
                        json.dumps(self.usr.api.LastJson))["challenge"]["url"],
                                    new=2)
                    if self.usr.api.login():
                        self.usr.api.searchUsername(self.usr_name)
                        self.usr_pk = self.usr.api.LastJson["user"]["pk"]
                        self.root.quit()
                        self.logged_in = True
                        return 0

                usr_login.config(state="normal")
                psswd.config(state="normal")
                login.config(state="normal")
                psswd.delete(0, "end")
                psswd.config(show="")
                psswd.insert(0, "Password")

                try:
                    del self.psswd_cleared
                except AttributeError:
                    pass

                self.root.title("WINstagramDM - Login")
                #Resetup login thread to allow rerun
                self.login_thread = threading.Thread(target=attempt_login)
                self.login_thread.daemon = True
Beispiel #2
0
 def setUp(self):
     self.db = pymongo.MongoClient("localhost", 27017, safe=True).feedtester
     self.user = api.User()
     self.feed = api.Feed()
     self.log = logging.getLogger('apitest')
     self.testfeedurl = 'http://feeds.harvardbusiness.org/harvardbusiness/bregman/'
     self.prxydict = {'http_proxy': 'http://www-proxy.au.oracle.com:80'}
Beispiel #3
0
def before_request():
    g.userManagement = api.UserManagement()
    userEmail = session.get('email', None)
    userLoggedIn = session.get('loggedIn', False)
    if userLoggedIn:
        g.user = api.User(userEmail)
    else:
        g.user = None
def main():
    '''

    '''
    import ai as ai
    import read_sensor as read
    if config["mock"]:
        import mock_GPIO as GPIO  # Warning: NOT FULL COVERAGE
        import mock_pressure as pressure
        import mock_temp as tempature
        import ai as ai
    else:
        try:
            import RPi.GPIO as GPIO
        except ImportError:
            pass  # Not ideal but saves issues with building on none pi devices
        import pressure_sensor as pressure
        import temp_humidity_sensor as tempature

    user_info = api.User("John Doe")  #TODO log user create to debug
    temp_sensor_info = api.Sensor(
        "Temperature")  #TODO log user create to debug
    humidity_sensor_info = api.Sensor("Humidity")
    pressure_sensor_info = api.Sensor("Pressure")
    read_sensor_info = api.Sensor("Read")
    web_api = api.WebAPI(user_info,
                         base_url=config["base_url"],
                         offline=config["offline"])
    temp_humidity = tempature.TempAndHumiditySensor(
        temp_api_info=temp_sensor_info, hum_api_info=humidity_sensor_info)
    pressure_sensor = pressure.PressureSensor(pressure_sensor_info)
    read_sensor = read.ReadSensor(11, read_sensor_info)
    api_queue = queue.Queue()
    aiInterpretor = ai.aiModule()
    aiInterpretor.trainSensor()
    pressure_sensor_thread(pressure_sensor_thread, 6, config, pressure_sensor,
                           api_queue, aiInterpretor)
    tempature_humdity_sensor_thread(tempature_humdity_sensor_thread, 6, config,
                                    temp_humidity, api_queue)
    read_sensor_thread(read_sensor_thread, 6, config, read_sensor, api_queue)
    #  start threading, apply queue
    try:
        while True:
            if api_queue.full():
                logging.warn("Queue is full!")
            #Stalls until value exists
            q = api_queue.get()
            web_api.send_data(q["sensor_info"], api.timestamp_data(q["value"]))
    except KeyboardInterrupt:
        config["stop"] = True
        pass  #Leave system as expected
    finally:
        GPIO.cleanup()
Beispiel #5
0
def get_tenent(useraccount):
    tenant = g.db.query(Tenant).filter(Tenant.used == False).first()
    tenant.used = True
    token = auth()
    useraccount.tenant_password = "".join(utils.read_random(10))
    useraccount.tenant_password = useraccount.tenant_password.lower()
    name = useraccount.user.login_name.replace("@", "").replace(".", "")
    ua = api.User(token, None)
    user_id = ua.create(name,
                        useraccount.tenant_password,
                        useraccount.user.login_name,
                        enabled=True)
    role = api.Role(token).get_role_id("projectmanager")
    rep = api.Tenant(token, tenant_id=tenant.id).append_user(user_id, role)
    g.db.flush()
    g.db.commit()
    return dict(id=tenant.id, name=tenant.name, user_id=tenant.admin_user_id)
Beispiel #6
0
    def setUp(self):
        prxyval = Helper.getconfigvalue('dev.cfg', 'http_proxy', None)

        if prxyval is not None:
            self.prxydict = {'http_proxy': prxyval}
        else:
            self.prxydict = None

        dburl = Helper.getconfigvalue('dev.cfg', 'DATABASE_URI', None)
        dbname = Helper.getconfigvalue('dev.cfg', 'DBNAME', None)

        self.db = pymongo.MongoClient(dburl)[dbname]
        self.feed = Feed()
        self.log = logging.getLogger('scheduleit')
        self.user = api.User()
        self.feed = api.Feed()
        self.log = logging.getLogger('apitest')
        self.testfeedurl = 'http://feeds.harvardbusiness.org/harvardbusiness/bregman/'
Beispiel #7
0
import tornado.ioloop
import tornado.web
import json
import asyncio

import api
import os
os.chdir("Server")
port = os.getenv("PORT",8888)


us = api.User("MikeVernik")

class BaseHandler(tornado.web.RequestHandler):
    def get(self, *args, **kwargs):
        self.write("say something")

    def set_default_headers(self, *args, **kwargs):
        self.set_header("Access-Control-Allow-Origin", "*")
        self.set_header("Access-Control-Allow-Headers", "*")
        self.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")

class MainHandler(BaseHandler):
    def get(self):
        self.write("Hello, world")
        print(self.request.body)
        print(self.request)


class DialogueChanged(BaseHandler):
    def get(self):