fixes #2557
This commit is contained in:
@@ -4,7 +4,7 @@ class SessionsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
session_creator = SessionCreator.new(session, cookies, params[:name], params[:password], params[:remember], request.ssl?)
|
||||
session_creator = SessionCreator.new(session, cookies, params[:name], params[:password], request.remote_ip, params[:remember], request.ssl?)
|
||||
|
||||
if session_creator.authenticate
|
||||
url = params[:url] if params[:url] && params[:url].start_with?("/")
|
||||
|
||||
@@ -27,6 +27,7 @@ module Moderator
|
||||
def search_by_ip_addr(ip_addrs)
|
||||
sums = Hash.new {|h, k| h[k] = 0}
|
||||
|
||||
add_row(sums, "select id as k, 1 as count from users where last_ip_addr in (?)", ip_addrs)
|
||||
add_row(sums, "select creator_id as k, count(*) from comments where ip_addr in (?) group by k", ip_addrs)
|
||||
add_row(sums, "select updater_id as k, count(*) from post_versions where updater_ip_addr in (?) group by k", ip_addrs)
|
||||
add_row(sums, "select updater_id as k, count(*) from note_versions where updater_ip_addr in (?) group by k", ip_addrs)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
class SessionCreator
|
||||
attr_reader :session, :cookies, :name, :password, :remember, :secure
|
||||
attr_reader :session, :cookies, :name, :password, :ip_addr, :remember, :secure
|
||||
|
||||
def initialize(session, cookies, name, password, remember = false, secure = false)
|
||||
def initialize(session, cookies, name, password, ip_addr, remember = false, secure = false)
|
||||
@session = session
|
||||
@cookies = cookies
|
||||
@name = name
|
||||
@password = password
|
||||
@ip_addr = ip_addr
|
||||
@remember = remember
|
||||
@secure = secure
|
||||
end
|
||||
@@ -27,6 +28,7 @@ class SessionCreator
|
||||
end
|
||||
|
||||
session[:user_id] = user.id
|
||||
user.update_column(:last_ip_addr, ip_addr)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
|
||||
6
db/migrate/20151217213321_add_last_ip_addr_to_users.rb
Normal file
6
db/migrate/20151217213321_add_last_ip_addr_to_users.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddLastIpAddrToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :last_ip_addr, :inet
|
||||
add_index :users, :last_ip_addr, where: "last_ip_addr is not null"
|
||||
end
|
||||
end
|
||||
@@ -3175,7 +3175,8 @@ furry -rating:s'::text,
|
||||
bcrypt_password_hash text,
|
||||
per_page integer DEFAULT 20 NOT NULL,
|
||||
custom_style text,
|
||||
bit_prefs bigint DEFAULT 0 NOT NULL
|
||||
bit_prefs bigint DEFAULT 0 NOT NULL,
|
||||
last_ip_addr inet
|
||||
);
|
||||
|
||||
|
||||
@@ -7276,3 +7277,5 @@ INSERT INTO schema_migrations (version) VALUES ('20150728170433');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20150805010245');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20151217213321');
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
should "create a new session" do
|
||||
post :create, {:name => @user.name, :password => "password"}
|
||||
assert_redirected_to posts_path
|
||||
@user.reload
|
||||
assert_equal(@user.id, session[:user_id])
|
||||
assert_not_nil(@user.last_ip_addr)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user