diff --git a/Gemfile b/Gemfile index e0dda6e..d10698e 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,7 @@ gem 'mobility', '~> 1.1.1' # Omniauth Strategy for Battle.net OAuth Login. For more info visit https://dev.battle.net gem 'omniauth-bnet', '~> 2.0.0' # This gem provides a mitigation against CVE-2015-9284 -# gem 'omniauth-rails_csrf_protection', '~> 0.1.2' +gem 'omniauth-rails_csrf_protection', '~> 0.1.2' # A Ruby wrapper around Blizzard's Game Data and Profile APIs gem 'rbattlenet', '~> 2.2.4', git: 'https://github.com/Dainii/rbattlenet' # A gem that provides Rails integration for the Sentry error logger diff --git a/Gemfile.lock b/Gemfile.lock index 6bba82f..72c1b13 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -179,6 +179,9 @@ GEM omniauth-oauth2 (1.7.1) oauth2 (~> 1.4) omniauth (>= 1.9, < 3) + omniauth-rails_csrf_protection (0.1.2) + actionpack (>= 4.2) + omniauth (>= 1.3.1) orm_adapter (0.5.0) parallel (1.20.1) parser (3.0.1.0) @@ -390,6 +393,7 @@ DEPENDENCIES lograge (~> 0.11.2) mobility (~> 1.1.1) omniauth-bnet (~> 2.0.0) + omniauth-rails_csrf_protection (~> 0.1.2) pg (~> 1.1) pry-rails (~> 0.3.9) puma (~> 5.0) diff --git a/app/assets/stylesheets/wow_mounts.scss b/app/assets/stylesheets/wow_mounts.scss new file mode 100644 index 0000000..440adcd --- /dev/null +++ b/app/assets/stylesheets/wow_mounts.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the wow_mounts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/assets/stylesheets/wow_pets.scss b/app/assets/stylesheets/wow_pets.scss new file mode 100644 index 0000000..b3d9dd5 --- /dev/null +++ b/app/assets/stylesheets/wow_pets.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the wow_pets controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b1a8eaf..94182c4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base around_action :switch_locale def switch_locale(&action) - locale = I18n.default_locale + locale = I18n.locale_available?(request.headers['Locale']) ? request.headers['Locale'] : I18n.default_locale I18n.with_locale(locale, &action) end diff --git a/app/controllers/protected_controller.rb b/app/controllers/protected_controller.rb index cf05fab..1222316 100644 --- a/app/controllers/protected_controller.rb +++ b/app/controllers/protected_controller.rb @@ -1,3 +1,3 @@ class ProtectedController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_user! end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 22c69ce..1987428 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -11,6 +11,9 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController if @user.persisted? sign_in_and_redirect @user, event: :authentication + WowCharactersWorker.perform_async(@user.id) + WowMountsCollectionWorker.perform_async(@user.id) + WowPetsCollectionWorker.perform_async(@user.id) set_flash_message(:notice, :success, kind: 'Bnet') if is_navigational_format? else session['devise.bnet_data'] = request.env['omniauth.auth'].except(:extra) diff --git a/app/controllers/wow_characters_controller.rb b/app/controllers/wow_characters_controller.rb index 6817ab0..056b5b8 100644 --- a/app/controllers/wow_characters_controller.rb +++ b/app/controllers/wow_characters_controller.rb @@ -1,5 +1,9 @@ class WowCharactersController < ProtectedController def index - @characters = current_user.wow_characters.all + @wow_characters = current_user.wow_characters.all + end + + def show + @wow_character = current_user.wow_characters.find(params[:id]) end end diff --git a/app/controllers/wow_mounts_controller.rb b/app/controllers/wow_mounts_controller.rb new file mode 100644 index 0000000..db48eef --- /dev/null +++ b/app/controllers/wow_mounts_controller.rb @@ -0,0 +1,9 @@ +class WowMountsController < ProtectedController + def index + @wow_mounts = WowMount.all + end + + def show + @wow_mount = WowMount.find(params[:id]) + end +end diff --git a/app/controllers/wow_pets_controller.rb b/app/controllers/wow_pets_controller.rb new file mode 100644 index 0000000..d587274 --- /dev/null +++ b/app/controllers/wow_pets_controller.rb @@ -0,0 +1,9 @@ +class WowPetsController < ProtectedController + def index + @wow_pets = WowPet.all + end + + def show + @wow_pet = WowPet.find(params[:id]) + end +end diff --git a/app/helpers/wow_mounts_helper.rb b/app/helpers/wow_mounts_helper.rb new file mode 100644 index 0000000..7e20ab6 --- /dev/null +++ b/app/helpers/wow_mounts_helper.rb @@ -0,0 +1,2 @@ +module WowMountsHelper +end diff --git a/app/helpers/wow_pets_helper.rb b/app/helpers/wow_pets_helper.rb new file mode 100644 index 0000000..5fe264a --- /dev/null +++ b/app/helpers/wow_pets_helper.rb @@ -0,0 +1,2 @@ +module WowPetsHelper +end diff --git a/app/models/learned_wow_pet_ability.rb b/app/models/learned_wow_pet_ability.rb new file mode 100644 index 0000000..cf9bc33 --- /dev/null +++ b/app/models/learned_wow_pet_ability.rb @@ -0,0 +1,4 @@ +class LearnedWowPetAbility < ApplicationRecord + belongs_to :wow_pet + belongs_to :wow_pet_ability +end diff --git a/app/models/user.rb b/app/models/user.rb index ceab2a6..32eb1ad 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,6 +8,10 @@ class User < ApplicationRecord devise :rememberable, :omniauthable, omniauth_providers: [:bnet] has_many :wow_characters, dependent: :destroy + has_many :user_obtain_wow_mounts, dependent: :destroy + has_many :wow_mounts, through: :user_obtain_wow_mounts + has_many :user_obtain_wow_pets, dependent: :destroy + has_many :wow_pets, through: :user_obtain_wow_pets validates :battletag, presence: true, uniqueness: true @@ -28,8 +32,8 @@ class User < ApplicationRecord def self.new_with_session(params, session) super.tap do |user| - if (data = session['devise.bnet_data']) && session['devise.bnet_data']['extra']['raw_info'] - user.email = data['email'] if user.email.blank? + if (data = session['devise.bnet_data']) && session['devise.bnet_data']['extra']['raw_info'] && user.email.blank? + user.email = data['email'] end end end diff --git a/app/models/user_obtain_wow_mount.rb b/app/models/user_obtain_wow_mount.rb new file mode 100644 index 0000000..7702db6 --- /dev/null +++ b/app/models/user_obtain_wow_mount.rb @@ -0,0 +1,4 @@ +class UserObtainWowMount < ApplicationRecord + belongs_to :user + belongs_to :wow_mount +end diff --git a/app/models/user_obtain_wow_pet.rb b/app/models/user_obtain_wow_pet.rb new file mode 100644 index 0000000..906d8ad --- /dev/null +++ b/app/models/user_obtain_wow_pet.rb @@ -0,0 +1,4 @@ +class UserObtainWowPet < ApplicationRecord + belongs_to :user + belongs_to :wow_pet +end diff --git a/app/models/wow_character.rb b/app/models/wow_character.rb index ce4973d..57aa821 100644 --- a/app/models/wow_character.rb +++ b/app/models/wow_character.rb @@ -11,4 +11,35 @@ class WowCharacter < ApplicationRecord validates :name, presence: true validates :character_id, presence: true, uniqueness: true + + def gender_class_name + case gender + when 'FEMALE' + wow_class.female_name + when 'MALE' + wow_class.male_name + end + end + + def gender_race_name + case gender + when 'FEMALE' + wow_race.female_name + when 'MALE' + wow_race.male_name + end + end + + def title_name + if wow_character_title + case gender + when 'FEMALE' + wow_character_title.female_name.gsub('{name}', name) + when 'MALE' + wow_character_title.male_name.gsub('{name}', name) + end + else + name + end + end end diff --git a/app/models/wow_mount.rb b/app/models/wow_mount.rb new file mode 100644 index 0000000..f0ef4af --- /dev/null +++ b/app/models/wow_mount.rb @@ -0,0 +1,10 @@ +class WowMount < ApplicationRecord + extend Mobility + translates :name, :description, :translated_faction, :translated_source + + has_many :user_obtain_mounts, dependent: :destroy + has_many :users, through: :user_obtain_mounts + + validates :name, presence: true + validates :mount_id, presence: true, uniqueness: true +end diff --git a/app/models/wow_pet.rb b/app/models/wow_pet.rb new file mode 100644 index 0000000..f50d92b --- /dev/null +++ b/app/models/wow_pet.rb @@ -0,0 +1,10 @@ +class WowPet < ApplicationRecord + extend Mobility + translates :name, :translated_battle_pet_type, :description, :translated_source_type + + has_many :learned_wow_pet_abilities, dependent: :destroy + has_many :wow_pet_abilities, through: :learned_wow_pet_abilities + + validates :name, presence: true + validates :pet_id, presence: true, uniqueness: true +end diff --git a/app/models/wow_pet_ability.rb b/app/models/wow_pet_ability.rb new file mode 100644 index 0000000..de546c8 --- /dev/null +++ b/app/models/wow_pet_ability.rb @@ -0,0 +1,10 @@ +class WowPetAbility < ApplicationRecord + extend Mobility + translates :name, :translated_battle_pet_type + + has_many :learned_pet_abilities, dependent: :destroy + has_many :wow_pets, through: :learned_pet_abilities + + validates :name, presence: true + validates :ability_id, presence: true, uniqueness: true +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 2085730..750f390 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,2 +1,5 @@ -
Find me in app/views/home/index.html.erb
+<% if user_signed_in? %> +