Skip to content

Commit

Permalink
Don't rely on having an ApplicationController in the root app
Browse files Browse the repository at this point in the history
Makes things work nicer when using only engines
  • Loading branch information
jdtornow committed Sep 1, 2015
1 parent c2bf472 commit ead4ba9
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions app/controllers/sessions_controller.rb
@@ -1,42 +1,44 @@
class SessionsController < ApplicationController
before_filter :destroy_session, except: :create
if defined?(ApplicationController)
class SessionsController < ApplicationController
before_filter :destroy_session, except: :create

unloadable
unloadable

# GET /login
# GET /sign-in
def new
@session = Challah::Session.new(request)
end

# POST /login
# POST /sign-in
def create
@session = Challah::Session.new(request, params[:session])
@session.ip = request.remote_ip
# GET /login
# GET /sign-in
def new
@session = Challah::Session.new(request)
end

if @session.save
redirect_to return_to_path
else
redirect_to signin_path, alert: I18n.translate('sessions.create.failed_login')
# POST /login
# POST /sign-in
def create
@session = Challah::Session.new(request, params[:session])
@session.ip = request.remote_ip

if @session.save
redirect_to return_to_path
else
redirect_to signin_path, alert: I18n.translate('sessions.create.failed_login')
end
end
end

# GET /logout
# GET /sign-out
def destroy
redirect_to signin_path
end
# GET /logout
# GET /sign-out
def destroy
redirect_to signin_path
end

protected
protected

def destroy_session
current_user_session.destroy
end
def destroy_session
current_user_session.destroy
end

def return_to_path(default_path = '/')
result = session[:return_to]
result = nil if result and result == "http://#{request.domain}/"
result || default_path
def return_to_path(default_path = '/')
result = session[:return_to]
result = nil if result and result == "http://#{request.domain}/"
result || default_path
end
end
end
end

0 comments on commit ead4ba9

Please sign in to comment.