Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

all the work I did on the weekend

  • Loading branch information...
commit 380e2708e96727c162bd06112efc1e2716148aa0 1 parent 40fe5e0
unknown authored
View
12 app/controllers/application_controller.rb
@@ -4,7 +4,17 @@
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
-
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
+
+ private
+ def authenticate
+ session[:login_counter] = 0 if session[:login_counter].blank?
+ session[:realm] = session[:session_id].to_s + '_' + session[:login_counter].to_s if session[:realm].blank?
+ authenticate_or_request_with_http_basic(session[:realm]) do |user_name, password|
+ if user_name == 'admin' && password == 'password'
+ session[:current_user] = user_name
+ end
+ end
+ end
end
View
15 app/controllers/categories_controller.rb
@@ -1,4 +1,14 @@
class CategoriesController < ApplicationController
+ before_filter :authenticate, :except => [:index, :show]
+ before_filter :define_back_link, :except => [:index]
+
+ def logout
+ session[:login_counter] = session[:login_counter]
+ session[:realm] = session[:session_id].to_s + '_' + session[:login_counter].to_s
+ session[:current_user] = nil
+ redirect_to root_url
+ end
+
# GET /categories
# GET /categories.xml
def index
@@ -82,4 +92,9 @@ def destroy
format.xml { head :ok }
end
end
+
+ private
+ def define_back_link
+ @back_link = categories_path
+ end
end
View
9 app/controllers/categorizations_controller.rb
@@ -1,4 +1,7 @@
class CategorizationsController < ApplicationController
+ before_filter :authenticate, :except => [:show]
+ before_filter :define_back_link
+
%w{move_higher move_lower move_to_top move_to_bottom}.each do |action|
define_method action do
@categorization = Categorization.find(params[:id])
@@ -39,4 +42,10 @@ def destroy
@categorization.destroy
redirect_to(edit_category_path(@category))
end
+
+ private
+ def define_back_link
+ @category = Category.find(params[:category_id])
+ category_path(@category)
+ end
end
View
2  app/controllers/websites_controller.rb
@@ -1,4 +1,6 @@
class WebsitesController < ApplicationController
+ before_filter :authenticate
+
# GET /websites
# GET /websites.xml
def index
View
3  app/helpers/application_helper.rb
@@ -1,3 +1,6 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
+ def current_user
+ session[:current_user]
+ end
end
View
12 app/views/categories/index.html.erb
@@ -1,12 +1,10 @@
-<div id="header">
- <h1>Sitepro Portfolio</h1>
-</div>
-<% if false %>
- <p style="color: green"><%= flash[:notice] %></p>
-<% end %>
<ul>
<% @categories.each do |category| %>
<li><%= link_to category.name, category %></li>
<% end %>
</ul>
-<%= link_to 'New category', new_category_path %>
+<% if current_user == 'admin' %>
+ <%= link_to 'New category', new_category_path %>
+<% end %>
+
+<%= session.inspect %>
View
4 app/views/categories/show.html.erb
@@ -1,7 +1,3 @@
-<div id="header">
- <%= link_to 'Back', categories_path, :class => 'nav', :id => 'backButton' %>
- <h1>Sitepro Portfolio</h1>
-</div>
<h1><%=h @category.name %></h1>
<ul>
<% for categorization in @category.categorizations %>
View
5 app/views/categorizations/show.html.erb
@@ -1,8 +1,3 @@
-<div id="header">
- <%= link_to 'Back', category_path(@category), :class => 'nav', :id => 'backButton' %>
- <h1>Sitepro Portfolio</h1>
-</div>
-
<h1><%=h @website.title %></h1>
<br />
<img alt="" src="<%=h @website.image %>" />
View
25 app/views/layouts/application.html.erb
@@ -1,16 +1,21 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
- <title><%= controller.action_name %></title>
- <%= stylesheet_link_tag 'iphone' %>
- <%= javascript_include_tag :defaults %>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title><%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'iphone' %>
+ <%= javascript_include_tag :defaults %>
</head>
<body>
-
-<%= yield %>
-
+ <div id="header">
+ <% if defined? @back_link %>
+ <%= link_to 'Back', @back_link, :class => 'nav', :id => 'backButton' %>
+ <% end %>
+ <h1>Sitepro Portfolio</h1>
+ </div>
+ <% if false %>
+ <p style="color: green"><%= flash[:notice] %></p>
+ <% end %>
+ <%= yield %>
</body>
</html>
View
2  config/routes.rb
@@ -2,6 +2,8 @@
map.resources :websites
map.resources :categories, :has_many => :categorizations, :collection => { :move_higher => :post }
+ map.logout "/logout", {:controller => "categories", :action => "logout"}
+
%w{move_higher move_lower move_to_top move_to_bottom}.each do |action|
instance_eval <<-EOF
map.#{action}_category_categorization "categories/:category_id/categorizations/:id/#{action}", {:controller => "categorizations", :action => "#{action}"}
View
4,622 log/development.log
4,622 additions, 0 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.