Module: BravoLock::Controller::Helpers

Defined in:
lib/bravo_lock/controller/helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/bravo_lock/controller/helpers.rb', line 6

def self.included(base)
  base.send :helper_method, :current_user
end

Instance Method Details

#authenticate!Object

used as a before_filter

NOTE: sign_in_path is not recognised from here because this module is included in the main app itself. bravo_lock.sign_in_path would work but that assumes the engine is mounted as :bravo_lock. Another option to is to add a ‘sign_in’ route to the main app pointing to ‘bravo_lock/sessions#new’ but that might break if the controller or action changes. This is a workaround for now



18
19
20
21
22
23
# File 'lib/bravo_lock/controller/helpers.rb', line 18

def authenticate!
  return true if current_user
  session[:redirect] = request.fullpath
  redirect_to :controller => 'bravo_lock/sessions', :action => 'new' # *note
  false
end

#current_userObject

nodoc



27
28
29
# File 'lib/bravo_lock/controller/helpers.rb', line 27

def current_user
  @current_user ||= User.find_by_session_token(session[:user])
end

#verify_and_redirect(token) ⇒ Object

nodoc



33
34
35
36
37
# File 'lib/bravo_lock/controller/helpers.rb', line 33

def verify_and_redirect(token)
  user = BravoLock::Verification.verify! token
  flash[:notice] = I18n.t('flash.bravo_lock.verifications.verified.notice', :default => "Email verified")
  redirect_to (user)
end