Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## ISSUE - Redirect failing???
- Unknown action
- No action responded to show
- ## Config
- ActionController::Routing::Routes.draw do |map| map.resource :session
- map.signup '/signup', :controller => 'users', :action => 'new'
- map.login '/login', :controller => 'sessions', :action => 'new'
- map.logout '/logout', :controller => 'sessions', :action => 'destroy'
- # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
- map.root :controller => "site", :action => 'index'
- #OpenID
- map.open_id_complete 'session', :controller => "session", :action => "create", :requirements => { :method => :get }
- # See how all your routes lay out with "rake routes"
- # Install the default routes as the lowest priority.
- # Note: These default routes make all actions in every controller accessible via GET requests. You should
- # consider removing the them or commenting them out if you're using named routes and resources.
- map.connect ':controller/:action/:id'
- map.connect ':controller/:action/:id.:format'
- end
- ## SessionsController
- # This controller handles the login/logout function of the site.
- class SessionsController < ApplicationController
- # Be sure to include AuthenticationSystem in Application Controller instead
- include AuthenticatedSystem
- # render new.rhtml
- def new
- end
- def create
- if using_open_id?
- open_id_authentication(params[:openid_url])
- else
- password_authentication(params[:login], params[:password])
- end
- end
- def destroy
- self.current_user.forget_me if logged_in?
- cookies.delete :auth_token
- reset_session
- flash[:notice] = "You have been logged out."
- redirect_to('/')
- end
- protected
- def open_id_authentication(openid_url)
- authenticate_with_open_id(openid_url, :required => [:nickname, :email]) do |result, identity_url, registration|
- if result.successful?
- @user = User.find_or_initialize_by_identity_url(identity_url)
- if @user.new_record?
- @user.login = registration['nickname']
- @user.email = registration['email']
- @user.save(false)
- end
- self.current_user = @user
- successful_login
- else
- failed_login result.message
- end
- end
- end
- def password_authentication(login, password)
- self.current_user = User.authenticate(login, password)
- if logged_in?
- successful_login
- else
- failed_login
- end
- end
- def failed_login(message = "Authentication failed.")
- flash.now[:error] = message
- render :action => 'new'
- end
- def successful_login
- 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_to('/')
- flash[:notice] = "Logged in successfully"
- end
- end
Add Comment
Please, Sign In to add comment