def device_info (apikey, deviceID): global api_loggers global mydb if not(apikey in api_loggers): try: query = "select username from users where api_key = '{}'".format(apikey) mydb.cursor.execute(query) username = mydb.cursor.fetchall() username = username[0][0] apiuser = person.user(username, "dummy") apiuser.authenticated = True data = apiuser.dev_info(deviceID) api_loggers[apikey] = {"object" : apiuser} #this part is hard coded so remove after fixing the issue data = list(data) data[2] = "Rosegarden" return jsonify(data) except Exception as e: print (e) return jsonify({"data":"Oops Looks like api is not correct"}) else: data = api_loggers[apikey]["object"].dev_info(deviceID) #this part is hard coded so remove after fixing the issue data = list(data) data[2] = "Rosegarden" return jsonify (data)
def login(): error = "" if request.method == 'POST': user = person.user(request.form['username'], request.form['password']) if user.authenticated: user.session_id = str(binascii.b2a_hex(os.urandom(15))) logged_in[user.username] = {"object": user} return redirect('/overview/{}/{}'.format(request.form['username'], user.session_id)) else: error = "invalid Username or Passowrd" return render_template('Login.htm', error=error)
def listdevices(apikey): global api_loggers global mydb if not(apikey in api_loggers): try: query = "select username from users where api_key = '{}'".format(apikey) mydb.cursor.execute(query) username = mydb.cursor.fetchall() username = username[0][0] apiuser = person.user(username, "dummy") apiuser.authenticated = True devices_list = apiuser.get_devices() api_loggers[apikey] = {"object" : apiuser} return jsonify(devices_list) except Exception as e: print (e) return jsonify({"data":"Oops Looks like api is not correct"}) else: data = api_loggers[apikey]["object"].get_devices() return jsonify (data)