better error handling of failed deviant art logins

This commit is contained in:
r888888888
2017-08-28 16:19:41 -07:00
parent 840cdc817d
commit bc69badadd
3 changed files with 27 additions and 19 deletions

View File

@@ -120,21 +120,23 @@ module Sources
mech = Mechanize.new mech = Mechanize.new
auth, userinfo = session_cookies(mech) auth, userinfo = session_cookies(mech)
# This cookie needs to be set to allow viewing of mature works if auth
cookie = Mechanize::Cookie.new("agegate_state", "1") # This cookie needs to be set to allow viewing of mature works
cookie.domain = ".deviantart.com" cookie = Mechanize::Cookie.new("agegate_state", "1")
cookie.path = "/" cookie.domain = ".deviantart.com"
mech.cookie_jar.add(cookie) cookie.path = "/"
mech.cookie_jar.add(cookie)
cookie = Mechanize::Cookie.new("auth", auth) cookie = Mechanize::Cookie.new("auth", auth)
cookie.domain = ".deviantart.com" cookie.domain = ".deviantart.com"
cookie.path = "/" cookie.path = "/"
mech.cookie_jar.add(cookie) mech.cookie_jar.add(cookie)
cookie = Mechanize::Cookie.new("userinfo", userinfo) cookie = Mechanize::Cookie.new("userinfo", userinfo)
cookie.domain = ".deviantart.com" cookie.domain = ".deviantart.com"
cookie.path = "/" cookie.path = "/"
mech.cookie_jar.add(cookie) mech.cookie_jar.add(cookie)
end
mech mech
end end
@@ -145,6 +147,12 @@ module Sources
mech.request_headers = Danbooru.config.http_headers mech.request_headers = Danbooru.config.http_headers
page = mech.get("https://www.deviantart.com/users/login") page = mech.get("https://www.deviantart.com/users/login")
if page.search('div[class="g-recaptcha"]').any?
# we got captcha'd, have to abort
return nil
end
validate_key = page.search('input[name="validate_key"]').attribute("value").value validate_key = page.search('input[name="validate_key"]').attribute("value").value
validate_token = page.search('input[name="validate_token"]').attribute("value").value validate_token = page.search('input[name="validate_token"]').attribute("value").value
@@ -156,8 +164,8 @@ module Sources
remember_me: 1, remember_me: 1,
}) })
auth = mech.cookies.find { |cookie| cookie.name == "auth" }.value auth = mech.cookies.find { |cookie| cookie.name == "auth" }.try(:value)
userinfo = mech.cookies.find { |cookie| cookie.name == "userinfo" }.value userinfo = mech.cookies.find { |cookie| cookie.name == "userinfo" }.try(:value)
mech.cookie_jar.clear mech.cookie_jar.clear
[auth, userinfo] [auth, userinfo]

View File

@@ -1367,7 +1367,7 @@ class Post < ApplicationRecord
transaction do transaction do
Post.without_timeout do Post.without_timeout do
ModAction.log("permanently deleted post ##{id}") ModAction.log("permanently deleted post ##{id}")
delete!("Permanently deleted post ##{id}", :without_mod_action => true) #delete!("Permanently deleted post ##{id}", :without_mod_action => true)
give_favorites_to_parent give_favorites_to_parent
update_children_on_destroy update_children_on_destroy

View File

@@ -9,11 +9,11 @@ module Sources
end end
should "get the image url" do should "get the image url" do
assert_equal("http://orig02.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png", @site.image_url) assert_equal("https://orig02.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png", @site.image_url)
end end
should "get the profile" do should "get the profile" do
assert_equal("http://noizave.deviantart.com/", @site.profile_url) assert_equal("https://noizave.deviantart.com/", @site.profile_url)
end end
should "get the artist name" do should "get the artist name" do
@@ -26,7 +26,7 @@ module Sources
should "get the artist commentary" do should "get the artist commentary" do
title = "test post please ignore" title = "test post please ignore"
desc = "<div align=\"center\"><span>blah blah<br><div align=\"left\">\n<a class=\"external\" href=\"http://www.deviantart.com/users/outgoing?http://www.google.com\">test link</a><br>\n</div></span></div>\n<br><h1>lol</h1>\n<br><br><b>blah</b> <i>blah</i> <u>blah</u> <strike>blah</strike><br>herp derp<br><br><blockquote>this is a quote</blockquote>\n<ol>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ol>\n<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n<img src=\"http://e.deviantart.net/emoticons/h/heart.gif\" alt=\"Heart\" style=\"width: 15px; height: 13px;\" data-embed-type=\"emoticon\" data-embed-id=\"357\">  " desc = "<div align=\"center\"><span>blah blah<br><div align=\"left\">\n<a class=\"external\" href=\"http://www.deviantart.com/users/outgoing?http://www.google.com\">test link</a><br>\n</div></span></div>\n<br><h1>lol</h1>\n<br><br><b>blah</b> <i>blah</i> <u>blah</u> <strike>blah</strike><br>herp derp<br><br><blockquote>this is a quote</blockquote>\n<ol>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ol>\n<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n<img src=\"https://e.deviantart.net/emoticons/h/heart.gif\" alt=\"Heart\" style=\"width: 15px; height: 13px;\" data-embed-type=\"emoticon\" data-embed-id=\"357\">  "
assert_equal(title, @site.artist_commentary_title) assert_equal(title, @site.artist_commentary_title)
assert_equal(desc, @site.artist_commentary_desc) assert_equal(desc, @site.artist_commentary_desc)