def get_user_id(name): try: user=User.query.filter_by(name=name).first() if not user: return error_message('wrong id', code=405) return jsonify(user.json), 200 except IndexError: return error_message("Not a valid id!", code=405)
def get_passwords(username): try: idUser=User.query.filter_by(name=username).first() passwords = Password.query.filter_by(idUser=idUser.id).all() return jsonify([password.json for password in passwords]) except IndexError: return error_message("Not a valid id!", code=405)
def update_password(id): try: content = request.json account = content['account'] username = content['username'] password = content['password'] passw = Password.query.filter_by(id=id).first() if not passw: return error_message('bad id input', code=405) password = Event.query.filter_by(id=id).first() password.account = account password.username = username password.password = password db.session.commit() return jsonify([{"message": 'Event updated'}]), 200 except Exception as ex: return error_message('error in database update' + str(ex))
def create_password(): try: content = request.json account=content['account'] username=content['username'] password=content['password'] idUser=content['idUser'] passw=Password(account=account,username=username,password=password,idUser=idUser) db.session.add(passw) db.session.commit() return jsonify(passw.json),200 except Exception as ex: return error_message('error in database insert'+' '+str(ex))
def delete_password(id): try: password=Password.query.filter_by(id=id).first() db.session.delete(password) db.session.commit() # event = Event.query.filter_by(id=id).first() # participants = Participant.query.filter_by(idEvent=id).all() # for participant in participants: # RaceResult.query.filter_by(idParticipant=participant.id).delete() # db.session.delete(participant) # db.session.delete(event) # db.session.commit() return jsonify(id), 200 except Exception: return error_message('No such id')
def create_user(): try: content = request.json name = content["name"] password=content["password"] email = content["email"] # if "@" not in email or "." not in email: # return error_message('bad email input', code=400) user = User(name=name, password=password, email=email) db.session.add(user) db.session.commit() return jsonify(user.json), 200 except Exception as ex: return error_message('Error: '+str(ex))
def get_password(id): if not Password.query.filter_by(id=id).first(): return error_message('wrong id', code=405) password = Password.query.filter_by(id=id).first() return jsonify(password.json), 200