Permalink
Browse files

adding warden

  • Loading branch information...
1 parent 1b81483 commit f3e224ad94124c21583aab1ccc3083a56167b3ad Robert Sosinski committed Mar 17, 2012
View
@@ -7,8 +7,11 @@ gem 'rails', '3.2.2'
gem 'pg'
gem 'json'
gem 'rjson'
-gem 'devise', '~> 2.0.4'
+
+gem 'warden', '~> 1.1.1'
gem 'bcrypt-ruby', '~> 3.0.0'
+
+gem 'simple_form', '~> 2.0.1'
gem 'whenever', :require => false
group :assets do
View
@@ -46,11 +46,6 @@ GEM
columnize (0.3.4)
commonjs (0.2.0)
therubyracer (~> 0.9.9)
- devise (2.0.4)
- bcrypt-ruby (~> 3.0)
- orm_adapter (~> 0.0.3)
- railties (~> 3.1)
- warden (~> 1.1.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.3.0)
@@ -82,7 +77,6 @@ GEM
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
- orm_adapter (0.0.6)
pg (0.13.2)
polyglot (0.3.3)
rack (1.4.1)
@@ -128,6 +122,9 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
+ simple_form (2.0.1)
+ actionpack (~> 3.0)
+ activemodel (~> 3.0)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -154,7 +151,6 @@ PLATFORMS
DEPENDENCIES
bcrypt-ruby (~> 3.0.0)
- devise
factory_girl_rails
json
less (~> 2.0.10)
@@ -163,5 +159,7 @@ DEPENDENCIES
rjson
rspec-rails!
ruby-debug
+ simple_form (~> 2.0.1)
uglifier
+ warden (~> 1.1.1)
whenever
@@ -4,6 +4,7 @@
//= require knockout-2.0.0
//= require cookies
+//= require rails
//= require ko
//= require_self
@@ -1,2 +1,6 @@
class ApplicationController < ActionController::Base
+ def warden
+ env['warden']
+ end
+ helper_method :warden
end
@@ -1,2 +1,26 @@
class Root::SessionsController < Root::NamespaceController
+ def show
+ render :text => session.inspect
+ end
+
+ def new
+ end
+
+ def create
+ warden.authenticate!
+
+ render :text => session.inspect
+ end
+
+ def destroy
+ warden.logout
+
+ render :text => session.inspect
+ end
+
+ def failure
+ flash.now[:error] = warden.message
+
+ render :new
+ end
end
@@ -1,2 +1,7 @@
class Root::UsersController < Root::NamespaceController
+ def new
+ end
+
+ def create
+ end
end
View
@@ -1,14 +1,21 @@
class User < ActiveRecord::Base
has_secure_password
- attr_accessible :name, :password, :password_confirmation
+ attr_accessible :username, :password, :password_confirmation
has_many :tasks
- validates :name, :presence => true,
- :uniqueness => true,
- :format => { :with => /^[a-z0-9]{3,10}$/, :message => "must be 3 to 10 lower-case letters or numbers" }
+ validates :username, :presence => true,
+ :uniqueness => true,
+ :format => { :with => /^[a-z0-9]{3,10}$/, :message => "must be 3 to 10 lower-case letters or numbers" }
validates :password, :confirmation => true,
:format => { :with => /^([\x20-\x7E]){6,}$/, :message => "must be 3 or more characters" }
+
+
+ def self.authenticate(username, password)
+ find_by_username!(username).authenticate(password)
+ rescue
+ false
+ end
end
@@ -0,0 +1,18 @@
+<div class="navbar-inner">
+ <div class="container">
+ <%= link_to "Kiv7", root_path, :class => "brand" %>
+ <ul class="nav">
+ <li>
+ <%= link_to "About", pages_path(:action => :about) %>
+ </li>
+ <li>
+ <%= link_to "Admin", admin_stats_path %>
+ </li>
+ </ul>
+ <ul class="nav pull-right">
+ <li>
+ <%= link_to "Logout", sessions_path, :method => :delete %>
+ </li>
+ </ul>
+ </div>
+</div>
@@ -0,0 +1,18 @@
+<div class="navbar-inner">
+ <div class="container">
+ <%= link_to "Kiv7", root_path, :class => "brand" %>
+ <ul class="nav">
+ <li>
+ <%= link_to "About", pages_path(:action => :about) %>
+ </li>
+ </ul>
+ <ul class="nav pull-right">
+ <li>
+ <%= link_to "Login", new_sessions_path %>
+ </li>
+ <li>
+ <%= link_to "Signup", new_users_path %>
+ </li>
+ </ul>
+ </div>
+</div>
@@ -0,0 +1,15 @@
+<div class="navbar-inner">
+ <div class="container">
+ <%= link_to "Kiv7", root_path, :class => "brand" %>
+ <ul class="nav">
+ <li>
+ <%= link_to "About", pages_path(:action => :about) %>
+ </li>
+ </ul>
+ <ul class="nav pull-right">
+ <li>
+ <%= link_to "Logout", sessions_path, :method => :delete %>
+ </li>
+ </ul>
+ </div>
+</div>
@@ -10,33 +10,27 @@
<body>
<div id="navbar" class="navbar navbar-fixed-top">
- <div class="navbar-inner">
- <div class="container">
- <a class="brand" href="#">Kiv7</a>
- <ul class="nav">
- <li>
- <a href="#">About</a>
- </li>
- <li>
- <a href="#">Lists</a>
- </li>
- <li>
- <a href="#">Account</a>
- </li>
- </ul>
- <form class="navbar-search pull-left">
- <input type="text" class="search-query" placeholder="Filter Tasks">
- </form>
- <ul class="nav pull-right">
- <li>
- <a href="#">Logout</a>
- </li>
- </ul>
- </div>
- </div>
+ <% if warden.authenticated? %>
+ <% if warden.user.admin? %>
+ <%= render :partial => 'root/layouts/admin_nav' %>
+ <% else %>
+ <%= render :partial => 'root/layouts/user_nav' %>
+ <% end %>
+ <% else %>
+ <%= render :partial => 'root/layouts/guest_nav' %>
+ <% end %>
</div>
<div id="content" class="container">
+ <% if flash.any? %>
+ <% flash.each do |type, message| %>
+ <%= content_tag :div, :class => ["alert", "alert-#{type}"] do%>
+ <a class="close" data-dismiss="alert">×</a>
+ <strong><%= message %></strong>
+ <% end %>
+ <% end %>
+ <% end %>
+
<%= yield %>
</div>
</body>
@@ -1 +1,6 @@
-<h1>About</h1>
+<div class="page-header">
+ <h1>
+ About
+ <small>the site you are looking at, right now</small>
+ </h1>
+</div>
@@ -1 +1,6 @@
-<h1>Welcome<h1>
+<div class="page-header">
+ <h1>
+ Welcome
+ <small>to a useful task-tracking application</small>
+ </h1>
+</div>
@@ -0,0 +1,15 @@
+<div class="page-header">
+ <h1>
+ Login
+ <small>if you already have an account</small>
+ </h1>
+</div>
+
+<%= simple_form_for :session, :url => sessions_path, :html => { :class => "form-horizontal" } do |form| %>
+ <%= form.input :username %>
+ <%= form.input :password %>
+
+ <%= content_tag :div, :class => "form-actions" do %>
+ <%= form.button :submit, :value => "Login", :class => "btn-primary" %>
+ <% end %>
+<% end %>
Oops, something went wrong.

0 comments on commit f3e224a

Please sign in to comment.