def api_login(): logging.info("api_login Type "+ request.method) if request.method == 'POST': name = request.args.get("name","") email = request.args.get("email","") logging.info("name " + name +" email " + email) # once store token verified send a request for credential for gplus access_token = request.args.get("storeToken","") gplus_id = request.args.get("id","") logging.info(access_token) url = ("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s"% access_token) h = httplib2.Http() result = json.loads(h.request(url,'GET')[1]) query = Account.query(Account.email == email) account = query.get() if query.count() != 0: logging.info("Account Already Exists") key = account.key return json_success({"uuid":key.integer_id() }) logging.info("first time logging in") session['gplus_id'] = gplus_id session['username'] = name account = Account(name=name,email=email,gplusId=gplus_id,accessToken=access_token,loggedIn=True) key = account.put() session['userId'] = key.integer_id() return json_success({"uuid":key.integer_id()}) if request.method == 'GET': return page_not_found(404)
def newTak(): name = getValue(request, "name", None) uid = getValue(request, "userid", None) lat = getValue(request, "lat", None) lng = getValue(request, "lng", None) if not ( name and lat and lng and uid): return json_response(code=400) mapid = getValue(request, "mapid", None) map = None if uid is not None: user = Account.get_by_id(int(uid)) if user is None: return json_response(code=400) if mapid is not None: map = Map.get_by_id(int(mapid)) if map is None: map = Map(creator=user.name,creatorId=int(uid),name='Untitled',adminIds=[int(uid)]) key = map.put() mapid = key.id() account = Account.get_by_id(int(uid)) account.adminMaps.append(int(mapid)) account.put() tak = Tak(lng=lng,lat=lat, creator=user.name, name=name,mapId=int(mapid),creatorId=int(uid)) key = tak.put() map.takIds.append(key.integer_id()) map.put(); return json_success(tak.Get())
def newTak(): name = getValue(request, "name", None) uid = getValue(request, "userid", None) lat = getValue(request, "lat", None) lng = getValue(request, "lng", None) if not (name and lat and lng and uid): return json_response(code=400) mapid = getValue(request, "mapid", None) map = None if uid is not None: user = Account.get_by_id(int(uid)) if user is None: return json_response(code=400) if mapid is not None: map = Map.get_by_id(int(mapid)) if map is None: map = Map(creator=user.name, creatorId=int(uid), name='Untitled', adminIds=[int(uid)]) key = map.put() mapid = key.id() account = Account.get_by_id(int(uid)) account.adminMaps.append(int(mapid)) account.put() tak = Tak(lng=lng, lat=lat, creator=user.name, name=name, mapId=int(mapid), creatorId=int(uid)) key = tak.put() map.takIds.append(key.integer_id()) map.put() return json_success(tak.Get())
def api_login(): logging.info("api_login Type " + request.method) if request.method == 'POST': name = request.args.get("name", "") email = request.args.get("email", "") # once store token verified send a request for credential for gplus access_token = request.args.get("oauth", "") gplus_id = request.args.get("gplusid", "") #check for valid arguments if name == "" or email == "" or access_token == "" or gplus_id == "": return json_response(code=400) url = ("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s" % access_token) h = httplib2.Http() result = json.loads(h.request(url, 'GET')[1]) query = Account.query(Account.email == email) account = query.get() if query.count() != 0: key = account.key return json_success({"uuid": key.integer_id()}) session['gplus_id'] = gplus_id session['username'] = name account = Account(name=name, email=email, gplusId=gplus_id, accessToken=access_token, loggedIn=True) key = account.put() session['userId'] = key.integer_id() return json_success({"uuid": key.integer_id()})
def api_login(): logging.info("api_login Type "+ request.method) if request.method == 'POST': name = request.args.get("name","") email = request.args.get("email","") # once store token verified send a request for credential for gplus access_token = request.args.get("oauth","") gplus_id = request.args.get("gplusid","") #check for valid arguments if name == "" or email == "" or access_token == "" or gplus_id == "": return json_response(code=400) url = ("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s"% access_token) h = httplib2.Http() result = json.loads(h.request(url,'GET')[1]) query = Account.query(Account.email == email) account = query.get() if query.count() != 0: key = account.key return json_success({"uuid":key.integer_id() }) session['gplus_id'] = gplus_id session['username'] = name account = Account(name=name,email=email,gplusId=gplus_id,accessToken=access_token,loggedIn=True) key = account.put() session['userId'] = key.integer_id() return json_success({"uuid":key.integer_id()})
def login(): if request.method == 'POST': name = request.args.get("name","") email = request.args.get("email","") logging.info("name " + name +" email " + email) account = Account.query(Account.email == email).get() #create a state string state = '' for x in xrange(32): state+= random.choice(string.ascii_uppercase + string.digits) session['state'] = state storeToken = request.args.get("storeToken","") #verify store token with google servers try: oauth_flow = flow_from_clientsecrets('client_secrets.json', scope='') oauth_flow.redirect_uri = 'postmessage' credentials = oauth_flow.step2_exchange(storeToken) except FlowExchangeError: logging.info("error with Oauth") return page_not_found(404) # once store token verified send a request for credential for gplus access_token = credentials.access_token logging.info(access_token) url = ("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s"% access_token) h = httplib2.Http() result = json.loads(h.request(url,'GET')[1]) gplus_id = credentials.id_token['sub'] stored_credentials = session.get('credentials') stored_gplus_id = session.get('gplus_id') if account is not None: logging.info("User already logged in") account = Account.query(Account.email == email).get() account.loggedIn = True account.put() session['credentials'] = credentials session['gplus_id'] = gplus_id session['username'] = account.name session['userId'] = account.key.integer_id() session['loggedIn'] = True else: logging.info("first time logging in") session['credentials'] = credentials session['gplus_id'] = gplus_id session['username'] = name account = Account(name=name,email=email,gplusId=gplus_id,accessToken = access_token,loggedIn=True) key = account.put() session['userId'] = key.integer_id() session['loggedIn'] = True return '200' if request.method == 'GET': return page_not_found(404)
def favorite_mapsForUser(userid=-1): if userid <= 0: return json_response(code=400) user = Account.get_by_id(userid) if user is None: return json_response(code=400) if request.method == 'GET': # done # GET: returns json array of information about user's map objects return json_success(user.getFavorites()) mapid = getValue(request, "mapid", "") if not mapid: return json_response(code=400) map = Map.get_by_id(int(mapid)) if map is None: return json_response(code=400) if request.method == 'POST': if not map.key.integer_id() in user.favoriteMaps: user.favoriteMaps.append(map.key.integer_id()) user.put() return json_response(code=200) if request.method == 'DELETE': if map.key.integer_id() in user.favoriteMaps: user.favoriteMaps.remove(map.key.integer_id()) user.put() return json_response(code=200)
def favorite_mapsForUser(userid = -1): if userid <= 0: return json_response(code=400) user = Account.get_by_id(userid) if user is None: return json_response(code=400) if request.method == 'GET': # done # GET: returns json array of information about user's map objects return json_success(user.getFavorites()) mapid = getValue(request, "mapid", "") if not mapid: return json_response(code=400) map = Map.get_by_id(int(mapid)) if map is None: return json_response(code=400) if request.method == 'POST': if not map.key.integer_id() in user.favoriteMaps: user.favoriteMaps.append(map.key.integer_id()) user.put() return json_response(code=200) if request.method == 'DELETE': if map.key.integer_id() in user.favoriteMaps: user.favoriteMaps.remove(map.key.integer_id()) user.put() return json_response(code=200)
def newMap(userid='', name='', public=''): if not (name and public and userid): return json_response(code=400) user = Account.get_by_id(int(userid)) if user is None: return json_response(code=400) if public == 'true': public = True else: # default false if not set public = False for mapid in user.adminMaps: map = Map.get_by_id(int(mapid)) if map is not None and map.creatorId == int( userid) and map.name == name: return json_response(message="You already have a map of that name", code=400) map = Map(creator=user.name, creatorId=int(userid), name=name, adminIds=[int(userid)], public=public) key = map.put() # add map to user's list of maps user.adminMaps.append(key.integer_id()) user.put() #return map json return json_success(map.to_dict())
def userData(userid = -1): if userid <= 0: return json_response(code=400) user = Account.get_by_id(userid) if user is None: return json_response(code=400) if request.method == 'GET': # done # GET: returns json object of user return json_success(user.Get())
def mapInfoForUser(userid=-1): if userid <= 0: return json_response(code=400) user = Account.get_by_id(userid) if user is None: return json_response(code=400) if request.method == 'GET': # done # GET: returns json array of information about user's map objects return json_success(user.getMapsInfo())
def mapInfoForUser(userid = -1): if userid <= 0: return json_response(code=400) user = Account.get_by_id(userid) if user is None: return json_response(code=400) if request.method == 'GET': # done # GET: returns json array of information about user's map objects return json_success(user.getMapsInfo())
def userData(userid=-1): if userid <= 0: return json_response(code=400) user = Account.get_by_id(userid) if user is None: return json_response(code=400) if request.method == 'GET': # done # GET: returns json object of user return json_success(user.Get())
def api_login(): logging.info("api_login Type " + request.method) if request.method == 'POST': name = request.args.get("name", "") email = request.args.get("email", "") logging.info("name " + name + " email " + email) # once store token verified send a request for credential for gplus access_token = request.args.get("storeToken", "") gplus_id = request.args.get("id", "") logging.info(access_token) url = ("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s" % access_token) h = httplib2.Http() result = json.loads(h.request(url, 'GET')[1]) query = Account.query(Account.email == email) account = query.get() if query.count() != 0: logging.info("Account Already Exists") key = account.key return json_success({"uuid": key.integer_id()}) logging.info("first time logging in") session['gplus_id'] = gplus_id session['username'] = name account = Account(name=name, email=email, gplusId=gplus_id, accessToken=access_token, loggedIn=True) key = account.put() session['userId'] = key.integer_id() return json_success({"uuid": key.integer_id()}) if request.method == 'GET': return page_not_found(404)
def logout(): if request.method == 'POST': name = session['username'] account = Account.query(Account.name == name).get() account.loggedIn = False account.put() logging.info("session before " + str(len(session))) logging.info("session after " + str(len(session))) session['loggedIn'] = False logging.info("session set to loggedin = false") session.clear() return '200' if request.method == 'GET': return render_template('logout.html')
def index(): if "userId" in session: #logging.info("loggedIn=" + str(session['loggedIn'])) account = Account.get_by_id(session['userId']) if account is None: # prevent interal error return render_template('index.html') lin = account.loggedIn if lin == False: return render_template('index.html') if lin == True: return render_template('dashboard.html') if session: return render_template('dashboard.html') else: return render_template('index.html')
def mapAdmin(mapid=-1, email=""): if mapid <= 0: return json_response(code=400) if email == "": return json_response(code=400) map = Map.get_by_id(mapid) if map is None: return json_response(code=400) adminAccount = Account.query(Account.email == email).get() if adminAccount is None: return json_response(code=400) userid = adminAccount.key.integer_id() if request.method == 'POST': if userid not in map.adminIds: map.adminIds.append(userid) map.put() else: return json_success(adminAccount.Get()) if mapid not in adminAccount.adminMaps: adminAccount.adminMaps.append(mapid) adminAccount.put() return json_success(adminAccount.Get()) if request.method == 'DELETE': logging.info("delete") if userid not in map.adminIds: return json_response(code=400) if mapid not in adminAccount.adminMaps: return json_response(code=400) if adminAccount.key.integer_id() == map.creatorId: return json_response(code=400) map.adminIds.remove(userid) adminAccount.adminMaps.remove(mapid) map.put() adminAccount.put() return json_response(code=200)
def mapAdmin(mapid=-1,email=""): if mapid <= 0: return json_response(code=400) if email == "": return json_response(code=400) map = Map.get_by_id(mapid) if map is None: return json_response(code=400) adminAccount = Account.query(Account.email == email).get() if adminAccount is None: return json_response(code=400) userid = adminAccount.key.integer_id() if request.method == 'POST': if userid not in map.adminIds: map.adminIds.append(userid) map.put() else: return json_success(adminAccount.Get()) if mapid not in adminAccount.adminMaps: adminAccount.adminMaps.append(mapid) adminAccount.put() return json_success(adminAccount.Get()) if request.method == 'DELETE': logging.info("delete") if userid not in map.adminIds: return json_response(code=400) if mapid not in adminAccount.adminMaps: return json_response(code=400) if adminAccount.key.integer_id() == map.creatorId: return json_response(code=400) map.adminIds.remove(userid) adminAccount.adminMaps.remove(mapid) map.put() adminAccount.put() return json_response(code=200)
def admin_add(mapId,email): if request.method == 'POST': logging.info("email="+email) user = session['username'] uid = session['userId'] map = Map.get_by_id(mapId) adminAccount = Account.query(Account.email == email).get() if adminAccount == None: return json_response(message="No Account with that email exists",code=400) adminId = adminAccount.key.integer_id() if adminId not in map.adminIds: map.adminIds.append(adminId) map.put() if mapId not in adminAccount.adminMaps: adminAccount.adminMaps.append(mapId) adminAccount.put() return '200'
def admin_add(mapId, email): if request.method == 'POST': logging.info("email=" + email) user = session['username'] uid = session['userId'] map = Map.get_by_id(mapId) adminAccount = Account.query(Account.email == email).get() if adminAccount == None: return json_response(message="No Account with that email exists", code=400) adminId = adminAccount.key.integer_id() if adminId not in map.adminIds: map.adminIds.append(adminId) map.put() if mapId not in adminAccount.adminMaps: adminAccount.adminMaps.append(mapId) adminAccount.put() return '200'
def newMap(userid='', name='', public=''): if not (name and public and userid): return json_response(code=400); user = Account.get_by_id(int(userid)) if user is None: return json_response(code=400); if public == 'true': public = True else: # default false if not set public = False for mapid in user.adminMaps: map = Map.get_by_id(int(mapid)) if map is not None and map.creatorId == int(userid) and map.name == name: return json_response(message="You already have a map of that name", code=400); map = Map(creator=user.name,creatorId=int(userid),name=name,adminIds=[int(userid)], public=public) key = map.put() # add map to user's list of maps user.adminMaps.append(key.integer_id()) user.put() #return map json return json_success(map.to_dict());
def search(): if request.method == 'GET': maps = [] mapIds = [] queryType = request.args.get("queryType", "") query = request.args.get("query", "") uid = session['userId'] account = Account.get_by_id(uid) logging.info("searching for " + queryType + " " + query) mapQuery = Map.query(Map.public == True) for map in mapQuery: if queryType == 'searchMaps': if (query.lower() == map.name.lower()): logging.info("match!") maps.append(map) mapIds.append(map.key.integer_id()) for mapId in account.adminMaps: m = Map.get_by_id(mapId) if (query.lower() == m.name.lower()): if mapId not in mapIds: maps.append(m) logging.info(len(maps)) return render_template('search.html', maps=maps)
def search(): if request.method == 'GET': maps = [] mapIds = [] queryType=request.args.get("queryType","") query = request.args.get("query","") uid = session['userId'] account = Account.get_by_id(uid) logging.info("searching for " + queryType + " " + query) mapQuery = Map.query(Map.public == True) for map in mapQuery: if queryType == 'searchMaps': if(query.lower() == map.name.lower()): logging.info("match!") maps.append(map) mapIds.append(map.key.integer_id()) for mapId in account.adminMaps: m = Map.get_by_id(mapId) if (query.lower() == m.name.lower()): if mapId not in mapIds: maps.append(m) logging.info(len(maps)) return render_template('search.html',maps=maps)
def MakeUserAccount(UserID, Users): """ UserID : <int> Users : <dict> Returns account (Account object) """ #Make a Account and for the scenario, #Assume every User has 10 equipment and 10000 tokens user = Account(UserID) user.save_Equipment(100) user.save_Balance(10000) #stor user object in 'Users' dictionary Users[UserID] = user #create Transaction data to store in the block trx = Transaction(sender=AdminID, receiver=UserID, amount=10000, obj=['Equipment', 10]) return user, trx
def login(): if request.method == 'POST': name = request.args.get("name", "") email = request.args.get("email", "") logging.info("name " + name + " email " + email) account = Account.query(Account.email == email).get() #create a state string state = '' for x in xrange(32): state += random.choice(string.ascii_uppercase + string.digits) session['state'] = state storeToken = request.args.get("storeToken", "") #verify store token with google servers try: oauth_flow = flow_from_clientsecrets('client_secrets.json', scope='') oauth_flow.redirect_uri = 'postmessage' credentials = oauth_flow.step2_exchange(storeToken) except FlowExchangeError: logging.info("error with Oauth") return page_not_found(404) # once store token verified send a request for credential for gplus access_token = credentials.access_token logging.info(access_token) url = ("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s" % access_token) h = httplib2.Http() result = json.loads(h.request(url, 'GET')[1]) gplus_id = credentials.id_token['sub'] stored_credentials = session.get('credentials') stored_gplus_id = session.get('gplus_id') if account is not None: logging.info("User already logged in") account = Account.query(Account.email == email).get() account.loggedIn = True account.put() session['credentials'] = credentials session['gplus_id'] = gplus_id session['username'] = account.name session['userId'] = account.key.integer_id() session['loggedIn'] = True else: logging.info("first time logging in") session['credentials'] = credentials session['gplus_id'] = gplus_id session['username'] = name account = Account(name=name, email=email, gplusId=gplus_id, accessToken=access_token, loggedIn=True) key = account.put() session['userId'] = key.integer_id() session['loggedIn'] = True return '200' if request.method == 'GET': return page_not_found(404)
AdminID = 999 MinerID = 111 UserID = [random.randint(200, 800) for i in range(10)] #Create 10 Users randomly Users = {} #Store User object Userid : <class>account size = 10 PC = {} #Store every Private channel in storage #Total Property in Server Total_Token = 10000000 # 10000000 tokens Total_Equipment = 1000 # 1000 equipments # Total_ETC = 10000 #Creating Admin account, Setting primary numbers of Tokens and Equipments Admin = Account(AdminID) Admin.save_Equipment(1000) # Admin.save_ETC(10000) Admin.save_Balance(10000000) Transactions_que = [] #Temporary Storage for new transactions # Temporary_que = [] #The transaction will wait till six blocks added PrivateChannel_Network = np.zeros( (size, size)) #Graph of PrivateChannel among users PrivateChannel_Network[:][:] = 999 for i in range(size): PrivateChannel_Network[i][i] = 0 #First Transaction of the server is setting the primary properties in Admin account Base_Trx = Transaction(sender=000,
def getMaps(id): account = Account.get_by_id(id) return account.adminMaps
def favorites(): user = Account.get_by_id(int(session['userId'])) if user is None: return json_response(code=400) return json_success(user.getFavorites())
def favorites(): user = Account.get_by_id(int( session['userId'] )) if user is None: return json_response(code=400) return json_success(user.getFavorites())