ip bans: add hit counter, deleted flag, new ban type.

* Make IP bans soft deletable.
* Add a hit counter to track how many times an IP ban has blocked someone.
* Add a last hit timestamp to track when the IP ban last blocked someone.
* Add a new type of IP ban, the signup ban. Signup bans restrict new
  signups from editing anything until they've verified their email
  address.
This commit is contained in:
evazion
2020-04-06 14:12:56 -05:00
parent 98e84d83fb
commit b2ee1f0766
18 changed files with 178 additions and 40 deletions

View File

@@ -163,7 +163,7 @@ class ApplicationController < ActionController::Base
end
def ip_ban_check
raise User::PrivilegeError if !request.get? && IpBan.is_banned?(CurrentUser.ip_addr)
raise User::PrivilegeError if !request.get? && IpBan.hit!(:normal, CurrentUser.ip_addr)
end
def pundit_user

View File

@@ -19,9 +19,10 @@ class IpBansController < ApplicationController
respond_with(@ip_bans)
end
def destroy
def update
@ip_ban = authorize IpBan.find(params[:id])
@ip_ban.destroy
@ip_ban.update(permitted_attributes(@ip_ban))
respond_with(@ip_ban)
end
end

View File

@@ -59,9 +59,11 @@ class UsersController < ApplicationController
end
def create
requires_verification = IpLookup.new(CurrentUser.ip_addr).is_proxy? || IpBan.hit!(:signup, CurrentUser.ip_addr)
@user = authorize User.new(
last_ip_addr: CurrentUser.ip_addr,
requires_verification: IpLookup.new(CurrentUser.ip_addr).is_proxy?,
requires_verification: requires_verification,
name: params[:user][:name],
password: params[:user][:password],
password_confirmation: params[:user][:password_confirmation]