device-tracker 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rspec +2 -0
- data/Readme.md +1 -0
- data/bin/console +1 -1
- data/device-tracker.gemspec +8 -2
- data/exe/device-tracker +48 -9
- data/lib/device_tracker/app.rb +21 -0
- data/lib/{device/tracker → device_tracker}/config-schema.json +0 -0
- data/lib/{device/tracker → device_tracker}/config.ru +0 -0
- data/lib/device_tracker/controllers/application_controller.rb +220 -0
- data/lib/device_tracker/controllers/devices_controller.rb +313 -0
- data/lib/device_tracker/controllers/heartbeat_controller.rb +54 -0
- data/lib/device_tracker/controllers/os_controller.rb +41 -0
- data/lib/device_tracker/controllers/transactions_controller.rb +19 -0
- data/lib/device_tracker/controllers/users_controller.rb +191 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20150521071815_create_users.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20150521082155_create_devices.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20150521120335_create_operating_systems.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20150527162242_create_transactions.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20151027073050_create_heartbeat.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20151028132946_add_user_verification.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20151028141328_remove_is_active_from_users.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20151029085629_add_password_reset_code_to_users.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20151030130341_add_missing_column_to_devices.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/migrate/20151102141601_add_serial_number_to_devices.rb +0 -0
- data/lib/{device/tracker → device_tracker}/db/schema.rb +0 -0
- data/lib/device_tracker/db/seeds.rb +46 -0
- data/lib/{device/tracker → device_tracker}/dependencies.rb +0 -1
- data/lib/device_tracker/device_tracker.rb +17 -0
- data/lib/device_tracker/helpers/application_helper.rb +82 -0
- data/lib/device_tracker/models/device.rb +35 -0
- data/lib/device_tracker/models/heartbeat.rb +7 -0
- data/lib/device_tracker/models/operating_system.rb +6 -0
- data/lib/device_tracker/models/transaction.rb +54 -0
- data/lib/device_tracker/models/user.rb +20 -0
- data/lib/{device/tracker → device_tracker}/public/css/bootstrap-sortable.css +0 -0
- data/lib/{device/tracker → device_tracker}/public/css/bootstrap.min.css +0 -0
- data/lib/{device/tracker → device_tracker}/public/css/custom.css +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/android-chrome-144x144.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/android-chrome-192x192.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/android-chrome-36x36.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/android-chrome-48x48.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/android-chrome-72x72.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/android-chrome-96x96.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-114x114.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-120x120.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-144x144.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-152x152.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-180x180.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-57x57.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-60x60.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-72x72.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-76x76.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon-precomposed.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/apple-touch-icon.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/browserconfig.xml +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/favicon-16x16.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/favicon-32x32.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/favicon-96x96.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/favicon.ico +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/manifest.json +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/mstile-144x144.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/mstile-150x150.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/mstile-310x150.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/mstile-310x310.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/mstile-70x70.png +0 -0
- data/lib/{device/tracker → device_tracker}/public/favicon/safari-pinned-tab.svg +0 -0
- data/lib/{device/tracker → device_tracker}/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/{device/tracker → device_tracker}/public/fonts/glyphicons-halflings-regular.svg +0 -0
- data/lib/{device/tracker → device_tracker}/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/{device/tracker → device_tracker}/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/{device/tracker → device_tracker}/public/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/lib/{device/tracker → device_tracker}/public/js/bootstrap-sortable.js +0 -0
- data/lib/{device/tracker → device_tracker}/public/js/bootstrap.min.js +0 -0
- data/lib/{device/tracker → device_tracker}/public/js/jquery-2.1.4.min.js +0 -0
- data/lib/device_tracker/version.rb +3 -0
- data/lib/{device/tracker → device_tracker}/views/404.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/_alert.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/_device_form.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/_device_list.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/_footer.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/_header.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/_heartbeat_list.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/_user_form.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/devices/edit.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/devices/index.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/devices/new.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/devices/show.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/devices/users.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/emails/new_password.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/emails/password_reset.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/emails/registration.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/emails/reminder.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/emails/verification.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/forgot_password.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/index.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/layout.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/login.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/operating_system/operating_systems.json.jbuilder +0 -0
- data/lib/{device/tracker → device_tracker}/views/os/manage.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/transactions/_transactions_list.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/transactions/index.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/users/edit.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/users/manage.erb +0 -0
- data/lib/{device/tracker → device_tracker}/views/users/new.erb +0 -0
- metadata +187 -103
- data/lib/device/tracker.rb +0 -19
- data/lib/device/tracker/app.rb +0 -25
- data/lib/device/tracker/controllers/application_controller.rb +0 -215
- data/lib/device/tracker/controllers/devices_controller.rb +0 -315
- data/lib/device/tracker/controllers/heartbeat_controller.rb +0 -55
- data/lib/device/tracker/controllers/os_controller.rb +0 -43
- data/lib/device/tracker/controllers/transactions_controller.rb +0 -21
- data/lib/device/tracker/controllers/users_controller.rb +0 -193
- data/lib/device/tracker/db/data/devices.xlsx +0 -0
- data/lib/device/tracker/db/seeds.rb +0 -25
- data/lib/device/tracker/helpers/application_helper.rb +0 -84
- data/lib/device/tracker/models/device.rb +0 -39
- data/lib/device/tracker/models/heartbeat.rb +0 -9
- data/lib/device/tracker/models/operating_system.rb +0 -8
- data/lib/device/tracker/models/transaction.rb +0 -56
- data/lib/device/tracker/models/user.rb +0 -22
- data/lib/device/tracker/version.rb +0 -5
@@ -1,55 +0,0 @@
|
|
1
|
-
require_relative 'application_controller'
|
2
|
-
|
3
|
-
module Device
|
4
|
-
module Tracker
|
5
|
-
|
6
|
-
class HeartbeatController < ApplicationController
|
7
|
-
|
8
|
-
post "/" do
|
9
|
-
begin
|
10
|
-
heartbeat = JSON.parse(request.body.read)
|
11
|
-
rescue Exception => e
|
12
|
-
halt 412, {
|
13
|
-
error: true,
|
14
|
-
message: "#{e.message}"
|
15
|
-
}.to_json
|
16
|
-
end
|
17
|
-
|
18
|
-
# {"heartbeat": {"device_id": "BBCFM003", "longitude": 53.470096, "latitude": -2.281457}}
|
19
|
-
if valid_heartbeat?(heartbeat)
|
20
|
-
|
21
|
-
heartbeat = heartbeat["heartbeat"]
|
22
|
-
|
23
|
-
unid = heartbeat["device_id"].upcase
|
24
|
-
|
25
|
-
if Device.exists?(unid: unid)
|
26
|
-
device = Device.find_by_unid(unid)
|
27
|
-
|
28
|
-
Heartbeat.create({
|
29
|
-
longitude: heartbeat["longitude"],
|
30
|
-
latitude: heartbeat["latitude"],
|
31
|
-
device_id: device.id
|
32
|
-
})
|
33
|
-
|
34
|
-
halt 201, {
|
35
|
-
error: false,
|
36
|
-
message: "Heartbeat for device: #{unid} received."
|
37
|
-
}.to_json
|
38
|
-
else
|
39
|
-
halt 404, {
|
40
|
-
error: true,
|
41
|
-
message: "The device with id: #{unid} doesn't exist."
|
42
|
-
}.to_json
|
43
|
-
end
|
44
|
-
|
45
|
-
else
|
46
|
-
halt 412, {
|
47
|
-
error: true,
|
48
|
-
message: "Manformed heartbeat received, so will not be processed."
|
49
|
-
}.to_json
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require_relative 'application_controller'
|
2
|
-
module Device
|
3
|
-
module Tracker
|
4
|
-
class OSController < ApplicationController
|
5
|
-
|
6
|
-
before do
|
7
|
-
perform_admin_check
|
8
|
-
end
|
9
|
-
|
10
|
-
get "/manage" do
|
11
|
-
@os = OperatingSystem.all.order(:name)
|
12
|
-
erb :"os/manage"
|
13
|
-
end
|
14
|
-
|
15
|
-
post "/create" do
|
16
|
-
|
17
|
-
@os = OperatingSystem.create(params[:os])
|
18
|
-
|
19
|
-
if @os.valid?
|
20
|
-
@os.save
|
21
|
-
create_flash "success", ["Successfully added #{@os.name}"]
|
22
|
-
redirect back
|
23
|
-
else
|
24
|
-
create_flash "warning", @os.errors.full_messages
|
25
|
-
redirect back
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
delete "/:os_id/delete" do |os_id|
|
30
|
-
|
31
|
-
if OperatingSystem.exists?(os_id)
|
32
|
-
OperatingSystem.destroy(os_id)
|
33
|
-
create_flash "success", ["Operating system deleted."]
|
34
|
-
redirect back
|
35
|
-
else
|
36
|
-
create_flash "warning", ["Operating system not found."]
|
37
|
-
redirect back
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'application_controller'
|
2
|
-
|
3
|
-
module Device
|
4
|
-
module Tracker
|
5
|
-
class TransactionsController < ApplicationController
|
6
|
-
|
7
|
-
get "/" do
|
8
|
-
|
9
|
-
@transactions = Transaction.limit(100).order(created_at: :desc).all
|
10
|
-
|
11
|
-
erb :"transactions/index"
|
12
|
-
end
|
13
|
-
|
14
|
-
get "/:device_id" do |device_id|
|
15
|
-
@transactions = Transaction.where(device_id: device_id).limit(100).order(created_at: :desc).all
|
16
|
-
erb :"transactions/index"
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,193 +0,0 @@
|
|
1
|
-
require_relative 'application_controller'
|
2
|
-
|
3
|
-
module Device
|
4
|
-
module Tracker
|
5
|
-
class UsersController < ApplicationController
|
6
|
-
|
7
|
-
before do
|
8
|
-
|
9
|
-
if ! %w[new create].include? request.path_info.split('/')[1]
|
10
|
-
protected!
|
11
|
-
end
|
12
|
-
|
13
|
-
if %w[manage].include? request.path_info.split('/')[1]
|
14
|
-
perform_admin_check
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
get "/manage" do
|
19
|
-
|
20
|
-
@users = User.all
|
21
|
-
|
22
|
-
erb :"users/manage", users: @users
|
23
|
-
end
|
24
|
-
|
25
|
-
get "/new" do
|
26
|
-
erb :"users/new"
|
27
|
-
end
|
28
|
-
|
29
|
-
get "/:user_id/edit" do |user_id|
|
30
|
-
# TODO Move this out into its own function
|
31
|
-
user = get_logged_in_user
|
32
|
-
|
33
|
-
if user[:is_admin] != true and user[:id] != user_id.to_i
|
34
|
-
create_flash "warning", ["You don't have permission to view this page."]
|
35
|
-
redirect back
|
36
|
-
end
|
37
|
-
|
38
|
-
if User.exists?(user_id)
|
39
|
-
@user = User.find(user_id)
|
40
|
-
@is_admin = user[:is_admin]
|
41
|
-
erb :"users/edit"
|
42
|
-
else
|
43
|
-
create_flash "warning", ["Sorry, but that user doesn't exist"]
|
44
|
-
redirect back
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
put "/:user_id" do |user_id|
|
49
|
-
|
50
|
-
if get_logged_in_user[:is_admin] != true and get_logged_in_user[:id] != user_id.to_i
|
51
|
-
create_flash "warning", ["You don't have permission to view this page."]
|
52
|
-
redirect back
|
53
|
-
end
|
54
|
-
|
55
|
-
if User.exists?(user_id)
|
56
|
-
|
57
|
-
attributes = {
|
58
|
-
username: params[:user][:username],
|
59
|
-
email: params[:user][:email],
|
60
|
-
name: params[:user][:name]
|
61
|
-
}
|
62
|
-
|
63
|
-
# Only admins have access to these attributes
|
64
|
-
if is_admin?
|
65
|
-
attributes[:is_admin] = (!params[:user][:is_admin].nil? and params[:user][:is_admin] == "on")
|
66
|
-
attributes[:is_verified] = (!params[:user][:is_verified].nil? and params[:user][:is_verified] == "on")
|
67
|
-
end
|
68
|
-
|
69
|
-
# Should we change the password?
|
70
|
-
|
71
|
-
if change_password?(params)
|
72
|
-
attributes[:password] = params[:user][:password]
|
73
|
-
attributes[:password_confirmation] = params[:user][:password_confirmation]
|
74
|
-
end
|
75
|
-
|
76
|
-
user = User.find(user_id)
|
77
|
-
users_previous_verification = user.is_verified
|
78
|
-
|
79
|
-
if user.update(attributes)
|
80
|
-
if user.is_verified && users_previous_verification == false
|
81
|
-
verification_email(user)
|
82
|
-
end
|
83
|
-
create_flash "success", ["The account was successfully updated."]
|
84
|
-
redirect back
|
85
|
-
else
|
86
|
-
create_flash "warning", user.errors.full_messages
|
87
|
-
redirect back
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
create_flash "warning", ["I'm sorry but that user does not exist!"]
|
92
|
-
redirect back
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
post "/create" do
|
97
|
-
|
98
|
-
user = User.new
|
99
|
-
|
100
|
-
attributes = {
|
101
|
-
username: params[:user][:username],
|
102
|
-
password: params[:user][:password],
|
103
|
-
password_confirmation: params[:user][:password_confirmation],
|
104
|
-
name: params[:user][:name],
|
105
|
-
email: params[:user][:email]
|
106
|
-
}
|
107
|
-
|
108
|
-
user.username = attributes[:username]
|
109
|
-
user.password = attributes[:password]
|
110
|
-
user.email = attributes[:email]
|
111
|
-
user.name = attributes[:name]
|
112
|
-
user.password_confirmation = attributes[:password_confirmation]
|
113
|
-
|
114
|
-
attributes.each do |key, value|
|
115
|
-
flash[key] = value if key != :password
|
116
|
-
end
|
117
|
-
|
118
|
-
if user.valid? and user.save
|
119
|
-
|
120
|
-
report_transaction("#{user.email} registered a new account.", Transaction.registration)
|
121
|
-
|
122
|
-
# Account is awaiting activation
|
123
|
-
admin_email_registration(request, user)
|
124
|
-
create_flash "info", ["Registration successful, please wait for your account to be activated."]
|
125
|
-
redirect "/"
|
126
|
-
else
|
127
|
-
create_flash "warning", [user.errors.full_messages.first]
|
128
|
-
redirect back
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
delete "/:user_id/delete" do |user_id|
|
133
|
-
if User.exists?(user_id)
|
134
|
-
user = User.find(user_id)
|
135
|
-
|
136
|
-
email = user.email
|
137
|
-
|
138
|
-
if user.devices.count > 0
|
139
|
-
Device.where(user_id: user.id).update_all(available: true, checked_out_since: nil, user_id: nil)
|
140
|
-
end
|
141
|
-
|
142
|
-
if user.destroy
|
143
|
-
report_transaction("#{email} was deleted by #{get_logged_in_user[:email]}.", Transaction.deletion)
|
144
|
-
end
|
145
|
-
|
146
|
-
create_flash "success", ["The user account has been successfully removed!"]
|
147
|
-
else
|
148
|
-
create_flash "warning", ["Unable to remove the user account, try again."]
|
149
|
-
end
|
150
|
-
|
151
|
-
redirect back
|
152
|
-
end
|
153
|
-
|
154
|
-
def verification_email(user)
|
155
|
-
|
156
|
-
@user = user
|
157
|
-
@get_started_link = request.base_url + '/devices'
|
158
|
-
body = ERB.new(File.read(EMAILS_PATH + "/verification.erb")).result(binding)
|
159
|
-
|
160
|
-
begin
|
161
|
-
Pony.mail(
|
162
|
-
:to => [@user.email],
|
163
|
-
:from => 'no-reply@device-tracker',
|
164
|
-
:subject => 'Account Verified | Device Tracker',
|
165
|
-
:html_body => body
|
166
|
-
)
|
167
|
-
rescue Net::OpenTimeout => e
|
168
|
-
puts "ERROR: Error sending email"
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
def admin_email_registration(request, user)
|
174
|
-
@user = user
|
175
|
-
@verification_link = request.base_url + '/users/' + user.id.to_s + '/edit'
|
176
|
-
|
177
|
-
body = ERB.new(File.read(EMAILS_PATH + "/registration.erb")).result(binding)
|
178
|
-
|
179
|
-
begin
|
180
|
-
Pony.mail(
|
181
|
-
:to => [User.where(is_admin: true).map {|u| u.email }],
|
182
|
-
:from => 'no-reply@device-tracker',
|
183
|
-
:subject => 'New Registration | Device Tracker',
|
184
|
-
:html_body => body
|
185
|
-
)
|
186
|
-
rescue Net::OpenTimeout => e
|
187
|
-
puts "ERROR: Error sending email"
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
Binary file
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Device
|
2
|
-
module Tracker
|
3
|
-
class Seed
|
4
|
-
def self.seed(name: name, password: password, email: email)
|
5
|
-
|
6
|
-
user = User.where(email: email)
|
7
|
-
|
8
|
-
if user.exists?
|
9
|
-
return
|
10
|
-
end
|
11
|
-
|
12
|
-
user = User.find_or_create_by({
|
13
|
-
name: name,
|
14
|
-
username: 'admin',
|
15
|
-
email: email,
|
16
|
-
is_admin: true,
|
17
|
-
is_verified: true
|
18
|
-
})
|
19
|
-
user.password = password
|
20
|
-
user.save
|
21
|
-
puts "Added #{user.username} to the database."
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
module Device
|
2
|
-
module Tracker
|
3
|
-
module ApplicationHelper
|
4
|
-
|
5
|
-
SECRET = 'mYR4nd0mAr$eS3cr3t/fuGg1wugGl3'
|
6
|
-
|
7
|
-
def is_admin?
|
8
|
-
user = get_logged_in_user
|
9
|
-
return if user.nil?
|
10
|
-
user[:is_admin]
|
11
|
-
end
|
12
|
-
|
13
|
-
def value_for(name, object)
|
14
|
-
if flash[name]
|
15
|
-
flash[name]
|
16
|
-
elsif object
|
17
|
-
object.send name
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def get_logged_in_user
|
22
|
-
session[:user] unless session[:user].nil?
|
23
|
-
end
|
24
|
-
|
25
|
-
def generate_activation_code(size = 6)
|
26
|
-
charset = %w{0 1 2 3 4 6 7 8 9 A C D E F G H J K M N P Q R T V W X Y Z}
|
27
|
-
(0...size).map{ charset.to_a[rand(charset.size)] }.join
|
28
|
-
end
|
29
|
-
|
30
|
-
def change_password?(params)
|
31
|
-
if params[:user][:password].empty? or params[:user][:password_confirmation].empty?
|
32
|
-
false
|
33
|
-
else
|
34
|
-
true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def protected!
|
39
|
-
if session[:user].nil?
|
40
|
-
create_flash "info", ["You must be logged in to see this page."]
|
41
|
-
redirect "/login"
|
42
|
-
elsif !session[:user][:is_verified]
|
43
|
-
create_flash "info", ["You account is awaiting verification by an admin."]
|
44
|
-
redirect "/login"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def report_transaction(message, type, device = nil)
|
49
|
-
transaction = Transaction.new
|
50
|
-
|
51
|
-
if session[:user]
|
52
|
-
transaction.user_id = get_logged_in_user[:id]
|
53
|
-
end
|
54
|
-
|
55
|
-
transaction.description = message
|
56
|
-
transaction.transaction_type = type
|
57
|
-
transaction.device_id = device.id unless device.nil?
|
58
|
-
|
59
|
-
transaction.save!
|
60
|
-
end
|
61
|
-
|
62
|
-
def perform_admin_check
|
63
|
-
user = get_logged_in_user
|
64
|
-
if user.nil? or user[:is_admin] == false
|
65
|
-
create_flash "warning", ["#{user[:name]} does not have permissions to access this page."]
|
66
|
-
redirect back
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_flash(type, message)
|
71
|
-
flash[:message] = {css_class: type, message: message }
|
72
|
-
end
|
73
|
-
|
74
|
-
def valid_heartbeat?(data)
|
75
|
-
if !data["heartbeat"].nil? and !data["heartbeat"]["longitude"].nil? and
|
76
|
-
!data["heartbeat"]["latitude"].nil? and !data["heartbeat"]["device_id"].nil?
|
77
|
-
return true
|
78
|
-
end
|
79
|
-
false
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
module Device
|
4
|
-
module Tracker
|
5
|
-
class Device < ActiveRecord::Base
|
6
|
-
|
7
|
-
belongs_to :operating_system
|
8
|
-
belongs_to :user
|
9
|
-
|
10
|
-
has_many :transactions
|
11
|
-
has_many :heartbeats
|
12
|
-
|
13
|
-
validates :unid, :manufacturer, :device, :description, :operating_system, presence: true
|
14
|
-
|
15
|
-
validates :unid, uniqueness: true
|
16
|
-
|
17
|
-
def unid=(unid)
|
18
|
-
self[:unid] = unid.upcase
|
19
|
-
end
|
20
|
-
|
21
|
-
def full_name
|
22
|
-
self[:manufacturer] + " " + self[:device]
|
23
|
-
end
|
24
|
-
|
25
|
-
def passed_use_by_date?
|
26
|
-
(! self[:available] and (Time.now - self[:checked_out_since]).to_i / 1.day >= 3)
|
27
|
-
end
|
28
|
-
|
29
|
-
def checked_out_since_formatted
|
30
|
-
self[:checked_out_since].strftime("%A, %d %B %Y at %I:%M%p")
|
31
|
-
end
|
32
|
-
|
33
|
-
def days_checked_out
|
34
|
-
(Time.now.to_date - self[:checked_out_since].to_date).floor
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|