Module: Hobo::OpenidController
- Defined in:
- lib/openid_controller.rb
Instance Method Summary collapse
-
#hobo_openid_complete(options = {}) ⇒ Object
:*_notice - failure, cancellation, setup_needed, new_user_failure.
-
#hobo_openid_login(request, options = {}) ⇒ Object
Login action for controller.
- #openid_logout(options = {}) ⇒ Object
Instance Method Details
#hobo_openid_complete(options = {}) ⇒ Object
:*_notice - failure, cancellation, setup_needed, new_user_failure
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/openid_controller.rb', line 44 def hobo_openid_complete(={}) .reverse_merge!(:success_notice => "You have logged in", :failure_notice => "Verification failed", :cancellation_notice => "Verification cancelled", :setup_needed_notice => "OpenID server reports setup is needed", :new_user_failure_notice => "Could not create a new user account", :redirect_to => { :controller => "front", :action => "index"}, :model => User, :openid_field => :openid, :mappings => []) user = nil current_url = url_for(:action => 'complete_openid', :only_path => false) # un-munge params array parameters = params.reject{|k,v|request.path_parameters[k]} response = openid_consumer.complete parameters, current_url case response.status when OpenID::Consumer::SUCCESS openid = response.identity_url user = model.first :conditions => { [:openid_field] => openid } if user #user exists hobo_openid_complete_user_exists(user, ) else hobo_openid_complete_new_user(response, openid, ) end when OpenID::Consumer::FAILURE flash[:notice] = [:failure_notice] when OpenID::Consumer::CANCEL flash[:notice] = [:cancellation_notice] when OpenID::Consumer::SETUP_NEEDED flash[:notice] = [:setup_needed_notice] else flash[:notice] = "Unknown response from OpenID server." end redirect_to :action => :openid_login unless performed? end |
#hobo_openid_login(request, options = {}) ⇒ Object
Login action for controller. Parameters: Recognized options are:
:model - class of your user model (default User)
:login - field of params where users provide openIDs (default :login)
:return_to - page to return
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/openid_controller.rb', line 11 def hobo_openid_login(request, = {}) .reverse_merge!(:success_notice => "You have logged in", :failure_notice => "Verification failed", :cancellation_notice => "Verification cancelled", :setup_needed_notice => "OpenID server reports setup is needed", :new_user_failure_notice => "Could not create a new user account", :redirect_to => { :controller => "front", :action => "index" }, :model => User, :openid_field => :openid, :mappings => []) .reverse_merge!(:return_to => url_for(:action => :complete_openid), :model => User, :login => :login) return unless request.post? openid = params[[:login]] begin oidreq = openid_consumer.begin openid rescue => e flash[:error] = "Discovery failed: #{e}" redirect_to homepage(request) and return end redirect_to oidreq.redirect_url(homepage(request), [:return_to]) end |
#openid_logout(options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/openid_controller.rb', line 90 def openid_logout(={}) = .reverse_merge(:notice => "You have been logged out.", :redirect_to => base_url) current_user.forget_me if logged_in? .delete :auth_token reset_session flash[:notice] = [:notice] redirect_back_or_default([:redirect_to]) end |