diff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.cr index 6eaf3071..1a243408 100644 --- a/src/invidious/routes/login.cr +++ b/src/invidious/routes/login.cr @@ -14,22 +14,9 @@ module Invidious::Routes::Login return error_template(400, "Login has been disabled by administrator.") end - email = nil - password = nil - captcha = nil - - account_type = env.params.query["type"]? - account_type ||= "invidious" - - captcha_type = env.params.query["captcha"]? - captcha_type ||= "image" - templated "user/login" end - def self.signup_page(env) - end - def self.login(env) locale = env.get("preferences").as(Preferences).locale @@ -84,6 +71,32 @@ module Invidious::Routes::Login end end + def self.signup_page(env) + locale = env.get("preferences").as(Preferences).locale + + user = env.get? "user" + + referer = get_referer(env, "/feed/subscriptions") + + return env.redirect referer if user + + if !CONFIG.registration_enabled + return error_template(400, "Registration has been disabled by administrator.") + end + + email = nil + password = nil + captcha = nil + + account_type = env.params.query["type"]? + account_type ||= "invidious" + + captcha_type = env.params.query["captcha"]? + captcha_type ||= "image" + + templated "user/register" + end + def self.signup(env) locale = env.get("preferences").as(Preferences).locale referer = get_referer(env, "/feed/subscriptions") @@ -95,14 +108,14 @@ module Invidious::Routes::Login 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 + if password.nil? || password.empty? + return error_template(401, "Password cannot be empty") + end + # See https://security.stackexchange.com/a/39851 if password.bytesize > 55 return error_template(400, "Password cannot be longer than 55 characters") @@ -129,14 +142,13 @@ module Invidious::Routes::Login captcha = Invidious::User::Captcha.generate_text(HMAC_KEY) end - return templated "user/login" + return templated "user/register" end tokens = env.params.body.select { |k, _| k.match(/^token\[\d+\]$/) }.map { |_, v| v } answer ||= "" captcha_type ||= "image" - case captcha_type when "image" answer = answer.lstrip('0') diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr index 9ba67411..2aca8c78 100644 --- a/src/invidious/routing.cr +++ b/src/invidious/routing.cr @@ -55,8 +55,11 @@ module Invidious::Routing def register_user_routes # User login/out get "/login", Routes::Login, :login_page - get "/signup", Routes::Login, :signup_page post "/login", Routes::Login, :login + + get "/signup", Routes::Login, :signup_page + post "/signup", Routes::Login, :signup + post "/signout", Routes::Login, :signout # User preferences diff --git a/src/invidious/views/user/login.ecr b/src/invidious/views/user/login.ecr index 078eaa5c..79c4a16b 100644 --- a/src/invidious/views/user/login.ecr +++ b/src/invidious/views/user/login.ecr @@ -7,75 +7,23 @@
- <% case account_type when %> - <% else # "invidious" %> -
-
- <% if email %> - - <% else %> - - "> - <% end %> + +
+ + "> - <% if password %> - - <% else %> - - "> - <% end %> + + "> - <% if captcha %> - <% case captcha_type when %> - <% when "image" %> - <% captcha = captcha.not_nil! %> - - <% captcha[:tokens].each_with_index do |token, i| %> - - <% end %> - - - - <% else # "text" %> - <% captcha = captcha.not_nil! %> - <% captcha[:tokens].each_with_index do |token, i| %> - - <% end %> - - - "> - <% end %> +
- - <% end %> + +
+ +
diff --git a/src/invidious/views/user/register.ecr b/src/invidious/views/user/register.ecr new file mode 100644 index 00000000..61179369 --- /dev/null +++ b/src/invidious/views/user/register.ecr @@ -0,0 +1,77 @@ +<% content_for "header" do %> +<%= translate(locale, "sign_up_page_title") %> - Invidious + +<% end %> + +
+
+
+
+
+
+ <% if email %> + + <% else %> + + "> + <% end %> + + <% if password %> + + <% else %> + + "> + <% end %> + + <% if captcha %> + <% case captcha_type when %> + <% when "image" %> + <% captcha = captcha.not_nil! %> + + <% captcha[:tokens].each_with_index do |token, i| %> + + <% end %> + + + + <% else # "text" %> + <% captcha = captcha.not_nil! %> + <% captcha[:tokens].each_with_index do |token, i| %> + + <% end %> + + + "> + <% end %> + + + + <% case captcha_type when %> + <% when "image" %> + + <% else # "text" %> + + <% end %> + <% else %> + + <% end %> +
+
+
+
+
+