mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-28 15:38:30 +00:00
Update authentication.cr
This commit is contained in:
parent
ae058da25c
commit
6014ee9cc1
@ -35,16 +35,45 @@ module Invidious::Routes::API::V1::Authentication
|
|||||||
password = password.byte_slice(0, 55)
|
password = password.byte_slice(0, 55)
|
||||||
# send captcha if enabled
|
# send captcha if enabled
|
||||||
if CONFIG.captcha_enabled
|
if CONFIG.captcha_enabled
|
||||||
# send captcha
|
captcha_response = nil
|
||||||
captcha = Invidious::User::Captcha.generate_text(HMAC_KEY, ":captcha")
|
begin
|
||||||
# puts captcha
|
captcha_response = CaptchaResponse.from_json(env.request.body || "{}")
|
||||||
response = JSON.build do |json|
|
rescue
|
||||||
json.object do
|
end
|
||||||
json.field "question", captcha["question"]
|
if captcha_response
|
||||||
json.field "tokens", captcha["tokens"]
|
answer = captcha_response.answer
|
||||||
end
|
tokens = captcha_response.tokens
|
||||||
|
answer = Digest::MD5.hexdigest(answer.downcase.strip)
|
||||||
|
if tokens.empty?
|
||||||
|
return error_json(500, "Erroneous CAPTCHA")
|
||||||
|
end
|
||||||
|
|
||||||
|
found_valid_captcha = false
|
||||||
|
error_exception = Exception.new
|
||||||
|
tokens.each do |tok|
|
||||||
|
begin
|
||||||
|
validate_request(tok, answer, env.request, HMAC_KEY, locale)
|
||||||
|
found_valid_captcha = true
|
||||||
|
rescue ex
|
||||||
|
error_exception = ex
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if !found_valid_captcha
|
||||||
|
return error_json(500, error_exception)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# send captcha
|
||||||
|
captcha = Invidious::User::Captcha.generate_text(HMAC_KEY, ":captcha")
|
||||||
|
# puts captcha
|
||||||
|
response = JSON.build do |json|
|
||||||
|
json.object do
|
||||||
|
json.field "question", captcha["question"]
|
||||||
|
json.field "tokens", captcha["tokens"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return response
|
||||||
end
|
end
|
||||||
return response
|
|
||||||
end
|
end
|
||||||
# create user
|
# create user
|
||||||
sid = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
sid = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
||||||
|
Loading…
Reference in New Issue
Block a user