Permalink
Browse files

basic authentication on server-side added (part 2)

  • Loading branch information...
1 parent 7108934 commit 8716b2a71eba823166ea7057322c105e7b9eb566 @sectore committed Jan 11, 2012
Showing with 50 additions and 59 deletions.
  1. +2 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +11 −1 README.md
  4. +13 −0 app/controllers/application_controller.rb
  5. +16 −3 app/views/layouts/application.html.erb
  6. +4 −55 config/routes.rb
  7. +2 −0 db/seeds.rb
View
@@ -7,6 +7,8 @@ gem 'rails', '3.1.1'
gem 'sqlite3'
+gem "bcrypt-ruby", :require => "bcrypt"
+
# Gems used only for assets and not required
# in production environments by default.
View
@@ -31,6 +31,7 @@ GEM
multi_json (~> 1.0)
ansi (1.4.1)
arel (2.2.1)
+ bcrypt-ruby (3.0.1)
builder (3.0.0)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
@@ -109,6 +110,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ bcrypt-ruby
coffee-rails (~> 3.1.1)
jquery-rails
rails (= 3.1.1)
View
@@ -12,7 +12,17 @@ coming soon
coming soon
##Local installation
-coming soon
+1) Open Terminal
+
+ git clone git://github.com/sectore/CafeTownsend-Angular-Rails.git
+ cd CafeTownsend-Angular-Rails
+ bundle install
+ rake db:migrate
+ rake db:seed
+ rails server
+
+2) Open [http://localhost:3000](http://localhost:3000/) within [Chrome](https://www.google.com/chrome)
+
##Author
Jens Krause // [WEBSECTOR.DE](http://www.websector.de)
@@ -1,3 +1,16 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ helper_method :current_user, :logged_in?
+
+ private
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+
+ def logged_in?
+ current_user != nil
+ end
+
+
end
@@ -6,9 +6,22 @@
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
-<body>
-<%= yield %>
+<body class="<%= params[:controller] %>">
+
+<div id="user_nav">
+ <% if logged_in? %>
+ Hello <%= current_user.name %>.
+ <%= link_to "Log out", logout_path %>
+ <% else %>
+ <%= link_to "log in", login_path %>
+ <% end %>
+</div>
+
+<% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+<% end %>
-</body>
+<%= yield %>
</html>
+
View
@@ -1,58 +1,7 @@
CafeTownsendAngularRails::Application.routes.draw do
- # The priority is based upon order of creation:
- # first created -> highest priority.
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => 'welcome#index'
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+ get "logout" => "sessions#destroy", :as => "logout"
+ get "login" => "sessions#new", :as => "login"
+ root :to => "sessions#new"
+ resources :sessions
end
View
@@ -5,3 +5,5 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+User.create!(name: 'Luke', password: 'Skywalker')

0 comments on commit 8716b2a

Please sign in to comment.