def users_login(cls, request): try: user = Usuarios.query(Usuarios.email == request.email).fetch( ) #obtiene el usuario dado el email if not user or len(user) == 0: #si no encuentra user saca raise NotFoundException() user = user[0] keye = user.empresa_key.urlsafe( ) # regresa como mensaje el empresa key if not user.verify_password( request.password): # checa la contrasena raise NotFoundException() token = jwt.encode( { 'user_id': user.key.id(), 'exp': time.time() + 43200 }, 'secret') #crea el token message = TokenMessage(token=token, message=keye, code=1) # regresa token except NotFoundException: message = TokenMessage(token=None, message='Wrong username or password', code=-1) return message
def get(self): self.response.headers.add_header('Access-Control-Allow-Origin', '*') self.response.headers['Content-Type'] = 'application/json' id_user = self.request.get('user') objemp = Usuarios.query(Usuarios.email == id_user).get() if objemp is None: myList = [] json_string = json.dumps(myList, default=MyClass) self.response.write(json_string) return None strKey = objemp.key.urlsafe() ownerKey = ndb.Key(urlsafe=strKey) myEntities = Publisher.query(Publisher.user_key == ownerKey) myList = [] for i in myEntities: myObj = DemoClass() myObj.entityKey = i.entityKey myObj.nameA = i.nameA myObj.location = i.location myObj.year = i.year myObj.logo = i.logo myList.append(myObj) json_string = json.dumps(myList, default=MyClass) self.response.write(json_string)
def lista_usuarios(cls, request): try: token = jwt.decode(request.tokenint, 'secret') #checa token user = Usuarios.get_by_id( token['user_id']) #obtiene usuario dado el token lista = [] #crea lista lstMessage = UserList(code=1) # crea objeto mensaje lstBd = Usuarios.query().fetch() # recupera de base de datos for i in lstBd: # recorre lista.append( UserUpdate( token='', entityKey=i.entityKey, #empresa_key=user.empresa_key.urlsafe(), email=i.email, codigo_empresa=i.codigo_empresa)) # agrega a la lista lstMessage.data = lista # la manda al messa message = lstMessage #regresa except jwt.DecodeError: message = UserList(code=-1, data=[]) #token invalido except jwt.ExpiredSignatureError: message = UserList(code=-2, data=[]) #token expiro return message
def get(self): self.response.headers.add_header('Access-Control-Allow-Origin', '*') self.response.headers['Content-Type'] = 'application/json' c = ModelClass() try: userkey = self.request.get('key') id_userkey = ndb.Key(urlsafe=userkey) myUser = Usuarios.query(Usuarios.key == id_userkey).get() c.key = userkey if myUser is not None: c.email = myUser.email c.passwd = myUser.password else: c.message = "error: not found" except: c.message = "Exception ..." json_string = json.dumps(c, default=ObjectClass) self.response.write(json_string)
def get(self): self.response.headers.add_header('Access-Control-Allow-Origin', '*') self.response.headers['Content-Type'] = 'application/json' id_empresa = self.request.get('empresa') objemp = Empresa.query(Empresa.codigo_empresa == id_empresa).get() myUsers = Usuarios.query() myList = [] for i in myUsers: myObj = DemoClass() myObj.nombre = i.nombre myObj.email = i.email myObj.edad = i.edad myObj.talla = i.talla myObj.urlImage = i.urlImage myList.append(myObj) json_string = json.dumps(myList, default=MyClass) self.response.write(json_string)
def get(self): self.response.headers.add_header('Access-Control-Allow-Origin', '*') self.response.headers['Content-Type'] = 'application/json' myList = [] try: lstUsers = Usuarios.query().fetch() for i in lstUsers: c = ModelClass() c.id = i.key.urlsafe() c.email = i.email c.passwd = i.password myList.append(c) except: c = ModelClass() c.message = "Exception ..." myList.append(c) json_string = json.dumps(myList, default=ObjectClass) self.response.write(json_string)