module Fiona7 class SessionsController < ActionController::Base before_filter :load_login_page def create login, password = params[:login], params[:password] if valid_credentials?(login, password) rsession.user_name = login redirect_to login_redirect else flash[:error] = I18n.t(:"fiona7.invalid_credentails") begin redirect_to :back rescue ActionController::RedirectBackError redirect_to scrivito_path(@login_page) end end end def destroy rsession.destroy begin redirect_to :back rescue ActionController::RedirectBackError redirect_to true_root_path end end protected def load_login_page @login_page = Fiona7LoginPage.instance || Scrivito::BasicObj.root end def login_redirect session[:login_redirect].presence || true_root_path end def true_root_path if Fiona7.mode == :standalone '/' elsif Fiona7.mode == :legacy root_path else raise "Invalid Fiona7.mode = #{Fiona7.mode}" end end def valid_credentials?(login, password) Reactor::Sudo.su(Fiona7.root) do Reactor::Cm::User.new(login).has_password?(password) end rescue Reactor::Cm::XmlRequestError => e Rails.logger.error("Error logging in: #{e.message}") false end end end