Browse Source

#327

feature/327
みてるぞ 2 days ago
parent
commit
c1af29617f
3 changed files with 2 additions and 15 deletions
  1. +0
    -13
      backend/app/controllers/users_controller.rb
  2. +1
    -1
      backend/app/models/ip_address.rb
  3. +1
    -1
      backend/app/models/user.rb

+ 0
- 13
backend/app/controllers/users_controller.rb View File

@@ -1,8 +1,5 @@
class UsersController < ApplicationController
def create
return head :unprocessable_entity if request.remote_ip.blank?
return head :forbidden if ip_address_banned?

user = nil
User.transaction do
user = User.create!(inheritance_code: SecureRandom.uuid, role: :guest)
@@ -15,9 +12,6 @@ class UsersController < ApplicationController
end

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])
return render json: { valid: false } unless user
return head :forbidden if user.banned?
@@ -65,11 +59,4 @@ class UsersController < ApplicationController

UserIp.create_or_find_by!(user:, ip_address:)
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

+ 1
- 1
backend/app/models/ip_address.rb View File

@@ -5,6 +5,6 @@ class IpAddress < ApplicationRecord
has_many :users, through: :user_ips

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)
end

+ 1
- 1
backend/app/models/user.rb View File

@@ -22,6 +22,6 @@ class User < ApplicationRecord
def gte_member? = member? || admin?

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)
end

Loading…
Cancel
Save