2011-05-11 13:38:46 +02:00
|
|
|
class SessionsController < ApplicationController
|
2019-10-28 21:11:35 +01:00
|
|
|
skip_before_action :authenticate
|
2011-05-11 13:38:46 +02:00
|
|
|
layout 'login'
|
2018-12-31 16:02:04 +01:00
|
|
|
|
2011-05-11 13:38:46 +02:00
|
|
|
def new
|
2018-12-31 16:02:04 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
2011-05-11 13:38:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
user = User.authenticate(params[:nick], params[:password])
|
|
|
|
if user
|
2015-03-03 14:55:30 +01:00
|
|
|
user.update_attribute(:last_login, Time.now)
|
2017-09-22 01:14:48 +02:00
|
|
|
login_and_redirect_to_return_to user, :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
|
2013-06-15 02:04:44 +02:00
|
|
|
logout
|
2023-03-30 10:05:47 +02:00
|
|
|
if FoodsoftConfig[:logout_redirect_url].present?
|
|
|
|
redirect_to FoodsoftConfig[:logout_redirect_url]
|
|
|
|
else
|
|
|
|
redirect_to login_url, :notice => I18n.t('sessions.logged_out')
|
|
|
|
end
|
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
|