This repository has been archived by the owner on Feb 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ba_extension.rb
150 lines (124 loc) · 5.32 KB
/
ba_extension.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Uncomment this if you reference any of your controllers in activate
# require_dependency 'application'
class BaExtension < Radiant::Extension
version "1.0"
description "Event and Conference organizing."
url "http://github.com/aslakhellesoy/ba/tree/master"
define_routes do |map|
map.logout '/logout', :controller => 'site_sessions', :action => 'destroy'
map.register '/register', :controller => 'site_users', :action => 'create'
map.signup '/signup', :controller => 'site_users', :action => 'new'
map.activate '/activate/:activation_code', :controller => 'site_users', :action => 'activate', :activation_code => nil
map.resources :site_users, :member => { :suspend => :put,
:unsuspend => :put,
:purge => :delete }
map.resource :site_session
# map.resources :presentations
# map.resource :attendance
# map.resource :attendance, :path_prefix => "*url" do |attendance|
# attendance.resources :presentations
# end
map.with_options(:controller => 'admin/price') do |prices|
prices.price_index 'admin/price', :action => 'index'
prices.price_edit 'admin/price/edit/:id', :action => 'edit'
prices.price_new 'admin/price/new', :action => 'new'
prices.price_remove 'admin/price/remove/:id', :action => 'remove'
end
map.with_options(:controller => 'admin/site_user') do |site_users|
site_users.site_user_index 'admin/site_user', :action => 'index'
site_users.site_user_edit 'admin/site_user/edit/:id', :action => 'edit'
site_users.site_user_new 'admin/site_user/new', :action => 'new'
site_users.site_user_remove 'admin/site_user/remove/:id', :action => 'remove'
end
map.with_options(:controller => 'admin/program') do |programs|
programs.program_index 'admin/program', :action => 'index'
programs.program_edit 'admin/program/:id', :action => 'edit'
end
map.with_options(:controller => 'admin/email') do |email|
email.email_new 'admin/email/new', :action => 'new'
end
map.namespace(:admin) do |admin|
admin.resources :presentations
end
end
def activate
Page.class_eval do
attr_accessor :controller
def cache?
false
end
end
SiteController.class_eval do
session :disabled => false # :on
include AuthenticatedSystem
before_filter :authenticate_from_activation_code
before_filter :authenticate_from_reset_code
public :redirect_to, :flash
def process_page_with_set_controller(page)
page.controller = self
process_page_without_set_controller(page)
end
alias_method_chain :process_page, :set_controller
def no_login_required?
true
end
def authenticate_from_activation_code
if activation_code = params.delete(:activation_code)
logout_keeping_session!
site_user = SiteUser.find_by_activation_code(activation_code) unless activation_code.blank?
if site_user && !site_user.active?
self.current_site_user = site_user
end
end
end
def authenticate_from_reset_code
if reset_code = params.delete(:reset_code)
logout_keeping_session!
site_user = SiteUser.find_by_reset_code(reset_code) unless reset_code.blank?
if site_user
site_user.clear_reset_code!
self.current_site_user = site_user
end
end
end
end
admin.tabs.add "Prices", "/admin/price", :after => "Layouts", :visibility => [:all]
admin.tabs.add "Programs", "/admin/program", :after => "Prices", :visibility => [:all]
admin.tabs.add "Site Users", "/admin/site_user", :after => "Programs", :visibility => [:all]
admin.tabs.add "Email", "/admin/email/new", :after => "Site Users", :visibility => [:all]
admin.instance_eval do
def price
@price ||= returning OpenStruct.new do |snippet|
snippet.edit = Radiant::AdminUI::RegionSet.new do |edit|
edit.main.concat %w{edit_header edit_form}
edit.form.concat %w{edit_code edit_amount edit_max edit_currency edit_happening_page}
edit.form_bottom.concat %w{edit_buttons}
end
end
end
end
tweak_page_edit_ui
end
def deactivate
admin.tabs.remove "Prices"
SiteController.class_eval { session :off }
end
private
def tweak_page_edit_ui
# Add fields for input of Happening attributes. See app/views/admin/_edit_page_happening.html.erb
admin.page.edit.add :layout_row, "edit_page_happening"
# Add javascript that only displays Happening when page type is HappeningPage
Admin::PageController.class_eval do
before_filter :edit_page_happening_js
def edit_page_happening_js
include_javascript 'admin/edit_page_happening.js'
end
end
end
end
# This is for restful authentication (site site_users)
require 'aasm'
unless defined?(REST_AUTH_SITE_KEY)
REST_AUTH_SITE_KEY = '83750ca3f127dcabc9d78bf45a19941c16dcaec6'
REST_AUTH_DIGEST_STRETCHES = 10
end