forked from MarseyWorld/MarseyWorld
use get_user whenever possible instead of repeating code
parent
88d77fd6c1
commit
c3870505ea
|
@ -377,15 +377,11 @@ def post_forgot():
|
||||||
if not email_regex.fullmatch(email):
|
if not email_regex.fullmatch(email):
|
||||||
return render_template("login/forgot_password.html", error="Invalid email!"), 400
|
return render_template("login/forgot_password.html", error="Invalid email!"), 400
|
||||||
|
|
||||||
|
user = get_user(username, graceful=True)
|
||||||
username = username.lstrip('@').replace('\\', '').replace('_', '\_').replace('%', '').strip()
|
|
||||||
email = email.replace('\\', '').replace('_', '\_').replace('%', '').strip()
|
email = email.replace('\\', '').replace('_', '\_').replace('%', '').strip()
|
||||||
|
|
||||||
user = g.db.query(User).filter(
|
if user and user.email.lower() == email.lower():
|
||||||
User.username.ilike(username),
|
|
||||||
User.email.ilike(email)).one_or_none()
|
|
||||||
|
|
||||||
if user:
|
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
token = generate_hash(f"{user.id}+{now}+forgot+{user.login_nonce}")
|
token = generate_hash(f"{user.id}+{now}+forgot+{user.login_nonce}")
|
||||||
url = f"{SITE_FULL}/reset?id={user.id}&time={now}&token={token}"
|
url = f"{SITE_FULL}/reset?id={user.id}&time={now}&token={token}"
|
||||||
|
|
|
@ -732,7 +732,7 @@ def settings_name_change(v):
|
||||||
|
|
||||||
new_name = request.values.get("name").strip()
|
new_name = request.values.get("name").strip()
|
||||||
|
|
||||||
if new_name==v.username:
|
if new_name == v.username:
|
||||||
abort(400, "You didn't change anything")
|
abort(400, "You didn't change anything")
|
||||||
|
|
||||||
if v.patron:
|
if v.patron:
|
||||||
|
@ -743,17 +743,9 @@ def settings_name_change(v):
|
||||||
if not used_regex.fullmatch(new_name):
|
if not used_regex.fullmatch(new_name):
|
||||||
abort(400, "This isn't a valid username.")
|
abort(400, "This isn't a valid username.")
|
||||||
|
|
||||||
search_name = new_name.replace('\\', '').replace('_','\_').replace('%','')
|
existing = get_user(new_name, graceful=True)
|
||||||
|
|
||||||
x = g.db.query(User).filter(
|
if existing and existing.id != v.id:
|
||||||
or_(
|
|
||||||
User.username.ilike(search_name),
|
|
||||||
User.original_username.ilike(search_name),
|
|
||||||
User.prelock_username.ilike(search_name),
|
|
||||||
)
|
|
||||||
).one_or_none()
|
|
||||||
|
|
||||||
if x and x.id != v.id:
|
|
||||||
abort(400, f"Username `{new_name}` is already in use.")
|
abort(400, f"Username `{new_name}` is already in use.")
|
||||||
|
|
||||||
v.username = new_name
|
v.username = new_name
|
||||||
|
|
|
@ -710,20 +710,12 @@ def is_available(name):
|
||||||
|
|
||||||
name = name.strip()
|
name = name.strip()
|
||||||
|
|
||||||
if len(name)<3 or len(name)>25:
|
if len(name) < 3 or len(name) > 25:
|
||||||
return {name:False}
|
return {name: False}
|
||||||
|
|
||||||
name2 = name.replace('\\', '').replace('_','\_').replace('%','')
|
existing = get_user(name, graceful=True)
|
||||||
|
|
||||||
x = g.db.query(User).filter(
|
if existing:
|
||||||
or_(
|
|
||||||
User.username.ilike(name2),
|
|
||||||
User.original_username.ilike(name2),
|
|
||||||
User.prelock_username.ilike(name2),
|
|
||||||
)
|
|
||||||
).one_or_none()
|
|
||||||
|
|
||||||
if x:
|
|
||||||
return {name: False}
|
return {name: False}
|
||||||
else:
|
else:
|
||||||
return {name: True}
|
return {name: True}
|
||||||
|
|
Loading…
Reference in New Issue