class WmsWebCma::ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale helper_method :current_agent, :company_branding def current_agent @current_agent ||= (session[:current_agent] ? Agent.find(session[:current_agent]["uuid"]) : nil) end def company_branding @company_branding ||= WmsWebCma::Branding.company(agent_uuid: agent_uuid_for_branding) if current_agent end def logged_in? current_agent end def has_subscription? warn current_agent.subscription('webcma').inspect if current_agent @has_subscription ||= current_agent && current_agent.subscription('webcma').try(:valid) end def has_mld_id? @has_mld_id ||= current_agent && current_agent.mls_agentid.present? end def render_unauthorized(message = "") @message = message render :template => "wms_web_cma/errors/unauthorized", :status => :unauthorized return false end def render_no_mls render :template => "wms_web_cma/errors/no_mls", :status => :unauthorized return false end protected def agent_uuid_for_branding if params[:brand_as].present? agent_uuid = params[:brand_as] else agent_uuid = current_agent.uuid end agent_uuid end private def set_locale I18n.locale = params[:locale] if params[:locale].present? end def default_url_options(options = {}) {locale: I18n.locale} end end