Sha256: 9b66588be27b35949a0dad1a6d3039f65318fb7ae43316eb794df7061f505006

Contents?: true

Size: 1.09 KB

Versions: 20

Compression:

Stored size: 1.09 KB

Contents

module SessionsHelper

  def sign_in(user)
    remember_token = User.new_remember_token
    cookies.permanent[:remember_token] = remember_token
    user.update_attribute(:remember_token, User.digest(remember_token))
    self.current_user = user
  end

  def signed_in?
    !current_user.nil?
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
    remember_token  = User.digest(cookies[:remember_token])
    @current_user ||= User.find_by(remember_token: remember_token)
  end

  def current_user?(user)
    user == current_user
  end

  def signed_in_user
    unless signed_in?
      store_location
      redirect_to signin_url, notice: "Please sign in."
    end
  end

  def sign_out
    current_user.update_attribute(:remember_token,
                                  User.digest(User.new_remember_token))
    cookies.delete(:remember_token)
    self.current_user = nil
  end

  def redirect_back_or(default)
    redirect_to(session[:return_to] || default)
    session.delete(:return_to)
  end

  def store_location
    session[:return_to] = request.url if request.get?
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
rails_magic_renamer-2.0.0.pre.alpha spec/support/sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.4.2 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.4.1 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.3.2 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.3.1 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.3 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.4 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.3 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.11 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.10 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.9 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.8 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.7 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.6 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.5 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.4 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.3 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.2 sample_app_rails_4/app/helpers/sessions_helper.rb
active_mocker-1.2.pre.1 sample_app_rails_4/app/helpers/sessions_helper.rb