def get(self): # Parse Aguments args = log_in_parser.parse_args() # Create the chiper object and encypt the password cipher = AESCipher(secret_key) user_password = args["password"] encrypted_password = cipher.encrypt(user_password) # look for the user with that password try: usuario = session.query(Usuario).filter( and_( Usuario.nombre == args["nombre"], Usuario.password == encrypted_password )).first() except OperationalError: session.rollback() reconnect_to_db() LogIn.get(self) if usuario is None: # this user was not found return {"message": "Incorrect password or username"}, 500 else: info_usuario = { "nombre": usuario.nombre, "password": usuario.password, "permiso": usuario.permiso } return info_usuario, 200
def delete(self): #Parser arguments args = rem_event_parser.parse_args() #create the event id event_identifier = hash_event(args["nombre"]) # search for the assistants first then delete the event itself try: id_evento = session.query(Evento.id_evento).filter( Evento.nombre.like(args["nombre"])).scalar() except OperationalError: session.rollback() reconnect_to_db() RemoveEvent.delete(self) session.query(Asistente).filter( Asistente.id_evento == id_evento).delete() session.query(Evento).filter( Evento.id_evento == event_identifier).delete() session.commit() return '', 204 # return DELETE Success
def post(self): # Parser arguments args = add_event_parser.parse_args() #create the event id event_identifier = hash_event(args["nombre"]) # Create model object evento = Evento(id_evento=event_identifier, nombre=args["nombre"], lugar=args["lugar"], fecha=args["fecha"]) # Variable to control error detection for return values error_found = False try: session.add(evento) session.commit() except IntegrityError: # a duplicate entry was found in the db error_found = True print("\nDATABASE INTEGRITY ERROR! Aborting insersion of:\n{}". format(evento)) session.rollback() except OperationalError: session.rollback() reconnect_to_db() AddEvent.post(self) evento_data = { "id_evento": evento.id_evento, "nombre": evento.nombre, "lugar": evento.lugar, "fecha": evento.fecha } if error_found: return evento_data, 500 # Internal server error else: return evento_data, 201 # POST Success
def post(self): # Parse Arguments args = post_user_parser.parse_args() # Create the chiper object and encypt the password cipher = AESCipher(secret_key) user_password = args["password"] encrypted_password = cipher.encrypt(user_password) # Create model object usuario = Usuario(nombre=args["nombre"], password=encrypted_password, permiso=args["permiso"]) # Variable to control error detection for return values error_found = False try: session.add(usuario) session.commit() except IntegrityError: # a duplicate entry was found in the db error_found = True print("\nDATABASE INTEGRITY ERROR! Aborting Registration for:\n{}". format(usuario)) session.rollback() # restart session to get rid of errors except OperationalError: session.rollback() reconnect_to_db() ManageUsers.post(self) usuario_data = { "nombre": usuario.nombre, "password": usuario.password, "permiso": usuario.permiso } if error_found: return usuario_data, 500 # Internal Server Error else: return usuario_data, 201 # POST Success
def delete(self): # Process that deletes user from database # Create Parser args = rem_user_parser.parse_args() # Delete user specified try: session.query(Usuario).filter( Usuario.nombre == args["nombre"]).delete() except OperationalError: session.rollback() reconnect_to_db() ManageUsers.delete(self) session.commit() return '', 204 # return DELETE Success
def get(self, nombre_evento): # looks for an event id in the table and returns the number if one, and only one, match is found try: id_evento = session.query(Evento.id_evento).filter( Evento.nombre.like(nombre_evento)).scalar() except OperationalError: session.rollback() reconnect_to_db() DownloadStats.get(self, nombre_evento) # create a list to store all of the assistants info_asistentes = [] # look for all the assistants in the db try: asistentes_evento = session.query(Asistente).filter( Asistente.id_evento == id_evento).all() except OperationalError: session.rollback() reconnect_to_db() DownloadStats.get(self, nombre_evento) # add everyone to the list as a dict (json) for asistente in asistentes_evento: asistentes_auxiliar = { "doc_identidad": asistente.doc_identidad, "serial": asistente.serial, "nombre": asistente.nombre, "codigo": asistente.codigo, "ocupacion": asistente.ocupacion, "edad": asistente.edad, "sexo": asistente.sexo, "asistio": asistente.asistio, "id_evento": asistente.id_evento } info_asistentes.append(asistentes_auxiliar) return info_asistentes, 200
def put(self, nombre_evento, doc_identidad): # Calculate the event id id_evento = hash_event(nombre_evento) # look up the specific person you are looking for try: persona = session.query(Asistente).filter( and_(Asistente.doc_identidad == doc_identidad, Asistente.id_evento == id_evento)).first() except OperationalError: session.rollback() reconnect_to_db() UploadEvent.put(self, nombre_evento, doc_identidad) # update the specified value persona.asistio = True # commit the changes session.commit() return '', 201 # PUT success
def get(self): # Process to get a list with all of the users info_usuarios = [] try: lista_usuarios = session.query(Usuario).all() except OperationalError: session.rollback() reconnect_to_db() ManageUsers.get(self) for usuario in lista_usuarios: usuario_auxiliar = { "nombre": usuario.nombre, "password": usuario.password, "permiso": usuario.permiso } info_usuarios.append(usuario_auxiliar) return info_usuarios, 200
def post(self): # Parse Arguments args = register_parser.parse_args() # look for the corresponding event id based on the event name try: id_evento_persona = session.query(Evento.id_evento).filter( Evento.nombre == args["nombre_evento"]).scalar() except OperationalError: session.rollback() reconnect_to_db() Register.post(self) # Create model object persona = Asistente(doc_identidad=args["doc_identidad"], serial=args["serial"], nombre=args["nombre"], codigo=args["codigo"], ocupacion=args["ocupacion"], edad=args["edad"], sexo=args["sexo"], asistio=False, id_evento=id_evento_persona) # Variable to control error detection for return values error_found = False try: session.add(persona) session.commit() except IntegrityError: # a duplicate entry was found in the db error_found = True print("\nDATABASE INTEGRITY ERROR! Aborting Registration for:\n{}". format(persona)) session.rollback() # restart session to get rid of errors except OperationalError: session.rollback() reconnect_to_db() Register.post(self) persona_data = { "doc_identidad": persona.doc_identidad, "serial": persona.serial, "nombre": persona.nombre, "codigo": persona.codigo, "ocupacion": persona.ocupacion, "edad": persona.edad, "sexo": persona.sexo, "id_evento": persona.id_evento } if error_found: return persona_data, 500 # Internal Server Error else: return persona_data, 201 # POST Success
def get(self): # looks for an event id in the table and returns the number if one, and only one, match is found try: eventos = session.query(Evento).all() except OperationalError: session.rollback() reconnect_to_db() GetEvents.get(self) # create a list to store all the events lista_eventos = [] # add every event to the list for evento in eventos: evento_auxiliar = { "nombre": evento.nombre, "lugar": evento.lugar, "fecha": evento.fecha } lista_eventos.append(evento_auxiliar) return lista_eventos, 200