Permalink
Browse files

Restrict access

  • Loading branch information...
1 parent 66a87a5 commit 36a6cf30ef40461d6f550d52629a2c2a4058858b Anatoliy Chakkaev committed May 12, 2011
@@ -0,0 +1,17 @@
+loadUser = ->
+ if req.headers.authorization and req.headers.authorization.search('Basic ') == 0
+ creds = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString()
+ if creds == app.config.admin
+ req.session.user = true
+ @user = !!req.session.user
+ next()
+
+before loadUser
+
+publish 'userRequired', ->
+ if @user
+ next()
+ else
+ console.log 'Unable to authenticate user ' + req.headers.authorization
+ response.header 'WWW-Authenticate', 'Basic realm="Admin Area"'
+ send 'Authentication required', 401
@@ -1,3 +1,5 @@
+load('application')
+
action("page", function () {
var path = req.params[0];
var page = Page.index[path];
@@ -1,3 +1,7 @@
+load 'application'
+
+before use 'userRequired'
+
loadPage = ->
Page.findById req.params.id, (err, page) =>
if err or !page
@@ -11,13 +11,15 @@
<h1 class="title">
<%= page.title %>
</h1>
+ <% if (user) { %>
+ <%- link_to('Edit', edit_page(page)) %>
+ <% } %>
</div>
<div class="menu">
<%- menu(page) %>
</div>
<div class="content">
<%- body %>
- <%- link_to('Edit', edit_page(page)) %>
</div>
</div>
</body>
View
@@ -30,7 +30,7 @@
desc "Symlink config files"
task :symlink_configs, :roles => :app do
- %w[app_config.yml database.json].each do |f|
+ %w[app_config.yml].each do |f|
run "ln -sf #{shared_path}/config/#{f} #{release_path}/config/#{f}"
end
end
@@ -80,4 +80,4 @@
before 'deploy:setup', 'deploy:create_deploy_to_with_sudo'
after 'deploy:setup', 'deploy:write_upstart_script'
-after "deploy:finalize_update", "deploy:cleanup", "deploy:update_submodules"#, "deploy:symlink_configs", "deploy:check_packages"
+after "deploy:finalize_update", "deploy:cleanup", "deploy:update_submodules", "deploy:symlink_configs"#, "deploy:check_packages"
@@ -0,0 +1,5 @@
+app.config = require('yaml').eval(
+ require('fs')
+ .readFileSync(app.root + '/config/app_config.yml')
+ .toString()
+)[app.settings.env || 'development'];

0 comments on commit 36a6cf3

Please sign in to comment.