feat: ユーザに IP アドレスを紐づけ(#29) (#165)
#29 対応完了 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #165
This commit was merged in pull request #165.
This commit is contained in:
@@ -6,12 +6,15 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def verify
|
||||
ip_bin = IPAddr.new(request.remote_ip).hton
|
||||
ip_address = IpAddress.find_or_create_by!(ip_address: ip_bin)
|
||||
|
||||
user = User.find_by(inheritance_code: params[:code])
|
||||
render json: if user
|
||||
{ valid: true, user: user.slice(:id, :name, :inheritance_code, :role) }
|
||||
else
|
||||
{ valid: false }
|
||||
end
|
||||
return render json: { valid: false } unless user
|
||||
|
||||
UserIp.find_or_create_by!(user:, ip_address:)
|
||||
|
||||
render json: { valid: true, user: user.slice(:id, :name, :inheritance_code, :role) }
|
||||
end
|
||||
|
||||
def renew
|
||||
|
||||
@@ -8,7 +8,6 @@ class User < ApplicationRecord
|
||||
|
||||
has_many :posts
|
||||
has_many :settings
|
||||
has_many :ip_addresses
|
||||
has_many :user_ips, dependent: :destroy
|
||||
has_many :ip_addresses, through: :user_ips
|
||||
has_many :user_post_views, dependent: :destroy
|
||||
|
||||
Reference in New Issue
Block a user