app/controllers/kblog/articles_controller.rb in kblog-0.0.3 vs app/controllers/kblog/articles_controller.rb in kblog-0.0.4

- old
+ new

@@ -1,19 +1,17 @@ require_dependency "kblog/application_controller" module Kblog class ArticlesController < ::ApplicationController - layout 'kblog/kblog' - before_filter :set_blog_user - before_filter :set_article, only: [:show, :edit, :update, :destroy] - before_filter :authenticate, only: [:edit, :update, :create, :destroy] - - if Kblog.auth_type == 'basic' - http_basic_authenticate_with :name => Kblog.authname, :password => Kblog.authpassword, :except => [:index,:show] - end - - # GET /articles + + layout 'kblog/kblog' + + before_filter :set_blog_user + before_filter :set_article, only: [:show, :edit, :update, :destroy] + before_filter :authenticate, only: [:edit, :update, :create, :destroy] + + # GET /articles def index @articles = Article.order("created_at DESC").paginate(:page => params[:page], :per_page => 3) end # GET /articles/1 @@ -69,15 +67,16 @@ end # Never trust parameters from the scary internet, only allow the white list through. def article_params params[:article] - #params.require(:article).permit(:title, :content) end def authenticate if Kblog.auth_type == 'basic' - http_basic_authenticate_with :name => Kblog.authname, :password => Kblog.authpassword, :except => [:index,:show] + authenticate_or_request_with_http_basic("Kblog-#{Kblog::VERSION}") do |name,pass| + name == Kblog.authname && pass == Kblog.authpassword + end end if Kblog.auth_type == 'role' unless Kblog::Article.user_rights(current_user) logger.warn("#{self.class.name}#authenticate - insufficient rights: user: #{current_user}") redirect_to :back, :notice => 'forbidden'