Skip to content

Commit

Permalink
11 Add Basic Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
id774 committed Sep 21, 2012
1 parent 1f57d33 commit 557284b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/controllers/blogs_controller.rb
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

class BlogsController < ApplicationController
before_filter :authenticate if Auth.basic_auth
#before_filter :authenticate_user!

# GET /blogs
Expand Down Expand Up @@ -42,6 +43,14 @@ def update
end
end
end

private
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == Auth.username &&
password == Auth.password
end
end
end

class BootstrapPaginationRenderer < WillPaginate::ActionView::LinkRenderer
Expand Down
17 changes: 17 additions & 0 deletions app/models/auth.rb
@@ -0,0 +1,17 @@
class Auth < ActiveRecord::Base

class << self
def username
USERNAME
end

def password
PASSWORD
end

def basic_auth
BASIC_AUTH
end
end

end
3 changes: 3 additions & 0 deletions config/initializers/environment.rb
@@ -0,0 +1,3 @@
USERNAME = "your_username"
PASSWORD = "your_password"
BASIC_AUTH = false

0 comments on commit 557284b

Please sign in to comment.