This commit is contained in:
2026-05-04 15:42:17 +09:00
parent 7ab877d6bd
commit c1af29617f
3 changed files with 2 additions and 15 deletions
@@ -1,8 +1,5 @@
class UsersController < ApplicationController class UsersController < ApplicationController
def create def create
return head :unprocessable_entity if request.remote_ip.blank?
return head :forbidden if ip_address_banned?
user = nil user = nil
User.transaction do User.transaction do
user = User.create!(inheritance_code: SecureRandom.uuid, role: :guest) user = User.create!(inheritance_code: SecureRandom.uuid, role: :guest)
@@ -15,9 +12,6 @@ class UsersController < ApplicationController
end end
def verify def verify
return head :unprocessable_entity if request.remote_ip.blank?
return head :forbidden if ip_address_banned?
user = User.find_by(inheritance_code: params[:code]) user = User.find_by(inheritance_code: params[:code])
return render json: { valid: false } unless user return render json: { valid: false } unless user
return head :forbidden if user.banned? return head :forbidden if user.banned?
@@ -65,11 +59,4 @@ class UsersController < ApplicationController
UserIp.create_or_find_by!(user:, ip_address:) UserIp.create_or_find_by!(user:, ip_address:)
end end
def ip_address_banned?
ip_address = IpAddress.find_by(ip_address: IPAddr.new(request.remote_ip).hton)
return false unless ip_address
ip_address.banned?
end
end end
+1 -1
View File
@@ -5,6 +5,6 @@ class IpAddress < ApplicationRecord
has_many :users, through: :user_ips has_many :users, through: :user_ips
def banned? = banned_at.present? def banned? = banned_at.present?
def ban! = banned? or update!(banned_at: Time.current) def ban! = banned? || update!(banned_at: Time.current)
def unban! = update!(banned_at: nil) def unban! = update!(banned_at: nil)
end end
+1 -1
View File
@@ -22,6 +22,6 @@ class User < ApplicationRecord
def gte_member? = member? || admin? def gte_member? = member? || admin?
def banned? = banned_at.present? def banned? = banned_at.present?
def ban! = banned? or update!(banned_at: Time.current) def ban! = banned? || update!(banned_at: Time.current)
def unban! = update!(banned_at: nil) def unban! = update!(banned_at: nil)
end end