This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user