mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Merge branch 'fix-tuple-return-style' into pu
This commit is contained in:
commit
fb0f252b39
3 changed files with 34 additions and 34 deletions
|
@ -99,7 +99,7 @@ class BasicAuthBackend(AuthenticationBackend):
|
||||||
|
|
||||||
sid = conn.cookies.get("AURSID")
|
sid = conn.cookies.get("AURSID")
|
||||||
if not sid:
|
if not sid:
|
||||||
return None, AnonymousUser()
|
return (None, AnonymousUser())
|
||||||
|
|
||||||
now_ts = datetime.utcnow().timestamp()
|
now_ts = datetime.utcnow().timestamp()
|
||||||
record = session.query(Session).filter(
|
record = session.query(Session).filter(
|
||||||
|
@ -108,7 +108,7 @@ class BasicAuthBackend(AuthenticationBackend):
|
||||||
|
|
||||||
# If no session with sid and a LastUpdateTS now or later exists.
|
# If no session with sid and a LastUpdateTS now or later exists.
|
||||||
if not record:
|
if not record:
|
||||||
return None, AnonymousUser()
|
return (None, AnonymousUser())
|
||||||
|
|
||||||
# At this point, we cannot have an invalid user if the record
|
# At this point, we cannot have an invalid user if the record
|
||||||
# exists, due to ForeignKey constraints in the schema upheld
|
# exists, due to ForeignKey constraints in the schema upheld
|
||||||
|
@ -117,7 +117,7 @@ class BasicAuthBackend(AuthenticationBackend):
|
||||||
user.nonce = util.make_nonce()
|
user.nonce = util.make_nonce()
|
||||||
user.authenticated = True
|
user.authenticated = True
|
||||||
|
|
||||||
return AuthCredentials(["authenticated"]), user
|
return (AuthCredentials(["authenticated"]), user)
|
||||||
|
|
||||||
|
|
||||||
def auth_required(is_required: bool = True,
|
def auth_required(is_required: bool = True,
|
||||||
|
|
|
@ -126,26 +126,26 @@ def process_account_form(request: Request, user: models.User, args: dict):
|
||||||
host = request.client.host
|
host = request.client.host
|
||||||
ban = db.query(models.Ban, models.Ban.IPAddress == host).first()
|
ban = db.query(models.Ban, models.Ban.IPAddress == host).first()
|
||||||
if ban:
|
if ban:
|
||||||
return False, [
|
return (False, [
|
||||||
"Account registration has been disabled for your "
|
"Account registration has been disabled for your "
|
||||||
"IP address, probably due to sustained spam attacks. "
|
"IP address, probably due to sustained spam attacks. "
|
||||||
"Sorry for the inconvenience."
|
"Sorry for the inconvenience."
|
||||||
]
|
])
|
||||||
|
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
if not request.user.valid_password(args.get("passwd", None)):
|
if not request.user.valid_password(args.get("passwd", None)):
|
||||||
return False, ["Invalid password."]
|
return (False, ["Invalid password."])
|
||||||
|
|
||||||
email = args.get("E", None)
|
email = args.get("E", None)
|
||||||
username = args.get("U", None)
|
username = args.get("U", None)
|
||||||
|
|
||||||
if not email or not username:
|
if not email or not username:
|
||||||
return False, ["Missing a required field."]
|
return (False, ["Missing a required field."])
|
||||||
|
|
||||||
username_min_len = aurweb.config.getint("options", "username_min_len")
|
username_min_len = aurweb.config.getint("options", "username_min_len")
|
||||||
username_max_len = aurweb.config.getint("options", "username_max_len")
|
username_max_len = aurweb.config.getint("options", "username_max_len")
|
||||||
if not util.valid_username(args.get("U")):
|
if not util.valid_username(args.get("U")):
|
||||||
return False, [
|
return (False, [
|
||||||
"The username is invalid.",
|
"The username is invalid.",
|
||||||
[
|
[
|
||||||
_("It must be between %s and %s characters long") % (
|
_("It must be between %s and %s characters long") % (
|
||||||
|
@ -153,20 +153,20 @@ def process_account_form(request: Request, user: models.User, args: dict):
|
||||||
"Start and end with a letter or number",
|
"Start and end with a letter or number",
|
||||||
"Can contain only one period, underscore or hyphen.",
|
"Can contain only one period, underscore or hyphen.",
|
||||||
]
|
]
|
||||||
]
|
])
|
||||||
|
|
||||||
password = args.get("P", None)
|
password = args.get("P", None)
|
||||||
if password:
|
if password:
|
||||||
confirmation = args.get("C", None)
|
confirmation = args.get("C", None)
|
||||||
if not util.valid_password(password):
|
if not util.valid_password(password):
|
||||||
return False, [
|
return (False, [
|
||||||
_("Your password must be at least %s characters.") % (
|
_("Your password must be at least %s characters.") % (
|
||||||
username_min_len)
|
username_min_len)
|
||||||
]
|
])
|
||||||
elif not confirmation:
|
elif not confirmation:
|
||||||
return False, ["Please confirm your new password."]
|
return (False, ["Please confirm your new password."])
|
||||||
elif password != confirmation:
|
elif password != confirmation:
|
||||||
return False, ["Password fields do not match."]
|
return (False, ["Password fields do not match."])
|
||||||
|
|
||||||
backup_email = args.get("BE", None)
|
backup_email = args.get("BE", None)
|
||||||
homepage = args.get("HP", None)
|
homepage = args.get("HP", None)
|
||||||
|
@ -184,32 +184,32 @@ def process_account_form(request: Request, user: models.User, args: dict):
|
||||||
func.lower(models.User.Email) == email.lower())
|
func.lower(models.User.Email) == email.lower())
|
||||||
|
|
||||||
if not util.valid_email(email):
|
if not util.valid_email(email):
|
||||||
return False, ["The email address is invalid."]
|
return (False, ["The email address is invalid."])
|
||||||
elif backup_email and not util.valid_email(backup_email):
|
elif backup_email and not util.valid_email(backup_email):
|
||||||
return False, ["The backup email address is invalid."]
|
return (False, ["The backup email address is invalid."])
|
||||||
elif homepage and not util.valid_homepage(homepage):
|
elif homepage and not util.valid_homepage(homepage):
|
||||||
return False, [
|
return (False, [
|
||||||
"The home page is invalid, please specify the full HTTP(s) URL."]
|
"The home page is invalid, please specify the full HTTP(s) URL."])
|
||||||
elif pgp_key and not util.valid_pgp_fingerprint(pgp_key):
|
elif pgp_key and not util.valid_pgp_fingerprint(pgp_key):
|
||||||
return False, ["The PGP key fingerprint is invalid."]
|
return (False, ["The PGP key fingerprint is invalid."])
|
||||||
elif ssh_pubkey and not util.valid_ssh_pubkey(ssh_pubkey):
|
elif ssh_pubkey and not util.valid_ssh_pubkey(ssh_pubkey):
|
||||||
return False, ["The SSH public key is invalid."]
|
return (False, ["The SSH public key is invalid."])
|
||||||
elif language and language not in l10n.SUPPORTED_LANGUAGES:
|
elif language and language not in l10n.SUPPORTED_LANGUAGES:
|
||||||
return False, ["Language is not currently supported."]
|
return (False, ["Language is not currently supported."])
|
||||||
elif timezone and timezone not in time.SUPPORTED_TIMEZONES:
|
elif timezone and timezone not in time.SUPPORTED_TIMEZONES:
|
||||||
return False, ["Timezone is not currently supported."]
|
return (False, ["Timezone is not currently supported."])
|
||||||
elif db.query(models.User, username_exists(username)).first():
|
elif db.query(models.User, username_exists(username)).first():
|
||||||
# If the username already exists...
|
# If the username already exists...
|
||||||
return False, [
|
return (False, [
|
||||||
_("The username, %s%s%s, is already in use.") % (
|
_("The username, %s%s%s, is already in use.") % (
|
||||||
"<strong>", username, "</strong>")
|
"<strong>", username, "</strong>")
|
||||||
]
|
])
|
||||||
elif db.query(models.User, email_exists(email)).first():
|
elif db.query(models.User, email_exists(email)).first():
|
||||||
# If the email already exists...
|
# If the email already exists...
|
||||||
return False, [
|
return (False, [
|
||||||
_("The address, %s%s%s, is already in use.") % (
|
_("The address, %s%s%s, is already in use.") % (
|
||||||
"<strong>", email, "</strong>")
|
"<strong>", email, "</strong>")
|
||||||
]
|
])
|
||||||
|
|
||||||
def ssh_fingerprint_exists(fingerprint):
|
def ssh_fingerprint_exists(fingerprint):
|
||||||
return and_(models.SSHPubKey.UserID != user.ID,
|
return and_(models.SSHPubKey.UserID != user.ID,
|
||||||
|
@ -218,26 +218,26 @@ def process_account_form(request: Request, user: models.User, args: dict):
|
||||||
if ssh_pubkey:
|
if ssh_pubkey:
|
||||||
fingerprint = get_fingerprint(ssh_pubkey.strip().rstrip())
|
fingerprint = get_fingerprint(ssh_pubkey.strip().rstrip())
|
||||||
if fingerprint is None:
|
if fingerprint is None:
|
||||||
return False, ["The SSH public key is invalid."]
|
return (False, ["The SSH public key is invalid."])
|
||||||
|
|
||||||
if db.query(models.SSHPubKey,
|
if db.query(models.SSHPubKey,
|
||||||
ssh_fingerprint_exists(fingerprint)).first():
|
ssh_fingerprint_exists(fingerprint)).first():
|
||||||
return False, [
|
return (False, [
|
||||||
_("The SSH public key, %s%s%s, is already in use.") % (
|
_("The SSH public key, %s%s%s, is already in use.") % (
|
||||||
"<strong>", fingerprint, "</strong>")
|
"<strong>", fingerprint, "</strong>")
|
||||||
]
|
])
|
||||||
|
|
||||||
captcha_salt = args.get("captcha_salt", None)
|
captcha_salt = args.get("captcha_salt", None)
|
||||||
if captcha_salt and captcha_salt not in get_captcha_salts():
|
if captcha_salt and captcha_salt not in get_captcha_salts():
|
||||||
return False, ["This CAPTCHA has expired. Please try again."]
|
return (False, ["This CAPTCHA has expired. Please try again."])
|
||||||
|
|
||||||
captcha = args.get("captcha", None)
|
captcha = args.get("captcha", None)
|
||||||
if captcha:
|
if captcha:
|
||||||
answer = get_captcha_answer(get_captcha_token(captcha_salt))
|
answer = get_captcha_answer(get_captcha_token(captcha_salt))
|
||||||
if captcha != answer:
|
if captcha != answer:
|
||||||
return False, ["The entered CAPTCHA answer is invalid."]
|
return (False, ["The entered CAPTCHA answer is invalid."])
|
||||||
|
|
||||||
return True, []
|
return (True, [])
|
||||||
|
|
||||||
|
|
||||||
def make_account_form_context(context: dict,
|
def make_account_form_context(context: dict,
|
||||||
|
|
|
@ -44,7 +44,7 @@ class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
|
||||||
el = markdown.util.etree.Element('a')
|
el = markdown.util.etree.Element('a')
|
||||||
el.set('href', f'https://bugs.archlinux.org/task/{m.group(1)}')
|
el.set('href', f'https://bugs.archlinux.org/task/{m.group(1)}')
|
||||||
el.text = markdown.util.AtomicString(m.group(0))
|
el.text = markdown.util.AtomicString(m.group(0))
|
||||||
return el, m.start(0), m.end(0)
|
return (el, m.start(0), m.end(0))
|
||||||
|
|
||||||
|
|
||||||
class FlysprayLinksExtension(markdown.extensions.Extension):
|
class FlysprayLinksExtension(markdown.extensions.Extension):
|
||||||
|
@ -71,7 +71,7 @@ class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):
|
||||||
oid = m.group(1)
|
oid = m.group(1)
|
||||||
if oid not in self._repo:
|
if oid not in self._repo:
|
||||||
# Unkwown OID; preserve the orginal text.
|
# Unkwown OID; preserve the orginal text.
|
||||||
return None, None, None
|
return (None, None, None)
|
||||||
|
|
||||||
prefixlen = 12
|
prefixlen = 12
|
||||||
while prefixlen < 40:
|
while prefixlen < 40:
|
||||||
|
@ -82,7 +82,7 @@ class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):
|
||||||
el = markdown.util.etree.Element('a')
|
el = markdown.util.etree.Element('a')
|
||||||
el.set('href', commit_uri % (self._head, oid[:prefixlen]))
|
el.set('href', commit_uri % (self._head, oid[:prefixlen]))
|
||||||
el.text = markdown.util.AtomicString(oid[:prefixlen])
|
el.text = markdown.util.AtomicString(oid[:prefixlen])
|
||||||
return el, m.start(0), m.end(0)
|
return (el, m.start(0), m.end(0))
|
||||||
|
|
||||||
|
|
||||||
class GitCommitsExtension(markdown.extensions.Extension):
|
class GitCommitsExtension(markdown.extensions.Extension):
|
||||||
|
|
Loading…
Add table
Reference in a new issue