Skip to content

Commit

Permalink
Inactive User is redirected to Registration#review after successful l…
Browse files Browse the repository at this point in the history
…ogin
  • Loading branch information
adomokos committed Jul 13, 2010
1 parent 5f18ebe commit 9b99944
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 34 deletions.
15 changes: 8 additions & 7 deletions app/controllers/accounts_controller.rb
Expand Up @@ -2,11 +2,11 @@ class AccountsController < ApplicationController

before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => [:show, :edit, :update]

def new
@account = Account.new
end

def create
@account = Account.new(params[:account])
if @account.save
Expand All @@ -15,22 +15,23 @@ def create
render :action => :new
end
end

def show
@account = @current_user
end

def edit
@account = @current_user
end

def update
@account = @current_user # makes our views "cleaner" and more consistent
if @account.update_attributes(params[:user])
redirect_to account_url
else
render :action => :edit
end
end
end

end

2 changes: 2 additions & 0 deletions app/controllers/registrations_controller.rb
Expand Up @@ -43,11 +43,13 @@ def start_over
end

def review
=begin
if (@current_user == nil)
redirect_to new_registration_path
elsif @current_user.active
redirect_to '/'
end
=end
# logger.info("The current_user is #{@current_user}")
end

Expand Down
43 changes: 36 additions & 7 deletions app/controllers/user_sessions_controller.rb
Expand Up @@ -2,23 +2,52 @@ class UserSessionsController < ApplicationController

before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy

def new
@user_session = UserSession.new
end

def create
@user_session = UserSession.new(params[:user_session])

# validate_users_without_authlogic_magic_states

unless (is_valid_without_authlogic_magic_states?)
render :action => :new
return
end

if (!user_account_active?)
redirect_to registration_review_path
return
end

if @user_session.save
redirect_back_or_default account_url
else
render :action => :new
#account = Account.find_by_login(@user_session.login)
#redirect_to registration_review_path unless account.active?
#return
end
end

def destroy
current_user_session.destroy
redirect_back_or_default new_user_session_url
end

end

private
def is_valid_without_authlogic_magic_states?
UserSession.disable_magic_states = true
@user_session.validate
result = @user_session.valid?
UserSession.disable_magic_states = false
result
end

def user_account_active?
account = Account.find_by_login(@user_session.login)
return account.active
end

end

3 changes: 2 additions & 1 deletion app/models/account.rb
Expand Up @@ -2,6 +2,8 @@

class Account < ActiveRecord::Base

attr_accessible :login, :email, :password, :active

belongs_to :user
has_one :registration

Expand All @@ -12,6 +14,5 @@ class Account < ActiveRecord::Base
c.validate_password_field = true
c.perishable_token_valid_for = 5.minutes
end

end

5 changes: 3 additions & 2 deletions app/models/user_session.rb
@@ -1,5 +1,6 @@
class UserSession < Authlogic::Session::Base

authenticate_with Account
generalize_credentials_error_messages true
generalize_credentials_error_messages true
end

23 changes: 23 additions & 0 deletions features/step_definitions/user_login_steps.rb
Expand Up @@ -18,5 +18,28 @@
account.active = true
account.save!
end

end

Given /^the following inactive user records in the data store$/ do |table|
registration_converter = ConvertsRegistrationToAccountInformation.new
table.hashes.each do |hash|
registration = Registration.new(hash)
registration.password_confirmation = hash["password"]

# add address info
user_address = Factory(:user_address)
registration.address = user_address.address
registration.address2 = user_address.address2
registration.city = user_address.city
registration.state = user_address.state_code
registration.zip = user_address.zip

registration_converter.do_it(registration)
# Activate the account for now...
account = Account.find_by_login(hash["login"])
account.active = false
account.save!
end
end

8 changes: 6 additions & 2 deletions features/support/paths.rb
Expand Up @@ -7,16 +7,19 @@ module NavigationHelpers
#
def path_to(page_name)
case page_name

when /the home\s?page/
'/'

when /the user registration page/
new_registration_path

when /the user login page/
new_user_session_path

when /the registration review page/
registration_review_path

when /the user account page/
account_path
# Add more mappings here.
Expand All @@ -33,3 +36,4 @@ def path_to(page_name)
end

World(NavigationHelpers)

14 changes: 12 additions & 2 deletions features/user_login.feature
Expand Up @@ -19,8 +19,8 @@ Feature: Login Users

Scenario: User should be able to successfully log in
Given the following user records in the data store
| first_name | last_name | email_address | login | password | password_confirmation |
| John | Doe | jdoe@gmail.com | jdoe | password | password |
| first_name | last_name | email_address | login | password |
| John | Doe | jdoe@gmail.com | jdoe | password |
And I go to the user login page
And I fill in "Login" with "jdoe"
And I fill in "Password" with "password"
Expand All @@ -38,3 +38,13 @@ Feature: Login Users
When I go to the home page
Then I should see "jsmith"

Scenario: Inactive user is redirected to registration review after log in
Given the following inactive user records in the data store
| first_name | last_name | email_address | login | password |
| John | Doe | jdoe@gmail.com | jdoe | password |
And I am on the user login page
And I fill in "Login" with "jdoe"
And I fill in "Password" with "password"
When I press "Log In"
Then I should be on the registration review page

13 changes: 0 additions & 13 deletions spec/controllers/registrations_controller_spec.rb
Expand Up @@ -95,19 +95,6 @@
end
end

context "activates the user" do
it "redirects to the registration index page when the user is not logged in" do
get 'review'
response.should redirect_to new_registration_path
end

it "redirects to the registration index page when the user is active and logged in" do
@current_user = Factory.build(:user)
get 'review'
response.should redirect_to new_registration_path
end
end

it "clears the session info when the start_over action is called" do
session["registration_params"] = {"first_name" => "John"}
session["registration_step"] = "personal_info"
Expand Down

0 comments on commit 9b99944

Please sign in to comment.