Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ gem 'jbuilder', '~> 2.5'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
# Faker is used to easily generate fake data: names, addresses, phone numbers, etc.
gem 'faker'

# Client library for Amazon's Simple Email Service's REST API
gem 'fast_jsonapi', '~> 1.1', '>= 1.1.1'

# Random name generator
gem 'random_name_generator'

# Pagination library for Rails, Sinatra, Merb, DataMapper, and more
gem 'will_paginate', '~> 3.1.0'

Expand Down
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ GEM
crass (1.0.6)
erubi (1.10.0)
execjs (2.7.0)
faker (2.15.1)
i18n (>= 1.6, < 2)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ffi (1.13.1)
Expand Down Expand Up @@ -118,7 +120,6 @@ GEM
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (13.0.1)
random_name_generator (1.2.1)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
Expand Down Expand Up @@ -190,13 +191,13 @@ PLATFORMS
DEPENDENCIES
bootsnap (>= 1.1.0)
byebug
faker
fast_jsonapi (~> 1.1, >= 1.1.1)
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
pg (>= 0.18, < 2.0)
puma (~> 3.11)
rails (~> 5.2.4, >= 5.2.4.4)
random_name_generator
redis (~> 3.3, >= 3.3.1)
rubocop
sass-rails (~> 5.0)
Expand Down
18 changes: 8 additions & 10 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'random_name_generator'

module Api
module V1
class UsersController < ApplicationController
Expand Down Expand Up @@ -37,31 +35,31 @@ def user_params
end

def authenticate!
current_user = User.find_by(ip_address: ip_addr, device: device_name)
current_user = User.find_by(ip_address: get_ip_address, device: get_device_name)

if current_user.present?
current_user.refresh_activity
else
current_user = User.create(name: user_name, device: device_name, ip_address: ip_addr)
current_user = User.create(name: get_user_name, device: get_device_name, ip_address: get_ip_address)
end
session['user_id'] = current_user.id
end

def device_name
def get_user_name
Faker::Movies::LordOfTheRings.character
end

def get_device_name
agent = request.user_agent
return 'tablet' if agent =~ /(tablet|ipad)|(android(?!.*mobile))/i
return 'mobile' if agent =~ /Mobile/
return 'desktop'
end

def ip_addr
def get_ip_address
request.remote_ip == '::1' ? '192.168.0.1' : request.remote_ip.to_s
end

def user_name
RandomNameGenerator.new(RandomNameGenerator::GOBLIN).compose(2)
end

end
end
end
6 changes: 3 additions & 3 deletions app/javascript/components/Users/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const User = (props) =>{
const {name, ip_address, device, emoji, last_seen_at, visits, online} = props.attributes.attributes;
const time_in_minutes = Math.round((date_in_seconds - last_seen_at)/60);

const status = online ? `Online` : `Last see ${get_time_in_words(time_in_minutes, last_seen_at)} ago`;
const status = online ? `Online` : `Last seen ${get_time_in_words(time_in_minutes, last_seen_at)} ago`;
const link_border = online ? "#8eff00" : "#efefef";
const card_class = online ? 'active' : '';
return (
Expand Down Expand Up @@ -82,8 +82,8 @@ function get_time_in_words(time, last_seen_at){
}
}

function change_ip(string){
return string.split(".")
function change_ip(ip_address){
return ip_address.split(".")
.map((e,i) => i<3 ? e : e.replace(/[0-9]/g,"*"))
.join(".")
}
Expand Down
10 changes: 5 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
User.create([{ name: RandomNameGenerator.new(RandomNameGenerator::GOBLIN).compose(2),
User.create([{ name: Faker::Movies::LordOfTheRings.character,
ip_address: '192.168.0.1',
device: 'iphone'
}, { name: RandomNameGenerator.new(RandomNameGenerator::GOBLIN).compose(2),
ip_address: '192.168.0.2',
}, { name: Faker::Movies::LordOfTheRings.character,
ip_address: '2.468.123.21',
device: 'android'
}, { name: RandomNameGenerator.new(RandomNameGenerator::GOBLIN).compose(2),
ip_address: '192.168.0.3',
}, { name: Faker::Movies::LordOfTheRings.character,
ip_address: '92.8.0.123',
device: 'unknown' }
])