Home arrow Ruby-on-Rails arrow Page 3 - Securing the Login for a Rails Ecommerce Application
RUBY-ON-RAILS

Securing the Login for a Rails Ecommerce Application


In the first part of this four-part series we started to learn about security for an ecommerce application in Ruby-on-Rails. In this second part we're going to test some of what we did in the first part, and implement some important login features. This article is excerpted from chapter eight of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
June 17, 2010
TABLE OF CONTENTS:
  1. · Securing the Login for a Rails Ecommerce Application
  2. · Implementing the Fail Log In User Story
  3. · Adding the Flash Message
  4. · Adding Login Links and Styling

print this article
SEARCH DEVARTICLES

Securing the Login for a Rails Ecommerce Application - Adding the Flash Message
(Page 3 of 4 )

Openapp/controllers/account_controller.rband add the flash message to show for failed logins:

class AccountController < ApplicationController
 
# If you want "remember me" functionality, add this before_filter to➥
Application Controller
 
before_filter :login_from_cookie

  # say something nice, you goof! something sweet.
  def index
    redirect_to(:action => 'signup') unless logged_in? || User.count > 0
  end

  def login
    return unless request.post?
    self.current_user = User.authenticate(params[:login], params[:password])
    if current_user
     
if params[:remember_me] == "1"
        self.current_user.remember_me
        cookies[:auth_token] = { :value => self.current_user.remember_token ,➥
:expires => self.current_user.remember_token_expires_at }
      end
      redirect_back_or_default(:controller => '/account', :action => 'index')
      flash[:notice] = "Logged in successfully"
    
end
    
flash.now[:notice] = "Incorrect login!"
 
end
...

Running the test again shows all green, so try it out in the browser. Figure 8-2 shows the result. As you can see, the plugin is doing its job.


Figure 8-2.  A failed login


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials