Extract logic for registration into #signups

This commit is contained in:
syeopite 2023-07-26 07:39:50 -07:00
parent d956b1826e
commit 72ec494f2b
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A

View File

@ -72,14 +72,34 @@ module Invidious::Routes::Login
env.response.cookies << cookie
end
else
return self.signup(env)
end
env.redirect referer
else
env.redirect referer
end
end
def self.signup(env)
locale = env.get("preferences").as(Preferences).locale
referer = get_referer(env, "/feed/subscriptions")
if !CONFIG.registration_enabled
return error_template(400, "Registration has been disabled by administrator.")
end
if password.empty?
email = env.params.body["email"]?.try &.downcase.byte_slice(0, 254)
password = env.params.body["password"]?
if password.nil? || password.empty?
return error_template(401, "Password cannot be empty")
end
if email.nil? || email.empty?
return error_template(401, "User ID is a required field")
end
# See https://security.stackexchange.com/a/39851
if password.bytesize > 55
return error_template(400, "Password cannot be longer than 55 characters")
@ -125,7 +145,7 @@ module Invidious::Routes::Login
return error_template(400, ex)
end
else # "text"
answer = Digest::MD5.hexdigest(answer.downcase.strip)
answer = Digest::MD5.hexdigest(answer)
if tokens.empty?
return error_template(500, "Erroneous CAPTCHA")
@ -175,12 +195,6 @@ module Invidious::Routes::Login
end
end
env.redirect referer
else
env.redirect referer
end
end
def self.signout(env)
locale = env.get("preferences").as(Preferences).locale