foodsoft/app/controllers/sessions_controller.rb

39 lines
991 B
Ruby
Raw Normal View History

class SessionsController < ApplicationController
skip_before_filter :authenticate
layout 'login'
def new
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)
login user
if session[:return_to].present?
redirect_to_url = session[:return_to]
session[:return_to] = nil
else
redirect_to_url = root_url
end
redirect_to redirect_to_url, :notice => I18n.t('sessions.logged_in')
else
flash.now.alert = I18n.t(FoodsoftConfig[:use_nick] ? 'sessions.login_invalid_nick' : 'sessions.login_invalid_email')
render "new"
end
end
def destroy
logout
2013-02-05 12:30:44 +01:00
redirect_to login_url, :notice => I18n.t('sessions.logged_out')
end
# 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
end