mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-29 07:58:35 +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
|
env.response.cookies << cookie
|
||||||
end
|
end
|
||||||
else
|
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
|
if !CONFIG.registration_enabled
|
||||||
return error_template(400, "Registration has been disabled by administrator.")
|
return error_template(400, "Registration has been disabled by administrator.")
|
||||||
end
|
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")
|
return error_template(401, "Password cannot be empty")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if email.nil? || email.empty?
|
||||||
|
return error_template(401, "User ID is a required field")
|
||||||
|
end
|
||||||
|
|
||||||
# See https://security.stackexchange.com/a/39851
|
# See https://security.stackexchange.com/a/39851
|
||||||
if password.bytesize > 55
|
if password.bytesize > 55
|
||||||
return error_template(400, "Password cannot be longer than 55 characters")
|
return error_template(400, "Password cannot be longer than 55 characters")
|
||||||
@ -125,7 +145,7 @@ module Invidious::Routes::Login
|
|||||||
return error_template(400, ex)
|
return error_template(400, ex)
|
||||||
end
|
end
|
||||||
else # "text"
|
else # "text"
|
||||||
answer = Digest::MD5.hexdigest(answer.downcase.strip)
|
answer = Digest::MD5.hexdigest(answer)
|
||||||
|
|
||||||
if tokens.empty?
|
if tokens.empty?
|
||||||
return error_template(500, "Erroneous CAPTCHA")
|
return error_template(500, "Erroneous CAPTCHA")
|
||||||
@ -175,12 +195,6 @@ module Invidious::Routes::Login
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
env.redirect referer
|
|
||||||
else
|
|
||||||
env.redirect referer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.signout(env)
|
def self.signout(env)
|
||||||
locale = env.get("preferences").as(Preferences).locale
|
locale = env.get("preferences").as(Preferences).locale
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user