Module: Devbootcamp::Auth::Helpers
- Defined in:
- lib/devbootcamp/auth/helpers.rb
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #current_user ⇒ Object
- #current_user=(current_user) ⇒ Object
- #deauthenticate! ⇒ Object
- #oauth_sign_in_page_url ⇒ Object
- #setup_devbootcamp_oauth! ⇒ Object
Instance Method Details
#authenticate! ⇒ Object
16 17 18 19 20 21 |
# File 'lib/devbootcamp/auth/helpers.rb', line 16 def authenticate! if Devbootcamp::OAuth.(params[:code]) session[:devbootcamp_oauth_token] = Devbootcamp::OAuth.token_as_hash end authenticated? end |
#authenticated? ⇒ Boolean
8 9 10 |
# File 'lib/devbootcamp/auth/helpers.rb', line 8 def authenticated? !!session[:devbootcamp_oauth_token] end |
#current_user ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/devbootcamp/auth/helpers.rb', line 33 def current_user return nil unless authenticated? return @current_user if @current_user if session[:current_user_attributes] @current_user = Devbootcamp::User.new(session[:current_user_attributes]) else self.current_user = Devbootcamp::User.me end end |
#current_user=(current_user) ⇒ Object
28 29 30 31 |
# File 'lib/devbootcamp/auth/helpers.rb', line 28 def current_user= current_user @current_user = current_user session[:current_user_attributes] = current_user.attributes end |
#deauthenticate! ⇒ Object
23 24 25 26 |
# File 'lib/devbootcamp/auth/helpers.rb', line 23 def deauthenticate! session.delete(:devbootcamp_oauth_token) session.delete(:current_user_attributes) end |
#oauth_sign_in_page_url ⇒ Object
12 13 14 |
# File 'lib/devbootcamp/auth/helpers.rb', line 12 def oauth_sign_in_page_url Devbootcamp::OAuth. end |
#setup_devbootcamp_oauth! ⇒ Object
3 4 5 6 |
# File 'lib/devbootcamp/auth/helpers.rb', line 3 def setup_devbootcamp_oauth! Devbootcamp::OAuth.callback_url = to(oauth_callback_path) Devbootcamp::OAuth.token_from_hash(session[:devbootcamp_oauth_token]) end |