/
sentries_controller.rb
56 lines (49 loc) · 1.45 KB
/
sentries_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class SentriesController < ApplicationController
before_filter :login_required, :except => 'index'
before_filter :http_basic_authenticate, :only => 'index'
layout nil
def index
if params[:device_id]
@sentries = Sentry.find(:all, :conditions => {:device_id => params[:device_id]})
respond_to do |format|
format.json { render :json => @sentries }
end
end
end
def edit
@sentry = Sentry.find(params[:id])
end
def create
@sentry = Sentry.new(params[:sentry])
if @sentry.save
flash[:notice] = "Sentry created successfully."
redirect_to :back
else
flash[:notice] = "Sentry could not be created."
redirect_to :back
end
end
def update
@sentry = Sentry.find(params[:id])
if @sentry.update_attributes(params[:sentry])
flash[:notice] = "Sentry updated successfully."
redirect_to :back
else
flash[:notice] = "Sentry could not be updated."
redirect_to :back
end
end
def destroy
@sentry = Sentry.find(params[:id])
@sentry.destroy
redirect_to :back
end
protected
def http_basic_authenticate
authenticate_or_request_with_http_basic do |username, password|
# after testing uncomment the following line and comment out the test line
# username == APP_CONFIG[:event_api_username] && password == APP_CONFIG[:event_api_password]
username == "test" && password == "test"
end
end
end