Skip to content

Commit

Permalink
Easier to activate new users
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason L Perry committed Jan 29, 2009
1 parent c68073d commit 86fd0ae
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/controllers/application.rb
Expand Up @@ -54,5 +54,15 @@ def require_authentication
true
end
end

def require_officer
unless logged_in? && current_user.officer?
flash[:warning] = "You are not an officer."
redirect_to root_path
false
else
true
end
end

end
19 changes: 19 additions & 0 deletions app/controllers/users_controller.rb
@@ -1,6 +1,8 @@
class UsersController < ApplicationController
skip_before_filter :require_activation, :only => [:edit, :update]

before_filter :require_officer, :only => [:activate]

# GET /users
# GET /users.xml
def index
Expand Down Expand Up @@ -64,4 +66,21 @@ def destroy
end
end

def activate
@user = User.find(params[:id])

respond_to do |format|
if @user.update_attribute(:activated, true)
format.html do
flash[:notice] = "User was successfully updated."
redirect_to(@user)
end
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end

end
1 change: 1 addition & 0 deletions app/views/sessions/new.html.erb
Expand Up @@ -4,6 +4,7 @@
<% form_tag session_path do %>
<label for="openid_url">OpenID:</label> <%= text_field_tag "openid_url" %> <%= submit_tag "Sign In" %>
<% end %>
<p class="note"><strong>New Users:</strong> To register, sign in using your OpenID.<br/>If you aren't sure what OpenID is, don't worry, you probably <a href="http://openid.net/get/" title="How do I get an OpenID?">already have one</a>.</p>
</div>

<script type="text/javascript" id="__openidselector" src="https://www.idselector.com/selector/30fee8db4c5ef346b039606ef0f406ff6b851b84" charset="utf-8"></script>
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/index.html.erb
Expand Up @@ -4,12 +4,14 @@
<tr>
<th>Name</th>
<th>Email</th>
<th></th>
</tr>

<% for user in @users %>
<tr>
<td><%=h user.name %></td>
<td><%=h user.email %></td>
<td><%= link_to "activate", activate_user_path(user), :method => :put unless user.activated? %></td>
</tr>
<% end %>
</table>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -13,6 +13,8 @@

map.users "/users", :action => "index"
map.user "/users/:id", :action => "show"

map.activate_user "/users/:id/activate", :action => "activate", :conditions => { :method => :put }
end

map.root :controller => "application", :action => "splash"
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20090129025840_add_officer_to_users.rb
@@ -0,0 +1,9 @@
class AddOfficerToUsers < ActiveRecord::Migration
def self.up
add_column :users, :officer, :boolean
end

def self.down
remove_column :users, :officer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20081110215532) do
ActiveRecord::Schema.define(:version => 20090129025840) do

create_table "open_id_authentication_associations", :force => true do |t|
t.integer "issued"
Expand Down Expand Up @@ -50,6 +50,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "activated", :default => false
t.boolean "officer"
end

end
5 changes: 5 additions & 0 deletions public/stylesheets/screen.css
Expand Up @@ -278,6 +278,11 @@ h1 a:focus, h1 a:hover, h1 a:active {
margin: 1em 0;
}

#new-session p.note {
margin-top: 1em;
line-height: 1.2em;
}

/* Flash Messages --------------------------------------------------------- */

#flash {
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/users.yml
Expand Up @@ -4,6 +4,7 @@ jasper:
identity_url: http://ambethia.com/
time_zone: Eastern Time (US & Canada)
activated: true
officer: true

dedguy:
name: James B Seaman
Expand Down

0 comments on commit 86fd0ae

Please sign in to comment.