Module: OAuthCampingPlugin::Helpers
- Defined in:
- lib/camping-oauth.rb
Overview
Helpers module for OAuth Camping Plugin. The module will be plugged in to the main app Helpers module. Its methods will be added to Controllers and Views. Example: module CampingOAuthProvider::Helpers extend OAuthCampingPlugin::Helpers include OAuthCampingPlugin::Helpers end
Instance Method Summary collapse
-
#access_denied ⇒ Object
Redirects to the login page with an access denied error message.
-
#app_module ⇒ Object
Reverse engineers the main app module.
-
#current_user ⇒ Object
Returns the current user model instance.
-
#log_debug(msg) ⇒ Object
Logs a specific message if in debug mode.
-
#login_required ⇒ Object
Returns whether or not the user is logged in Typically used within a controller before filter such as in: before :OAuthRegisterApplication do login_required end.
-
#nonce_class ⇒ Object
Reverse engineers the main OauthNonce model class.
-
#set_user ⇒ Object
Looks up the user based on saved state (if any) and assigns it to the @user variable.
-
#user_class ⇒ Object
Reverse engineers the main User model class.
Instance Method Details
#access_denied ⇒ Object
Redirects to the login page with an access denied error message
408 409 410 411 412 |
# File 'lib/camping-oauth.rb', line 408 def access_denied @state.return_to = @request.url @info = 'Oops. You need to login before you can view that page.' redirect('/login') end |
#app_module ⇒ Object
Reverse engineers the main app module
367 368 369 370 |
# File 'lib/camping-oauth.rb', line 367 def app_module app_module_name = self.class.to_s.split("::").first app_module = app_module_name.constantize end |
#current_user ⇒ Object
Returns the current user model instance
392 393 394 |
# File 'lib/camping-oauth.rb', line 392 def current_user @user end |
#log_debug(msg) ⇒ Object
Logs a specific message if in debug mode
362 363 364 |
# File 'lib/camping-oauth.rb', line 362 def log_debug(msg) OAuthCampingPlugin.logger.debug(msg) if OAuthCampingPlugin.logger && OAuthCampingPlugin.logger.debug? end |
#login_required ⇒ Object
Returns whether or not the user is logged in Typically used within a controller before filter such as in: before :OAuthRegisterApplication do login_required end
401 402 403 404 405 |
# File 'lib/camping-oauth.rb', line 401 def login_required return true if @user access_denied return false end |
#nonce_class ⇒ Object
Reverse engineers the main OauthNonce model class
380 381 382 383 384 |
# File 'lib/camping-oauth.rb', line 380 def nonce_class app_module_name = self.class.to_s.split("::").first nonce_class_name = "#{app_module_name}::Models::OauthNonce" nonce_class_name.constantize end |
#set_user ⇒ Object
Looks up the user based on saved state (if any) and assigns it to the @user variable
387 388 389 |
# File 'lib/camping-oauth.rb', line 387 def set_user @user = user_class.find(@state.user_id) if @user.nil? && !@state.nil? && !@state.user_id.nil? end |
#user_class ⇒ Object
Reverse engineers the main User model class
373 374 375 376 377 |
# File 'lib/camping-oauth.rb', line 373 def user_class app_module_name = self.class.to_s.split("::").first user_class_name = "#{app_module_name}::Models::User" user_class_name.constantize end |