Skip to content

Commit 101df98

Browse files
committed
Added simple approval and suspended pages. Added filters to redirect users depending on the status. Moved about page to the pages controller
1 parent ebb5f3f commit 101df98

File tree

13 files changed

+64
-4
lines changed

13 files changed

+64
-4
lines changed
250 KB
Loading
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

app/assets/stylesheets/pages.css.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the Pages controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/

app/controllers/admin/admin_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def index
66
@all_users = User.find(:all, :conditions => ["id != ?", current_user.id])
77

88
# Note that this reject! will remove users from all_users in order to show users in 2 different tables
9-
@waiting_for_approval_users = @all_users.reject!{|user| user.status.waiting_approval? } || []
9+
@waiting_for_approval_users = @all_users.select{|user| user.status.waiting_approval? } || []
1010
end
1111

1212
def update
+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
class ApplicationController < ActionController::Base
22
protect_from_forgery
3+
4+
before_filter :force_approved_account
5+
before_filter :redirect_suspended_account
6+
7+
def force_approved_account
8+
# We will redirect to the approval page if a user is signed in, is not an admin and is marked as waiting for approval
9+
redirect = user_signed_in? && !current_user.is_admin? && current_user.status.waiting_approval?
10+
11+
redirect_to approval_path if redirect
12+
end
13+
14+
def redirect_suspended_account
15+
# We will redirect to suspended if a user is singed in and its marked as suspended
16+
redirect = user_signed_in? && current_user.status.suspended?
17+
18+
redirect_to suspended_path if redirect
19+
end
20+
321
end

app/controllers/pages_controller.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class PagesController < ApplicationController
2+
3+
before_filter :authenticate_user!, :except => :about
4+
5+
skip_filter :force_approved_account, :only => :approval
6+
skip_filter :redirect_suspended_account, :only => :suspended
7+
8+
def approval
9+
end
10+
11+
def suspended
12+
end
13+
14+
def about
15+
end
16+
17+
end

app/helpers/pages_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module PagesHelper
2+
end

app/models/setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def validate_public_site
3737
end
3838

3939
def self.default_values
40-
return {:max_rooms => 99, :public_site => false }
40+
return {:max_rooms => 99, :public_site => true }
4141
end
4242

4343
# Helper methods to be used while we don't need to deal with multi-tenancy

app/views/admin/admin/index.html.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<% end %>
1313

1414
<div class="waiting-for-approval-users">
15+
<div>Users waiting for approval</div>
1516
<% if @waiting_for_approval_users.any? %>
1617
<table cellspacing="0" cellpadding="0" border="0">
1718
<thead>
@@ -25,7 +26,7 @@
2526
</tr>
2627
</thead>
2728
<tbody>
28-
<% @all_users.each do |user| %>
29+
<% @waiting_for_approval_users.each do |user| %>
2930
<tr class="<%= cycle('odd', 'even')%>" data-user-id="<%= user.id%>">
3031
<td>
3132
<%= user.username %>
@@ -55,6 +56,7 @@
5556
</div>
5657

5758
<div class="approved-users">
59+
<div>All users</div>
5860
<% if @all_users.any? %>
5961
<table cellspacing="0" cellpadding="0" border="0">
6062
<thead>
File renamed without changes.

app/views/pages/approval.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
You admin has to approve your account before you start using the Kandan app.
3+
</div>

app/views/pages/suspended.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="suspended">
2+
Sorry buddy, the admin of this site has suspended your account.
3+
</div>
4+
<%= image_tag "emoticons/sad-meme.png", :alt => "sorry"%>

config/routes.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Kandan::Application.routes.draw do
22

3+
get "pages/approval"
4+
5+
get "pages/suspended"
6+
37
root :to => "main#index"
48
devise_for :users
59

@@ -12,7 +16,6 @@
1216

1317
get "/active_users" => "apis#active_users"
1418

15-
get "/about" =>"main#about"
1619
get "/users/edit" =>"main#users_edit"
1720

1821
namespace :admin do
@@ -21,6 +24,11 @@
2124
put "/update_users", :to => "admin#update_users", :as => "update_users"
2225
end
2326

27+
# Pages Controller
28+
get "/approval", :to => "pages#approval"
29+
get "/suspended", :to => "pages#suspended"
30+
get "/about", :to =>"pages#about"
31+
2432
# The priority is based upon order of creation:
2533
# first created -> highest priority.
2634

0 commit comments

Comments
 (0)