From 0c6249f6a1282fe2bdf96c12d99f2ed58acd65e0 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 29 Jan 2022 04:01:16 +0200 Subject: [PATCH] fsd --- files/routes/login.py | 68 ++++++++++++++++++++++--------------------- files/routes/users.py | 37 ++++++++++++----------- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/files/routes/login.py b/files/routes/login.py index 3a0050cc4..78c850ffd 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -34,45 +34,47 @@ def check_for_alts(current_id): if past_id == MOM_ID or current_id == MOM_ID: break if past_id == current_id: continue - check1 = g.db.query(Alt).filter_by( - user1=current_id, user2=past_id).one_or_none() - check2 = g.db.query(Alt).filter_by( - user1=past_id, user2=current_id).one_or_none() + li = [past_id, current_id] + existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none() - if not check1 and not check2: - - try: - new_alt = Alt(user1=past_id, user2=current_id) - g.db.add(new_alt) - g.db.flush() - except: pass + if not existing: + new_alt = Alt(user1=past_id, user2=current_id) + g.db.add(new_alt) + g.db.flush() - alts = g.db.query(Alt) - otheralts = alts.filter(or_(Alt.user1 == past_id, Alt.user2 == past_id, Alt.user1 == current_id, Alt.user2 == current_id)).all() + otheralts = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).all() for a in otheralts: - existing = alts.filter_by(user1=a.user1, user2=past_id).one_or_none() - if not existing: - new_alt = Alt(user1=a.user1, user2=past_id) - g.db.add(new_alt) - g.db.flush() + if a.user1 != past_id: + li = [a.user1, past_id] + existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none() + if not existing: + new_alt = Alt(user1=a.user1, user2=past_id) + g.db.add(new_alt) + g.db.flush() - existing = alts.filter_by(user1=a.user1, user2=current_id).one_or_none() - if not existing: - new_alt = Alt(user1=a.user1, user2=current_id) - g.db.add(new_alt) - g.db.flush() + if a.user1 != current_id: + li = [a.user1, current_id] + existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none() + if not existing: + new_alt = Alt(user1=a.user1, user2=current_id) + g.db.add(new_alt) + g.db.flush() - existing = alts.filter_by(user1=a.user2, user2=past_id).one_or_none() - if not existing: - new_alt = Alt(user1=a.user2, user2=past_id) - g.db.add(new_alt) - g.db.flush() + if a.user2 != past_id: + li = [a.user2, past_id] + existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none() + if not existing: + new_alt = Alt(user1=a.user2, user2=past_id) + g.db.add(new_alt) + g.db.flush() - existing = alts.filter_by(user1=a.user2, user2=current_id).one_or_none() - if not existing: - new_alt = Alt(user1=a.user2, user2=current_id) - g.db.add(new_alt) - g.db.flush() + if a.user2 != current_id: + li = [a.user2, current_id] + existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none() + if not existing: + new_alt = Alt(user1=a.user2, user2=current_id) + g.db.add(new_alt) + g.db.flush() @app.post("/login") diff --git a/files/routes/users.py b/files/routes/users.py index 986649e77..ad08e0ec4 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1010,23 +1010,22 @@ def saved_comments(v, username): @app.post("/fp/") @auth_required def fp(v, fp): - if v.username != fp: - v.fp = fp - users = g.db.query(User).filter(User.fp == fp, User.id != v.id).all() - if users: print(f'{v.username}: fp {v.fp}') - if v.email and v.is_activated: - alts = g.db.query(User).filter(User.email == v.email, User.is_activated, User.id != v.id).all() - if alts: - print(f'{v.username}: email {v.email}') - users += alts - for u in users: - li = [v.id, u.id] - existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).first() - if existing: continue - new_alt = Alt(user1=v.id, user2=u.id) - g.db.add(new_alt) - g.db.flush() - print('\n\n' + v.username + ' + ' + u.username + '\n\n') - g.db.add(v) - g.db.commit() + v.fp = fp + users = g.db.query(User).filter(User.fp == fp, User.id != v.id).all() + if users: print(f'{v.username}: fp {v.fp}') + if v.email and v.is_activated: + alts = g.db.query(User).filter(User.email == v.email, User.is_activated, User.id != v.id).all() + if alts: + print(f'{v.username}: email {v.email}') + users += alts + for u in users: + li = [v.id, u.id] + existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).first() + if existing: continue + new_alt = Alt(user1=v.id, user2=u.id) + g.db.add(new_alt) + g.db.flush() + print(v.username + ' + ' + u.username) + g.db.add(v) + g.db.commit() return '', 204 \ No newline at end of file