Permalink
Browse files

finished with sessions

  • Loading branch information...
kuloshius committed Jul 4, 2011
1 parent d59fd60 commit 08e781637f4f7ac681de0041902134d9ff897831
View
@@ -2,5 +2,8 @@ Autotest.add_hook :initialize do |autotest|
autotest.add_mapping(%r%^spec/(requests)/.*rb$%) do|filename, _|
filename
end
+# autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do
+# autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)
+# end
end
View
1 .rspec
@@ -1,3 +1,2 @@
--colour
--drb
-
View
14 Gemfile
@@ -1,17 +1,21 @@
source 'http://rubygems.org'
-gem 'rails'
+gem 'rails', '3.0.9'
gem 'mysql2', '0.2.11'
gem 'jquery-rails'
gem 'bcrypt-ruby', :require => 'bcrypt'
group :development do
- gem 'rspec-rails'
- gem 'faker'
+ gem 'rspec-rails', '2.6.1'
+ gem 'faker', '0.3.1'
+ gem 'annotate-models', '1.0.4'
+ gem 'ruby-debug19'
end
group :test do
- gem 'rspec'
+ gem 'rspec-rails', '2.6.1'
gem 'spork', '~> 0.9.0.rc'
- gem 'webrat'
+ gem 'webrat', '0.7.1'
+ gem 'factory_girl_rails', '1.0'
+ gem 'ruby-debug19'
end
View
@@ -28,26 +28,34 @@ GEM
activemodel (= 3.0.9)
activesupport (= 3.0.9)
activesupport (3.0.9)
+ annotate-models (1.0.4)
+ archive-tar-minitar (0.5.2)
arel (2.0.10)
bcrypt-ruby (2.1.4)
builder (2.1.2)
+ columnize (0.3.3)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
- faker (0.9.5)
- i18n (~> 0.4)
+ factory_girl (1.3.3)
+ factory_girl_rails (1.0)
+ factory_girl (~> 1.3)
+ rails (>= 3.0.0.beta4)
+ faker (0.3.1)
i18n (0.5.0)
jquery-rails (1.0.12)
railties (~> 3.0)
thor (~> 0.14)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mysql2 (0.2.11)
- nokogiri (1.4.6)
+ nokogiri (1.5.0)
polyglot (0.3.1)
rack (1.2.3)
rack-mount (0.6.14)
@@ -69,7 +77,7 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.4)
rake (0.9.2)
- rdoc (3.7)
+ rdoc (3.8)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
@@ -83,12 +91,22 @@ GEM
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.6.0)
- spork (0.9.0.rc8)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
+ spork (0.9.0.rc9)
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.29)
- webrat (0.7.3)
+ webrat (0.7.1)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
@@ -97,12 +115,14 @@ PLATFORMS
ruby
DEPENDENCIES
+ annotate-models (= 1.0.4)
bcrypt-ruby
- faker
+ factory_girl_rails (= 1.0)
+ faker (= 0.3.1)
jquery-rails
mysql2 (= 0.2.11)
- rails
- rspec
- rspec-rails
+ rails (= 3.0.9)
+ rspec-rails (= 2.6.1)
+ ruby-debug19
spork (~> 0.9.0.rc)
- webrat
+ webrat (= 0.7.1)
@@ -1,10 +1,5 @@
class ApplicationController < ActionController::Base
protect_from_forgery
- helper_method :current_user
-
- private
-
- def current_user
- @current_user ||= User.find(session[:user_id]) if session[:user_id]
- end
+ include SessionsHelper
+ before_filter :authenticate
end
@@ -1,13 +1,17 @@
class SessionsController < ApplicationController
+ skip_before_filter :authenticate, :only => [:new, :create]
+
def new
+ @title = "Sign in"
end
def create
user = User.authenticate(params[:email], params[:password])
if user
session[:user_id] = user.id
- redirect_to root_url, :notice => "Logged in!"
+ redirect_to user, :notice => "Logged in!"
else
+ @title = "Sign in"
flash.now.alert = "Invalid email or password"
render "new"
end
@@ -1,15 +1,8 @@
class UsersController < ApplicationController
- def new
- @user = User.new
- end
-
- def create
- @user = User.new(params[:user])
- if @user.save?
- redirect_to root_url, :notice => "Signed up!"
- else
- render "new"
- end
+ def show
+ @title = "SLP | Home"
+ @user = current_user
+ @company = Company.new
end
end
@@ -11,5 +11,5 @@ def title
def app_name
"SLP"
end
-
+
end
@@ -1,2 +1,11 @@
module SessionsHelper
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+
+ def authenticate
+ redirect_to(root_path) unless current_user
+ end
+
end
View
@@ -12,15 +12,14 @@
#
class User < ActiveRecord::Base
- attr_accessible :email, :password
+ attr_accessible :email, :password, :password_confirmation
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
- validates_presence_of :password, :on => :create
- validates_presence_of :email
- validates_uniqueness_of :email
+ validates_presence_of :password, :password_confirmation, :email
+ validates_uniqueness_of :email, :case_sensitive => false
def self.authenticate(email, password)
user = find_by_email(email)
@@ -1,4 +0,0 @@
-<p>
- <%= app_name %> is a project to make lifes easier for one's operating in waste industry
- with <a href="http://rubyonrails.org/">Ruby on Rails</a>.
-</p>
@@ -1,4 +0,0 @@
-<p>
- Suggestions? Bugs?
- <a href="mailto:tomas@ebox.lt"> Let me know!</a>
-</p>
@@ -1,3 +0,0 @@
-<p>
- This is help page. If you need any help with <%= app_name %>, <a href="http://www.google.com">click here</a>
-</p>
@@ -1,3 +0,0 @@
-<p>
- This is the home page.
-</p>
@@ -1,5 +1,5 @@
<h1>Log in</h1>
-<% form_tag sessions_path do %>
+<%= form_tag sessions_path do %>
<p>
<%= label_tag :email %><br />
<%= text_field_tag :email, params[:email] %>
@@ -9,4 +9,4 @@
<%= password_field_tag :password %>
</p>
<p class="button"><%= submit_tag "Log in" %>
-<% end -%>
+<% end %>
View
@@ -8,10 +8,5 @@ module Grays
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
- if Rails.env.test?
- initializer :after => :initialize_dependency_mechanism do
- ActiveSupport::Dependencies.mechanism = :load
- end
- end
end
end
@@ -32,5 +32,4 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
- config.action_mailer.default_url_options = {:host => 'localhost:3000'}
end
@@ -1,8 +0,0 @@
-ActionMailer::Base.smtp_settings = {
- :address => "smtp.bit.lt",
- :port => '25',
- :domain => "mydomain.com",
- :authentication => :plain,
- :user_name => "tomas@ebox.lt",
- :password => "tomopastas"
-}
@@ -1,39 +0,0 @@
-en:
- errors:
- messages:
- not_found: "not found"
- already_confirmed: "was already confirmed"
- not_locked: "was not locked"
-
- devise:
- failure:
- unauthenticated: 'You need to sign in or sign up before continuing.'
- unconfirmed: 'You have to confirm your account before continuing.'
- locked: 'Your account is locked.'
- invalid: 'Invalid email or password.'
- invalid_token: 'Invalid authentication token.'
- timeout: 'Your session expired, please sign in again to continue.'
- inactive: 'Your account was not activated yet.'
- sessions:
- signed_in: 'Signed in successfully.'
- signed_out: 'Signed out successfully.'
- passwords:
- send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
- updated: 'Your password was changed successfully. You are now signed in.'
- confirmations:
- send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
- confirmed: 'Your account was successfully confirmed. You are now signed in.'
- registrations:
- signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.'
- updated: 'You updated your account successfully.'
- destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
- unlocks:
- send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
- unlocked: 'Your account was successfully unlocked. You are now signed in.'
- mailer:
- confirmation_instructions:
- subject: 'Confirmation instructions'
- reset_password_instructions:
- subject: 'Reset password instructions'
- unlock_instructions:
- subject: 'Unlock Instructions'
View
@@ -1,13 +1,12 @@
Grays::Application.routes.draw do
+ get "users/show"
+
get "log_out" => "sessions#destroy", :as => "log_out"
get "log_in" => "sessions#new", :as => "log_in"
root :to => "sessions#new"
- resources :sessions
-
-
- match '/contact', :to => 'pages#contact'
- match '/about', :to => 'pages#about'
- match '/help', :to => 'pages#help'
+ resources :sessions, :only => [:new, :create, :destroy]
+ resources :users, :only => [:show]
+
Oops, something went wrong.

0 comments on commit 08e7816

Please sign in to comment.