mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-28 23:48:31 +00:00
Extract logic for registration into #signups
This commit is contained in:
parent
d956b1826e
commit
72ec494f2b
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user