Websites/app/controllers/yiff_rest/api_v2/application_controller.rb

25 lines
838 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module YiffRest
module APIV2
class ApplicationController < ::YiffRest::ApplicationController
protected
def site_domain
YiffRestRoutes::V2_DOMAIN
end
def validate_discord
redirect_to(Websites.config.yiffyapi_discord_redirect("manage_images"), allow_other_host: true) if session[:discord_user].blank?
end
def prepare_user
name = session.dig("discord_user", "global_name") || "#{session.dig('discord_user', 'username')}#{@session.dig('discord_user', 'discriminator')}"
CurrentUser.user = APIUser.find_or_create_by(id: session.dig("discord_user", "id"))
CurrentUser.update!(name: name, discord_data: session["discord_user"])
CurrentUser.update_avatar(session.dig("discord_user", "avatar"))
end
end
end
end