Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't rely on having an ApplicationController in the root app
Makes things work nicer when using only engines
- Loading branch information
Showing
1 changed file
with
35 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |