From 2a9769f7d944fb934a772f83c65623d17067650f Mon Sep 17 00:00:00 2001 From: kload Date: Sun, 15 Feb 2015 13:03:01 +0100 Subject: [PATCH] [fix] Load modules as proper modules + typo --- access.lua | 6 +++--- config.lua | 3 ++- helpers.lua | 32 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/access.lua b/access.lua index 5c14571..505daaa 100644 --- a/access.lua +++ b/access.lua @@ -125,7 +125,7 @@ then -- If all the previous cases have failed, redirect to portal else - hlp.flash("info", t("please_login")) + hlp.flash("info", hlp.t("please_login")) return hlp.redirect(conf.portal_url) end @@ -145,7 +145,7 @@ then end else -- Redirect to portal - hlp.flash("fail", t("please_login_from_portal")) + hlp.flash("fail", hlp.t("please_login_from_portal")) return hlp.redirect(conf.portal_url) end end @@ -357,6 +357,6 @@ end -- The default is to protect every URL by default. -- -hlp.flash("info", t("please_login")) +hlp.flash("info", hlp.t("please_login")) local back_url = ngx.var.scheme .. "://" .. ngx.var.host .. ngx.var.uri .. hlp.uri_args_string() return hlp.redirect(conf.portal_url.."?r="..ngx.encode_base64(back_url)) diff --git a/config.lua b/config.lua index 03ac69b..4bfded9 100644 --- a/config.lua +++ b/config.lua @@ -4,6 +4,7 @@ -- This file loads the configuration from config files or default values. -- +module('config', package.seeall) function get_config () @@ -84,7 +85,7 @@ function get_config () conf.lang = ngx.req.get_headers()["Accept-Language"] if conf.lang then - conf.lang = string.sub(lang, 1, 2) + conf.lang = string.sub(conf.lang, 1, 2) end return conf diff --git a/helpers.lua b/helpers.lua index 44c15b1..2ca8f7e 100644 --- a/helpers.lua +++ b/helpers.lua @@ -5,6 +5,7 @@ -- a set of useful functions related to HTTP and LDAP. -- +module('helpers', package.seeall) -- Read a FS stored file function read_file(file) @@ -422,22 +423,6 @@ end -- title, the flash notifications' content and the translated strings. function get_data_for(view) local user = ngx.var.cookie_SSOwAuthUser - local data = {} - - -- Pass all the translated strings to the view (to use with t_) - if conf.lang and i18n[conf.lang] then - translate_table = i18n[conf.lang] - else - translate_table = i18n[conf["default_language"]] - end - for k, v in pairs(translate_table) do - data["t_"..k] = v - end - - -- Pass flash notification content - data['flash_fail'] = {flashs["fail"]} - data['flash_win'] = {flashs["win"] } - data['flash_info'] = {flashs["info"]} -- For the login page we only need the page title if view == "login.html" then @@ -478,6 +463,21 @@ function get_data_for(view) end end + -- Pass all the translated strings to the view (to use with t_) + if conf.lang and i18n[conf.lang] then + translate_table = i18n[conf.lang] + else + translate_table = i18n[conf["default_language"]] + end + for k, v in pairs(translate_table) do + data["t_"..k] = v + end + + -- Pass flash notification content + data['flash_fail'] = {flashs["fail"]} + data['flash_win'] = {flashs["win"] } + data['flash_info'] = {flashs["info"]} + return data end