def login(request): ''' authentication :param request: :return: ''' if request.method == 'GET': code = request.GET.get("code", None) # request for the access_token and refresh token print "code: %s"%code r = getToken(code) if r: # get user info userInfo = getUserInfo(r['access_token'],r['openid']) discounts = Discount_Info.objects.filter(lang=0).order_by('-dis_id')[:15] ozdiscounts = Discount_Info.objects.filter(lang=1).order_by('-dis_id')[:15] rates = Rate.objects.all() # store user info is_exist = Visitor.objects.filter(openid=userInfo['openid']) if not is_exist: user = Visitor() # 存在即更新 else: user = is_exist[0] for key in user.__dict__: if key in userInfo: setattr(user, key, userInfo[key]) user.save() return render_to_response('index.html', dict(data=userInfo, discounts=discounts, rates=rates, ozdiscounts=ozdiscounts) ) # else: response = HttpResponse(u"认证失败") return response
def menu(): no_menu = True while no_menu: print("[1] Login") print("[2] Crear Cuenta") print("[3] Ver hilos") print("[0] Salir") opcion = utils.getNumber(4) if opcion == 1: user = input("Usuario: ") passs = input("Contraseña: ") token = utils.getToken(user, passs) if token != False: print("Bienvenido " + utils.getName(token)) no_menu = False else: print("Usuario/Contraseña Incorrectos") elif opcion == 2: user = input("Usuario: ") passs = input("Contraseña: ") name = input("Nombre: ") utils.Logon(user, passs, name) elif opcion == 3: print("Mostrar hilos") elif opcion == 0: print("Saliendo...") no_menu = False
def generate_user_data(self): regInput = self.collect_input() question1 = str(self.ques1.currentText()) question2 = str(self.ques2.currentText()) title = str(self.titleField.text()) or "Guess" token = getToken() timelog = getTime() sysInfo = get_user_location() productID = sysInfo['Product ID'] ip, cityIP, countryIP = get_local_pc_info() unix = getUnix() datelog = getDate() pcOS = sysInfo['os'] pcUser = sysInfo['pcUser'] pcPython = sysInfo['python'] if not os.path.exists(self.rawAvatarPth): avatar = get_avatar_image('default') else: avatar = self.rawAvatarPth data = [ regInput[0], regInput[1], regInput[3], regInput[4], title, regInput[5], regInput[6], regInput[7], regInput[8], regInput[9], regInput[10], regInput[11], token, timelog, productID, ip, cityIP, countryIP, unix, question1, regInput[12], question2, regInput[13], datelog, pcOS, pcUser, pcPython, avatar ] return data
def appSDKification(folder, progress): ''' zip app folder and send to WAB compiler to apply SDK compilation. The returned zip will be the official webapp ''' progress.oscillate() progress.setText("Get Authorization token") try: global __appSDKification_doAgain if __appSDKification_doAgain: QgsMessageLog.logMessage("Renew token in case of it is expired and retry", level=QgsMessageLog.WARNING) utils.resetCachedToken() token = utils.getToken() except Exception as e: pub.sendMessage(utils.topics.endAppSDKification, success=False, reason=str(e)) return # zip folder to send for compiling progress.setText("Preparing data to compile") zipFileName = tempFilenameInTempFolder("webapp.zip", "webappbuilder") try: with zipfile.ZipFile(zipFileName, "w") as zf: relativeFrom = os.path.dirname(folder) for dirname, subdirs, files in os.walk(folder): # exclude data folder if 'data' in subdirs: subdirs.remove('data') if relativeFrom in dirname: zf.write(dirname, dirname[len(relativeFrom):]) for filename in files: fiename = os.path.join(dirname, filename) zf.write(fiename, fiename[len(relativeFrom):]) except: msg = "Could not zip webapp folder: {}".format(folder) pub.sendMessage(utils.topics.endAppSDKification, success=False, reason=msg) return # prepare data for WAB compiling request with open(zipFileName, 'rb') as f: fileContent = f.read() fields = { 'file': (os.path.basename(zipFileName), fileContent) } payload, content_type = encode_multipart_formdata(fields) headers = {} headers["authorization"] = "Bearer {}".format(token) headers["Content-Type"] = content_type # prepare request (as in NetworkAccessManager) but without blocking request # do http post progress.setText("Wait compilation") global __anam if __anam: del __anam __anam = None __anam = NetworkAccessManager(debug=pluginSetting("logresponse")) __anam.request(utils.wabCompilerUrl(), method='POST', body=payload, headers=headers, blocking=False) __anam.reply.finished.connect( lambda: manageFinished(__anam, zipFileName, folder, progress) )
def checkSDKServerVersion(): localVersion = utils.sdkVersion() token = utils.getToken() headers = {} headers["authorization"] = "Bearer {}".format(token) nam = NetworkAccessManager(debug=pluginSetting("logresponse")) try: resp, text = nam.request(wabVersionUrl(), headers=headers) except Exception as e: # check if 401/403 => probably token expired permissionDenied = utils.isPermissionDenied(str(e)) if not permissionDenied: raise e else: # renew token and try again utils.resetCachedToken() token = utils.getToken() # retry call headers["authorization"] = "Bearer {}".format(token) try: resp, text = nam.request(wabVersionUrl(), headers=headers) except Exception as e: # check if 401/403 => probably token expired permissionDenied = utils.isPermissionDenied(str(e)) if not permissionDenied: raise e else: raise Exception( "Permission denied with current Connect credentials") remoteVersion = json.loads(text)["boundless-sdk"] if localVersion != remoteVersion: raise VersionMismatchError( "The server SDK version (%s) is different from the expected version (%s)" % (remoteVersion, localVersion))
def __krpcQueryGetPeersReceived(self, krpcQuery): """ Process a KRPC get_peers query. """ response = krpc.krpccoder.KRPCResponse.fromQuery(krpcQuery) response.token = utils.getToken(krpcQuery.fromNode) if AppState.peerStorage.torrentExists(krpcQuery.targetID): peers = AppState.peerStorage.getPeers(krpcQuery.targetID) if krpcQuery.noSeeders: peers = filter(lambda p: not p.seeder, peers) response.peers = AppState.peerStorage.getPeers(krpcQuery.targetID) else: response.nodes = AppState.routingTable.findClosestNodes(krpcQuery.targetID) self._krpcSend(response)
await client.send_message(file_resp[0], file_resp[1]) #if message.content.lower().startswith("update"): # await client.send_message(message.channel, content = "ok") # update() #test for all the kneejerk-reaction comments. require an exact match. #timt.time() returns a seconds amount, spam filter is 15sec #for test in kneejerkList: # if (message.content.lower() == test[0]): # if time.time() - test[2] >= 15: # test[2] = time.time() # await client.send_message(message.channel, content = test[1]) # else: # print("anti-spam caught something") #test for the same as above, but works whenever the test #text is at the beginning #for test in kneejerkBeginningList: # if (message.content.lower().startswith(test[0])): # if time.time() - test[2] >= 15: # test[2] = time.time() # await client.send_message(message.channel, content = test[1]) # else: # print("anti-spam caught something") #this actually starts the bot token = utils.getToken() client.run(token)
from bot import BotAppConfig from ip_camera import IpCameraConfig from utils import getToken, readToken config = BotAppConfig() config.timezone = 'Europe/Warsaw' if readToken(): config.token = getToken() config.alarm = False config.camera_config = None
def setupClass(self): print '------- testread1.py ----------' print 'prepare stuffs' self.token = utils.getToken() time.sleep(10)
def menu(): primera_vez = True name = "Anonimo" no_menu = True token = False os.system("cls") while no_menu: print(" ______________________ ") print("|| ||") print("|| MENU PRINCIPAL ||") print("|| ||") print("|| [1] Login ||") print("|| [2] Crear Cuenta ||") print("|| [3] Ver hilos ||") print("|| [0] Salir ||") print("|| ||") print("||______________________||") opcion = utils.getNumber(0, 4, "Opción: ") if opcion == 1: os.system("cls") print("{### FORMULARIO LOGEO ###}") user = input("Usuario: ") passs = utils.keyAlmacenada(0, user, "") no_guardado = False if passs == None: no_guardado = True passs = input("Contraseña: ") token = utils.getToken(user, passs) if token != False: if no_guardado: utils.keyAlmacenada(1, user, passs) name = utils.getName(token) no_menu2 = True while no_menu2: if primera_vez: os.system("cls") print("Bienvenido " + name) primera_vez = False maxima = 2 os.system("cls") print(" ______________________ ") print("|| ||") print("|| LOGEADO ||") print("|| ||") print("|| [1] Ver hilos ||") if user != "Anonimo": print("|| [2] Nuevo hilo ||") maxima = 3 if name == "dios": print("|| [3] Borrar hilo ||") maxima = 4 print("|| [0] Salir ||") print("|| ||") print("||______________________||") opcion = utils.getNumber(0, maxima, "Opción: ") if opcion == 1: no_menu21 = True while no_menu21: os.system("cls") print( " ______________________________________________ " ) print("||\t\t\t\t\t\t||") print("||\t\tSELECCIONA EL HILO\t\t||") utils.getHilos() print("||\t\t[100] Volver\t\t\t||") print("||\t\t\t\t\t\t||") print( "||______________________________________________||" ) opcion = utils.getNumber(100, utils.cuenta_hilos, "ID Hilo: ") if opcion >= 101: no_menu4 = True while no_menu4: os.system("cls") print("Mostrando hilo " + str(opcion) + ": " + utils.hilos[opcion - 101]) print( " _______________________________________________________________________________ " ) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t\tHILOS\t\t\t\t\t||") utils.getComentarios(opcion) if (name == "dios"): print( "||\t\t\t\t[98] Borrar comentario\t\t\t\t||" ) if (name != "Anonimo"): print( "||\t\t\t\t[99] Añadir comentario\t\t\t\t||" ) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t[100] Volver\t\t\t\t\t||") print("||\t\t\t\t\t\t\t\t\t\t||") print( "||______________________________________________________________________________||" ) opcion2 = utils.getNumber( 98, 101, "Opcion: ") if opcion2 == 100: no_menu4 = False os.system("cls") elif opcion2 == 99: print("{### NUEVO COMENTARIO ###}") texto_comentario = input( "Texto del comentario: ") utils.setComentarioHilo( opcion, texto_comentario, name, token) elif opcion2 == 98: print("{### BORRAR COMENTARIO ###}") Id_comentario = utils.getNumber( 100, utils.cuenta_comentarios, "Id Comentario: ") utils.deleteComentarioHilo( opcion, Id_comentario, token) else: no_menu21 = False os.system("cls") elif opcion == 2: os.system("cls") print("Escribe 'Cancelar' para cancelar la accion.") print("{########~NUEVO HILO~########}") titulo_hilo = input("Nombre del hilo: ") if titulo_hilo != "Cancelar": utils.setHilo(name, titulo_hilo, token) elif opcion == 3: os.system("cls") print( " ______________________________________________") print("||\t\t\t\t\t\t||") print("||\t\tSELECCIONA EL HILO\t\t||") utils.getHilos() print("||\t\t\t\t\t\t||") print("||\t\t[100] Volver\t\t\t||") print("||\t\t\t\t\t\t||") print( "||______________________________________________||" ) id_hilo = utils.getNumber(100, utils.cuenta_hilos, "ID Hilo: ") if id_hilo != 100: utils.deleteHilo(id_hilo, token) else: no_menu2 = False os.system("cls") primera_vez = True name = "Anonimo" token = False else: print("Usuario/Contraseña Incorrectos") elif opcion == 2: no_pass = True os.system("cls") print("{### FORMULARIO REGISTRO ###}") user = input("Usuario: ") while no_pass: passs = input("Contraseña: ") repass = input("Introduzca de nuevo la contraseña: ") if passs == repass: no_pass = False else: print("Las contraseñas no coinciden") name = input("Nombre: ") utils.Logon(user, passs, name) elif opcion == 3: if primera_vez: os.system("cls") print("Has entrado como " + name) primera_vez = False no_menu3 = True while no_menu3: print(" ______________________________________________ ") print("||\t\t\t\t\t\t||") print("||\t\tSELECCIONA EL HILO\t\t||") utils.getHilos() print("||\t\t\t\t\t\t||") print("||\t\t[100] Volver\t\t\t||") print("||______________________________________________||") opcion = utils.getNumber(100, utils.cuenta_hilos, "Opción: ") if opcion != 100: no_menu31 = True while no_menu31: os.system("cls") print("Mostrando hilo " + str(opcion) + ": " + utils.hilos[opcion - 101]) print( " _______________________________________________________________________________ " ) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t\tHILOS\t\t\t\t\t||") utils.getComentarios(opcion) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t[100] Volver\t\t\t\t\t||") print("||\t\t\t\t\t\t\t\t\t\t||") print( "||______________________________________________________________________________||" ) opcion = utils.getNumber(100, 101, "Opción: ") if opcion == 100: os.system("cls") no_menu31 = False else: os.system("cls") no_menu3 = False primera_vez = True name = "Anonimo" elif opcion == 0: os.system("cls") print("Saliendo...") no_menu = False