2011-05-11 13:38:46 +02:00
|
|
|
class SessionsController < ApplicationController
|
|
|
|
|
|
|
|
skip_before_filter :authenticate
|
|
|
|
layout 'login'
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
user = User.authenticate(params[:nick], params[:password])
|
|
|
|
if user
|
|
|
|
session[:user_id] = user.id
|
2012-08-24 19:52:38 +02:00
|
|
|
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
|
2013-07-18 16:23:29 +02:00
|
|
|
session[:locale] = user.locale
|
|
|
|
|
2012-12-30 16:34:01 +01:00
|
|
|
if session[:return_to].present?
|
|
|
|
redirect_to_url = session[:return_to]
|
|
|
|
session[:return_to] = nil
|
|
|
|
else
|
|
|
|
redirect_to_url = root_url
|
|
|
|
end
|
2013-02-04 02:00:27 +01:00
|
|
|
redirect_to redirect_to_url, :notice => I18n.t('sessions.logged_in')
|
2011-05-11 13:38:46 +02:00
|
|
|
else
|
2014-10-09 09:42:13 +02:00
|
|
|
flash.now.alert = I18n.t(FoodsoftConfig[:use_nick] ? 'sessions.login_invalid_nick' : 'sessions.login_invalid_email')
|
2011-05-11 13:38:46 +02:00
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
session[:user_id] = nil
|
2014-01-03 19:42:08 +01:00
|
|
|
session[:return_to] = nil
|
2013-02-05 12:30:44 +01:00
|
|
|
redirect_to login_url, :notice => I18n.t('sessions.logged_out')
|
2011-05-11 13:38:46 +02:00
|
|
|
end
|
2014-01-15 16:24:49 +01:00
|
|
|
|
|
|
|
# redirect to root, going to default foodcoop when none given
|
|
|
|
# this may not be so much session-related, but it must be somewhere
|
|
|
|
def redirect_to_foodcoop
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
|
2011-05-11 13:38:46 +02:00
|
|
|
end
|