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