29 |
--------------------------------------------------------------------------------
/app/mailers/registration_mailer.rb:
--------------------------------------------------------------------------------
1 | class RegistrationMailer < ActionMailer::Base
2 |
3 | def confirmation(registration, request)
4 | subject "#{RefinerySetting.find_or_set(:site_name, 'Progressbar Hackerspace')} - registration"
5 | recipients registration.email
6 | from "\"#{RefinerySetting[:site_name]}\" "
7 | sent_on Time.now
8 | @registration = registration
9 | end
10 |
11 | def approved_confirmation(registration, user, request)
12 | subject "#{RefinerySetting.find_or_set(:site_name, 'Progressbar Hackerspace')} - #{t('.registration_approved')}"
13 | recipients registration.email
14 | from "\"#{RefinerySetting[:site_name]}\" "
15 | sent_on Time.now
16 | @user = user
17 | @new_password_url = edit_user_password_url(:host => request.host_with_port,
18 | :reset_password_token => @user.reset_password_token)
19 | @registration = registration
20 | end
21 |
22 | def rejected_confirmation(registration, request)
23 | subject "#{RefinerySetting.find_or_set(:site_name, 'Progressbar Hackerspace')} - #{t('.registration_rejected')}"
24 | recipients registration.email
25 | from "\"#{RefinerySetting[:site_name]}\" "
26 | sent_on Time.now
27 | @registration = registration
28 | end
29 |
30 | def notification(registration, request)
31 | subject "#{RefinerySetting.find_or_set(:site_name, 'Progressbar Hackerspace')} - #{t('.registration_notification')}"
32 | recipients RefinerySetting.find_or_set(:registration_notification_recipients, RefinerySetting.find_or_set(:inquiry_notification_recipients, 'info@progressbar.sk'))
33 | from "\"#{RefinerySetting[:site_name]}\" "
34 | sent_on Time.now
35 | @registration = registration
36 | end
37 |
38 | end
39 |
--------------------------------------------------------------------------------
/app/controllers/admin/registrations_controller.rb:
--------------------------------------------------------------------------------
1 | module Admin
2 | class RegistrationsController < Admin::BaseController
3 |
4 | crudify :registration,
5 | :title_attribute => 'username', :xhr_paging => true
6 |
7 | helper_method :group_by_date
8 |
9 | before_filter :find_all_ham, :only => [:index, :approved, :rejected]
10 | before_filter :find_all_spam, :only => [:spam]
11 | before_filter :get_spam_count, :only => [:index, :spam, :approved, :rejected]
12 |
13 | def index
14 | @registrations = @registrations.unmoderated
15 | @registrations = @registrations.with_query(params[:search]) if searching?
16 | @registrations = @registrations.paginate({:page => params[:page]})
17 | end
18 |
19 | def approved
20 | unless params[:id].present?
21 | @registrations = @registrations.approved
22 | @registrations = @registrations.paginate({:page => params[:page]})
23 | render :action => 'index'
24 | else
25 | @registration = Registration.find(params[:id])
26 | password = (0...20).map{ ('a'..'z').to_a[rand(26)] }.join
27 |
28 | u = User.create(:username => @registration.username,
29 | :email => @registration.email,
30 | :password => password,
31 | :password_confirmation => password)
32 |
33 | if u.valid?
34 | begin
35 | last_user = User.order('progressbar_uid ASC').limit(1).last
36 | u.add_role(:member)
37 | u.add_role(:refinery)
38 | u.plugins = ['fees']
39 | u.progressbar_uid = last_user.nil? ? u.id : last_user.progressbar_uid.to_i + 42
40 | u.send(:generate_reset_password_token!)
41 | u.save
42 | @registration.approve!
43 | RegistrationMailer.approved_confirmation(@registration, u, request).deliver
44 | rescue
45 | logger.warn "There was an error delivering an approved registration confirmation.\n#{$!}\n"
46 | end
47 | else
48 | puts "#{@registration.email} - #{u.errors.to_s}"
49 | end
50 |
51 | flash[:notice] = t('approved', :scope => 'admin.registration', :author => @registration.username)
52 | redirect_to :action => 'index'
53 | end
54 | end
55 |
56 | def rejected
57 | unless params[:id].present?
58 | @registrations = @registrations.rejected
59 | @registrations = @registrations.paginate({:page => params[:page]})
60 | render :action => 'index'
61 | else
62 | begin
63 | @registration = Registration.find(params[:id])
64 | @registration.reject!
65 | RegistrationMailer.rejected_confirmation(@registration, request).deliver
66 | rescue
67 | logger.warn "There was an error delivering an rejected registration confirmation.\n#{$!}\n"
68 | end
69 | flash[:notice] = t('rejected', :scope => 'admin.registration', :author => @registration.username)
70 | redirect_to :action => 'index'
71 | end
72 | end
73 |
74 | def spam
75 | self.index
76 | render :action => 'index'
77 | end
78 |
79 | def toggle_spam
80 | find_registration
81 | @registration.toggle!(:spam)
82 |
83 | redirect_to :back
84 | end
85 |
86 | protected
87 |
88 | def find_all_ham
89 | @registrations = Registration.ham
90 | end
91 |
92 | def find_all_spam
93 | @registrations = Registration.spam
94 | end
95 |
96 | def get_spam_count
97 | @spam_count = Registration.count(:conditions => {:spam => true})
98 | end
99 |
100 | end
101 | end
--------------------------------------------------------------------------------
/features/step_definitions/registration_steps.rb:
--------------------------------------------------------------------------------
1 | Given /^I have no registrations$/ do
2 | Registration.delete_all
3 | end
4 |
5 | Given /^I (only )?have registrations titled "?([^\"]*)"?$/ do |only, titles|
6 | Registration.delete_all if only
7 | titles.split(', ').each do |title|
8 | Registration.create(:username => title)
9 | end
10 | end
11 |
12 | Then /^I should have ([0-9]+) registrations?$/ do |count|
13 | Registration.count.should == count.to_i
14 | end
15 |
16 | ###
17 | # new registration
18 | ###
19 |
20 | Given /^I am a visitor$/ do
21 | pending # express the regexp above with the code you wish you had
22 | end
23 |
24 | Given /^I have no registration$/ do
25 | pending # express the regexp above with the code you wish you had
26 | end
27 |
28 | Given /^I have a page titled "([^"]*)" with a custom url "([^"]*)"$/ do |arg1, arg2|
29 | pending # express the regexp above with the code you wish you had
30 | end
31 |
32 | When /^I go to the join us page$/ do
33 | pending # express the regexp above with the code you wish you had
34 | end
35 |
36 | Then /^I should see "([^"]*)"$/ do |arg1|
37 | pending # express the regexp above with the code you wish you had
38 | end
39 |
40 |
41 | #
42 | #Given /^I am a logged in refinery user$/ do
43 | # pending # express the regexp above with the code you wish you had
44 | #end
45 | #
46 | #When /^I go to the list of registrations$/ do
47 | # pending # express the regexp above with the code you wish you had
48 | #end
49 | #
50 | #Then /^I should see "([^"]*)"$/ do |arg1|
51 | # pending # express the regexp above with the code you wish you had
52 | #end
53 | #
54 | #When /^I follow "([^"]*)"$/ do |arg1|
55 | # pending # express the regexp above with the code you wish you had
56 | #end
57 | #
58 | #When /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
59 | # pending # express the regexp above with the code you wish you had
60 | #end
61 | #
62 | #When /^I press "([^"]*)"$/ do |arg1|
63 | # pending # express the regexp above with the code you wish you had
64 | #end
65 |
66 | #
67 | #When /^I follow "([^"]*)" within "([^"]*)"$/ do |arg1, arg2|
68 | # pending # express the regexp above with the code you wish you had
69 | #end
70 | #
71 | #Then /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
72 | # pending # express the regexp above with the code you wish you had
73 | #end
74 | #
75 | #Then /^I press "([^"]*)"$/ do |arg1|
76 | # pending # express the regexp above with the code you wish you had
77 | #end
78 | #
79 | #Then /^I should be on the list of registrations$/ do
80 | # pending # express the regexp above with the code you wish you had
81 | #end
82 | #
83 | #Then /^I should not see "([^"]*)"$/ do |arg1|
84 | # pending # express the regexp above with the code you wish you had
85 | #end
86 | #
87 | #Given /^I only have (\d+) new registration titled UniqueTitleOne$/ do |arg1|
88 | # pending # express the regexp above with the code you wish you had
89 | #end
90 | #
91 | #Then /^I should have (\d+) accepted registrations$/ do |arg1|
92 | # pending # express the regexp above with the code you wish you had
93 | #end
94 | #
95 | #Then /^I should have (\d+) rejected registrations$/ do |arg1|
96 | # pending # express the regexp above with the code you wish you had
97 | #end
98 |
99 | #
100 | #----
101 | #
102 | # @registrations-valid @valid
103 | # Scenario: Create Valid Registration
104 | # When I go to the list of registrations
105 | # And I follow "Add New Registration"
106 | # And I fill in "Username" with "This is a test of the first string field"
107 | # And I press "Save"
108 | # Then I should see "'This is a test of the first string field' was successfully added."
109 | # And I should have 1 registration
110 | #
111 | # @registrations-invalid @invalid
112 | # Scenario: Create Invalid Registration (without username)
113 | # When I go to the list of registrations
114 | # And I follow "Add New Registration"
115 | # And I press "Save"
116 | # Then I should see "Username can't be blank"
117 | # And I should have 0 registrations
118 | #
119 | # @registrations-edit @edit
120 | # Scenario: Edit Existing Registration
121 | # Given I have registrations titled "A username"
122 | # When I go to the list of registrations
123 | # And I follow "Edit this registration" within ".actions"
124 | # Then I fill in "Username" with "A different username"
125 | # And I press "Save"
126 | # Then I should see "'A different username' was successfully updated."
127 | # And I should be on the list of registrations
128 | # And I should not see "A username"
129 | #
130 | # @registrations-duplicate @duplicate
131 | # Scenario: Create Duplicate Registration
132 | # Given I only have registrations titled UniqueTitleOne, UniqueTitleTwo
133 | # When I go to the list of registrations
134 | # And I follow "Add New Registration"
135 | # And I fill in "Username" with "UniqueTitleTwo"
136 | # And I press "Save"
137 | # Then I should see "There were problems"
138 | # And I should have 2 registrations
139 | #
140 | # @registrations-accept @accept
141 | # Scenario: Accept Registration
142 | # Given I only have 1 new registration titled UniqueTitleOne
143 | # When I go to the list of registrations
144 | # And I follow "Accept this registration"
145 | # Then I should see "'UniqueTitleOne' was successfully accepted."
146 | # And I should have 1 accepted registrations
147 | #
148 | # @registrations-reject @reject
149 | # Scenario: Reject Registration
150 | # Given I only have registrations titled UniqueTitleOne
151 | # When I go to the list of registrations
152 | # And I follow "Reject this registration"
153 | # Then I should see "'UniqueTitleOne' was rejected."
154 | # And I should have 1 rejected registrations
155 |
--------------------------------------------------------------------------------