FIX: save registration IP address for invited users
This commit is contained in:
parent
b71f19d394
commit
95ada3f190
|
@ -45,7 +45,7 @@ class InvitesController < ApplicationController
|
||||||
|
|
||||||
if invite.present?
|
if invite.present?
|
||||||
begin
|
begin
|
||||||
user = invite.redeem(username: params[:username], name: params[:name], password: params[:password], user_custom_fields: params[:user_custom_fields])
|
user = invite.redeem(username: params[:username], name: params[:name], password: params[:password], user_custom_fields: params[:user_custom_fields], ip_address: request.remote_ip)
|
||||||
if user.present?
|
if user.present?
|
||||||
log_on_user(user) if user.active?
|
log_on_user(user) if user.active?
|
||||||
post_process_invite(user)
|
post_process_invite(user)
|
||||||
|
|
|
@ -53,8 +53,8 @@ class Invite < ActiveRecord::Base
|
||||||
invalidated_at.nil?
|
invalidated_at.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def redeem(username: nil, name: nil, password: nil, user_custom_fields: nil)
|
def redeem(username: nil, name: nil, password: nil, user_custom_fields: nil, ip_address: nil)
|
||||||
InviteRedeemer.new(self, username, name, password, user_custom_fields).redeem unless expired? || destroyed? || !link_valid?
|
InviteRedeemer.new(self, username, name, password, user_custom_fields, ip_address).redeem unless expired? || destroyed? || !link_valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.invite_by_email(email, invited_by, topic = nil, group_ids = nil, custom_message = nil)
|
def self.invite_by_email(email, invited_by, topic = nil, group_ids = nil, custom_message = nil)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_fields) do
|
InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_fields, :ip_address) do
|
||||||
|
|
||||||
def redeem
|
def redeem
|
||||||
Invite.transaction do
|
Invite.transaction do
|
||||||
|
@ -12,7 +12,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f
|
||||||
end
|
end
|
||||||
|
|
||||||
# extracted from User cause it is very specific to invites
|
# extracted from User cause it is very specific to invites
|
||||||
def self.create_user_from_invite(invite, username, name, password = nil, user_custom_fields = nil)
|
def self.create_user_from_invite(invite, username, name, password = nil, user_custom_fields = nil, ip_address = nil)
|
||||||
if username && UsernameValidator.new(username).valid_format? && User.username_available?(username)
|
if username && UsernameValidator.new(username).valid_format? && User.username_available?(username)
|
||||||
available_username = username
|
available_username = username
|
||||||
else
|
else
|
||||||
|
@ -25,7 +25,9 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f
|
||||||
username: available_username,
|
username: available_username,
|
||||||
name: available_name,
|
name: available_name,
|
||||||
active: false,
|
active: false,
|
||||||
trust_level: SiteSetting.default_invitee_trust_level
|
trust_level: SiteSetting.default_invitee_trust_level,
|
||||||
|
ip_address: ip_address,
|
||||||
|
registration_ip_address: ip_address
|
||||||
}
|
}
|
||||||
|
|
||||||
user = User.unstage(user_params)
|
user = User.unstage(user_params)
|
||||||
|
@ -92,7 +94,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f
|
||||||
|
|
||||||
def get_invited_user
|
def get_invited_user
|
||||||
result = get_existing_user
|
result = get_existing_user
|
||||||
result ||= InviteRedeemer.create_user_from_invite(invite, username, name, password, user_custom_fields)
|
result ||= InviteRedeemer.create_user_from_invite(invite, username, name, password, user_custom_fields, ip_address)
|
||||||
result.send_welcome_message = false
|
result.send_welcome_message = false
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,12 +12,15 @@ describe InviteRedeemer do
|
||||||
expect(user.approved).to eq(true)
|
expect(user.approved).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can set the password too" do
|
it "can set the password and ip_address" do
|
||||||
password = 's3cure5tpasSw0rD'
|
password = 's3cure5tpasSw0rD'
|
||||||
user = InviteRedeemer.create_user_from_invite(Fabricate(:invite, email: 'walter.white@email.com'), 'walter', 'Walter White', password)
|
ip_address = '192.168.1.1'
|
||||||
|
user = InviteRedeemer.create_user_from_invite(Fabricate(:invite, email: 'walter.white@email.com'), 'walter', 'Walter White', password, nil, ip_address)
|
||||||
expect(user).to have_password
|
expect(user).to have_password
|
||||||
expect(user.confirm_password?(password)).to eq(true)
|
expect(user.confirm_password?(password)).to eq(true)
|
||||||
expect(user.approved).to eq(true)
|
expect(user.approved).to eq(true)
|
||||||
|
expect(user.ip_address).to eq(ip_address)
|
||||||
|
expect(user.registration_ip_address).to eq(ip_address)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises exception with record and errors" do
|
it "raises exception with record and errors" do
|
||||||
|
|
|
@ -276,6 +276,9 @@ describe InvitesController do
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(session[:current_user_id]).to eq(invite.user_id)
|
expect(session[:current_user_id]).to eq(invite.user_id)
|
||||||
expect(invite.redeemed?).to be_truthy
|
expect(invite.redeemed?).to be_truthy
|
||||||
|
user = User.find(invite.user_id)
|
||||||
|
expect(user.ip_address).to be_present
|
||||||
|
expect(user.registration_ip_address).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to the first topic the user was invited to' do
|
it 'redirects to the first topic the user was invited to' do
|
||||||
|
|
Loading…
Reference in New Issue