Guest User

Untitled

a guest
May 26th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. ## ISSUE - Redirect failing???
  2. Unknown action
  3.  
  4. No action responded to show
  5.  
  6. ## Config
  7. ActionController::Routing::Routes.draw do |map| map.resource :session
  8. map.signup '/signup', :controller => 'users', :action => 'new'
  9. map.login '/login', :controller => 'sessions', :action => 'new'
  10. map.logout '/logout', :controller => 'sessions', :action => 'destroy'
  11. # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
  12. map.root :controller => "site", :action => 'index'
  13.  
  14. #OpenID
  15. map.open_id_complete 'session', :controller => "session", :action => "create", :requirements => { :method => :get }
  16. # See how all your routes lay out with "rake routes"
  17.  
  18. # Install the default routes as the lowest priority.
  19. # Note: These default routes make all actions in every controller accessible via GET requests. You should
  20. # consider removing the them or commenting them out if you're using named routes and resources.
  21. map.connect ':controller/:action/:id'
  22. map.connect ':controller/:action/:id.:format'
  23. end
  24.  
  25. ## SessionsController
  26. # This controller handles the login/logout function of the site.
  27. class SessionsController < ApplicationController
  28. # Be sure to include AuthenticationSystem in Application Controller instead
  29. include AuthenticatedSystem
  30.  
  31. # render new.rhtml
  32. def new
  33. end
  34.  
  35. def create
  36. if using_open_id?
  37. open_id_authentication(params[:openid_url])
  38. else
  39. password_authentication(params[:login], params[:password])
  40. end
  41. end
  42.  
  43. def destroy
  44. self.current_user.forget_me if logged_in?
  45. cookies.delete :auth_token
  46. reset_session
  47. flash[:notice] = "You have been logged out."
  48. redirect_to('/')
  49. end
  50.  
  51. protected
  52.  
  53. def open_id_authentication(openid_url)
  54. authenticate_with_open_id(openid_url, :required => [:nickname, :email]) do |result, identity_url, registration|
  55. if result.successful?
  56. @user = User.find_or_initialize_by_identity_url(identity_url)
  57. if @user.new_record?
  58. @user.login = registration['nickname']
  59. @user.email = registration['email']
  60. @user.save(false)
  61. end
  62. self.current_user = @user
  63. successful_login
  64. else
  65. failed_login result.message
  66. end
  67. end
  68. end
  69.  
  70. def password_authentication(login, password)
  71. self.current_user = User.authenticate(login, password)
  72. if logged_in?
  73. successful_login
  74. else
  75. failed_login
  76. end
  77. end
  78.  
  79. def failed_login(message = "Authentication failed.")
  80. flash.now[:error] = message
  81. render :action => 'new'
  82. end
  83.  
  84. def successful_login
  85. if params[:remember_me] == "1"
  86. self.current_user.remember_me
  87. cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
  88. end
  89. redirect_to('/')
  90. flash[:notice] = "Logged in successfully"
  91. end
  92. end
Add Comment
Please, Sign In to add comment