From 86fd0ae0bb39bee31a57d23b37bf5a25815ee6fa Mon Sep 17 00:00:00 2001 From: Jason L Perry Date: Wed, 28 Jan 2009 22:24:39 -0500 Subject: [PATCH] Easier to activate new users --- app/controllers/application.rb | 10 ++++++++++ app/controllers/users_controller.rb | 19 +++++++++++++++++++ app/views/sessions/new.html.erb | 1 + app/views/users/index.html.erb | 2 ++ config/routes.rb | 2 ++ .../20090129025840_add_officer_to_users.rb | 9 +++++++++ db/schema.rb | 3 ++- public/stylesheets/screen.css | 5 +++++ spec/fixtures/users.yml | 1 + 9 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20090129025840_add_officer_to_users.rb diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 1ac76ad..bf8b453 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9adef38..2d1a6ed 100644 --- a/app/controllers/users_controller.rb +++ b/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 @@ -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 diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 0825f49..bf45d5c 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -4,6 +4,7 @@ <% form_tag session_path do %> <%= text_field_tag "openid_url" %> <%= submit_tag "Sign In" %> <% end %> +

New Users: To register, sign in using your OpenID.
If you aren't sure what OpenID is, don't worry, you probably already have one.

diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index bf3235d..3f2cbe8 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -4,12 +4,14 @@ Name Email + <% for user in @users %> <%=h user.name %> <%=h user.email %> + <%= link_to "activate", activate_user_path(user), :method => :put unless user.activated? %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 40c005d..aa5922e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/db/migrate/20090129025840_add_officer_to_users.rb b/db/migrate/20090129025840_add_officer_to_users.rb new file mode 100644 index 0000000..46bf32b --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 73c754a..5ed3456 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -50,6 +50,7 @@ t.datetime "created_at" t.datetime "updated_at" t.boolean "activated", :default => false + t.boolean "officer" end end diff --git a/public/stylesheets/screen.css b/public/stylesheets/screen.css index 59d74d9..d3d420d 100644 --- a/public/stylesheets/screen.css +++ b/public/stylesheets/screen.css @@ -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 { diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index 7f29ece..4471eec 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -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