module Challah::Controller

These methods are added into ActionController::Base and are available in all of your app's controllers.

Protected Instance Methods

current_user() click to toggle source

The user that is currently logged into this session. If there is no user logged in, nil will be returned.

@note This method is also available as a helper in your views.

@return [User, nil] The current authenticated user.

# File lib/challah/controller.rb, line 70
def current_user
  @current_user ||= current_user_session.user
end
current_user?() click to toggle source

Is there currently a logged in user? Returns true if it is safe to use the {#current_user current_user} method.

@note This method is also available as a helper in your views.

@see current_user current_user

@return [Boolean] Is there a user logged in?

# File lib/challah/controller.rb, line 54
def current_user?
  !!current_user
end
current_user_session() click to toggle source

The current authentication session, if one exists. A {Session} object will be returned regardless of its valid status. If an invalid session is returned, the {Session#user user} attribute will be nil.

@return [Session] The current browser session.

# File lib/challah/controller.rb, line 79
def current_user_session
  @current_user_session ||= Challah::Session.find(request, params, user_model)
end
logged_in?()
Alias for: signed_in?
login_required()
Alias for: signin_required
signed_in?() click to toggle source

Alias for current_user?

# File lib/challah/controller.rb, line 59
def signed_in?
  current_user?
end
Also aliased as: logged_in?
signin_required() click to toggle source

Restrict a controller to only authenticated users. If someone tries to access a restricted action and is not logged in, they will be redirected to the login page.

This method is an alias for:

restrict_to_authenticated

@example

class YourController < ApplicationController
  before_action :login_required

  # ...
end

@example Specifing certain actions.

class YourOtherController < ApplicationController
  before_action :login_required, :only => [ :create, :update, :destroy ]

  # ...
end

@see Controller::ClassMethods#restrict_to_authenticated restrict_to_authenticated

# File lib/challah/controller.rb, line 106
def signin_required
  unless signed_in?
    session[:return_to] = request.url
    redirect_to signin_path and return
  end
end
Also aliased as: login_required
user_model() click to toggle source
# File lib/challah/controller.rb, line 114
def user_model
  @_challah_user_model ||= Challah.user
end