local ngx = require("ngx")
local resty_redis = require("resty.redis")
local resty_cookie = require("resty.cookie")
local cjson = require("cjson")
local notFilterUrlMap={
['/mimosaui/login.html'] ="login"--not check url
}
local redis=resty_redis:new()
redis:set_timeout(1000)
ok,err = redis:connect("192.168.23.21","6379")
if not ok then
ngx.log(ngx.ERR,"failed to connect to redis:",err)
end
-- auth
ok, err = redis:get_reused_times()
if 0 == ok then
local ok, err = redis:auth("goooUO4056")
if not ok then
ngx.say("failed to authenticate: ", err)
return
end
elseif err then
ngx.say("failed to get_reused_times: ", err)
end
local login_url='/mimosaui/redirect.html';
local uid='';
local function getuid()
local cookie=resty_cookie:new()
uid=cookie:get("SESSION")
if not uid then
return nil
end
ngx.log(ngx.ERR,"uid is =====",uid)
local res,err=redis:exists("spring:session:sessions:expires:"..uid)
ngx.log(ngx.ERR,"hget==",res)
if res == 0 then
ngx.log(ngx.ERR,"uid is missing,return nil")
return nil;
else
return uid
end
return nil
end
local _url=ngx.var.uri
ngx.log(ngx.ERR,"url=:",_url)
_url=notFilterUrlMap[_url]
if not _url then
uid= getuid();
end
redis:set_keepalive(10000,100)
ngx.log(ngx.ERR,tostring(uid))
if uid == nil then
ngx.log(ngx.ERR,"uid is missing,redirect",login_url)
--ngx.location.capture("/operate/admin/info")
-- ngx.req.set_uri(login_url,true)
ngx.redirect(login_url)
-- local result = {errorCode=10002,errorMessage=""}
-- ngx.header.content_type="application/json"
-- ngx.say(cjson.encode(result))
end
分享到:
相关推荐
java+redis+lua实现重复提交操作拦截.防止出现同一数据在同一时间被操作多次。实现基于aop和注解。
lua实现 basse64 lua lua实现 basse64 lua lua实现 basse64 lua
lua实现webservice调用 通过gsoap 实现 C/C++ 调用web service
1、简单工厂模式lua实现 2、工厂方法模式lua实现 3、原型模式lua实现 4、建造者模式lua实现 5、单例模式lua实现 6、抽象工厂模式lua实现 结构型模式 1、装饰模式lua实现 2、代理模式lua实现 3、外观模式lua实现 4、...
Lua实现跟py的sleep一样的定时器功能,在倒计时结束时调用函数
cocos2d-lua 实现富文本
解析Lua实现方法 解析Lua实现方法
cocos2dx 虚拟摇杆的lua实现
MVVM源于MVC(Model-View-Controller)模式,...MVVM本质就是基于操作数据来操作视图进而操作DOM,借助于MVVM无需直接操作DOM,开发者只需完成包含声明绑定的视图模板,编写ViewModel中有业务,使得View完全实现自动化。
自己写的中文笔划输入法算法演示程序,用Lua实现的,大家看看有没有参考价值,呵呵
用LUA实现在stm32平台上的在线编程
汉诺塔是一种经典的题目,用很多种语言均可实现。 本例子是用lua实现汉诺塔
Lua实现PureMVC
Lua实现OOP,可以继承,覆盖,sample里面实现了简单的lua类定义,并封装了简单的事件驱动机制
NGINX + LUA实现复杂的控制
Lua语言实现特殊字符过滤,对于使用Lua开发移动端游戏的童鞋非常常用。代码亲测有效,附使用实例
使用lua构建的字符菜单界面,与C交互,并使用消息队列传送用户选择的菜单选项, 形成一个独立的字符菜单模块,可以编译成login替代系统的login程序,嵌入式开发首选技术~~
A* 算法使用Lua实现,保存起来,以后再看。
使用lua实现的一个2048小程序,实现了2048的基本功能。