Sha256: 5506b62cc488e7108cb10bf98a62c98d9d0a746a5234ae0c6dbea23258b92741
Contents?: true
Size: 1.86 KB
Versions: 37
Compression:
Stored size: 1.86 KB
Contents
module Symphonia class LoginController < ApplicationController before_action { menu_item(:login) } def index if current_model.constantize.current.logged_in? return destroy else return new end end def new if current_model.constantize.current.logged_in? return redirect_to(after_login_path) end @model_session = "#{current_model}Session".constantize.new render :new end def create @model_session = "#{current_model}Session".constantize.new(login_session_params) if @model_session.save current_model.constantize.current = @model_session.user redirect_to after_login_path else render :new end end def login_session_params params.require(:login_session).permit(:login, :password, :remember_me).to_h end def destroy current_session && current_session.destroy session.delete :return_to redirect_to '/', notice: t(:text_successfully_logout) end private def current_model raise NotImplementedError end def current_session raise NotImplementedError end def after_login_path path = session[:return_to].presence path ||= Symphonia.config.after_login_path.presence path ||= get_first_menu_item_path(Symphonia::MenuManager.menu(:top_menu).values) || :admin_path case path when Symbol main_app.send(path) when Proc path.call(self) else path end end def get_first_menu_item_path(menu_items) menu_items.detect do |item| if (submenu = item[:children]).present? if (subitem = get_first_menu_item_path(submenu.values)) return subitem break end else item[:if].nil? || item[:if].call end end.try(:[], :url) end end end
Version data entries
37 entries across 37 versions & 1 rubygems