From 13065aa85aea1ee73e3641972efdf8ab5c99d37c Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Thu, 4 Mar 2010 16:33:26 +0800 Subject: [PATCH] Add devise gem and panel/users controller --- app/controllers/admin/assets_controller.rb | 1 + .../admin/components_controller.rb | 1 + app/controllers/admin/items_controller.rb | 3 + app/controllers/admin/layouts_controller.rb | 1 + app/controllers/admin/links_controller.rb | 1 + app/controllers/admin/pages_controller.rb | 1 + app/controllers/admin/snippets_controller.rb | 1 + app/controllers/panel/users_controller.rb | 47 ++++++++ app/models/item.rb | 2 +- app/models/user.rb | 6 ++ app/views/layouts/admin.html.erb | 2 +- app/views/layouts/panel.html.erb | 45 ++++++++ app/views/panel/users/_form.html.erb | 9 ++ app/views/panel/users/edit.html.erb | 18 ++++ app/views/panel/users/index.html.erb | 24 +++++ app/views/panel/users/new.html.erb | 18 ++++ config/environment.rb | 1 + config/environments/development.rb | 4 +- config/initializers/devise.rb | 102 ++++++++++++++++++ config/locales/devise.en.yml | 35 ++++++ config/locales/zh_tw.yml | 7 +- config/routes.rb | 3 + lib/tasks/dev.rake | 3 + 23 files changed, 331 insertions(+), 4 deletions(-) create mode 100644 app/controllers/panel/users_controller.rb create mode 100644 app/models/user.rb create mode 100644 app/views/layouts/panel.html.erb create mode 100644 app/views/panel/users/_form.html.erb create mode 100644 app/views/panel/users/edit.html.erb create mode 100644 app/views/panel/users/index.html.erb create mode 100644 app/views/panel/users/new.html.erb create mode 100644 config/initializers/devise.rb create mode 100644 config/locales/devise.en.yml diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index 61ef4d9bc..74879184b 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -1,6 +1,7 @@ class Admin::AssetsController < ApplicationController layout "admin" + before_filter :authenticate_user! def show @asset = Asset.find(params[:id]) diff --git a/app/controllers/admin/components_controller.rb b/app/controllers/admin/components_controller.rb index fda62c9ac..07abc7117 100644 --- a/app/controllers/admin/components_controller.rb +++ b/app/controllers/admin/components_controller.rb @@ -1,6 +1,7 @@ class Admin::ComponentsController < ApplicationController layout "admin" + before_filter :authenticate_user! before_filter :find_parent_item def show diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index ad472502d..72cb995c2 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -1,6 +1,9 @@ class Admin::ItemsController < ApplicationController layout "admin" + + before_filter :authenticate_user! + before_filter :find_parent_item before_filter :find_snippets, :only => :index diff --git a/app/controllers/admin/layouts_controller.rb b/app/controllers/admin/layouts_controller.rb index 67cfda2bc..f9ff63112 100644 --- a/app/controllers/admin/layouts_controller.rb +++ b/app/controllers/admin/layouts_controller.rb @@ -1,6 +1,7 @@ class Admin::LayoutsController < ApplicationController layout "admin" + before_filter :authenticate_user! def index @layouts = Layout.all diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb index 71ac9f3b9..b3ae0b78e 100644 --- a/app/controllers/admin/links_controller.rb +++ b/app/controllers/admin/links_controller.rb @@ -1,6 +1,7 @@ class Admin::LinksController < ApplicationController layout "admin" + before_filter :authenticate_user! before_filter :find_parent_item def show diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 5ac4bf717..179f775b3 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -1,6 +1,7 @@ class Admin::PagesController < ApplicationController layout "admin" + before_filter :authenticate_user! before_filter :find_parent_item def show diff --git a/app/controllers/admin/snippets_controller.rb b/app/controllers/admin/snippets_controller.rb index 2f8ad933f..57a2f09e5 100644 --- a/app/controllers/admin/snippets_controller.rb +++ b/app/controllers/admin/snippets_controller.rb @@ -1,6 +1,7 @@ class Admin::SnippetsController < ApplicationController layout "admin" + before_filter :authenticate_user! before_filter :find_parent_item def show diff --git a/app/controllers/panel/users_controller.rb b/app/controllers/panel/users_controller.rb new file mode 100644 index 000000000..1a0123b2a --- /dev/null +++ b/app/controllers/panel/users_controller.rb @@ -0,0 +1,47 @@ +class Panel::UsersController < ApplicationController + + layout "panel" + before_filter :authenticate_user! + + def index + @users = User.all + end + + def show + @user = User.find(params[:id]) + end + + def new + @user = User.new + end + + def create + @user = User.new(params[:user]) + if @user.save + redirect_to :action => :index + else + render :action => :new + end + end + + def edit + @user = User.find(params[:id]) + end + + def update + @user = User.find(params[:id]) + if @user.update_attributes(params[:user]) + redirect_to :action => :index + else + render :action => :edit + end + end + + def destroy + @user = User.find(params[:id]) + @user.destroy + + redirect_to :action => :index + end + +end diff --git a/app/models/item.rb b/app/models/item.rb index eb63113cf..d9091c31f 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -47,7 +47,7 @@ class Item def setup_default_value if self.position.blank? - max_page = Page.find(:last, :order => 'position') + max_page = Page.last(:order => 'position') self.position = (max_page)? max_page.position.to_i + 1 : 1 end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..5ce3f0d8c --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User + include MongoMapper::Document + + devise :authenticatable, :recoverable, :rememberable, :trackable + +end \ No newline at end of file diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 063430adb..7f2ea76c1 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -16,7 +16,7 @@