Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add API: Session:getUserHash(user)

Signed-off-by: Daogang Tang <daogangtang@gmail.com>
  • Loading branch information...
commit f6e6f9d73a0c11f9b07cc3c132e3054c84e2b3a8 1 parent 7a22185
@daogangtang daogangtang authored
Showing with 11 additions and 4 deletions.
  1. +2 −2 src/models/user.lua
  2. +9 −2 src/session.lua
View
4 src/models/user.lua
@@ -74,7 +74,7 @@ local User = Model:extend {
if not authed then return nil end
Session:setKey('user_id', self:classname() + ':' + user.id)
- Session:hashReversely(user, req.session_id)
+ Session:userHash(user, req.session_id)
return user
end;
@@ -82,7 +82,7 @@ local User = Model:extend {
logout = function (self)
-- I_AM_CLASS(self)
-- Class and instance can both call this function
- Session:delHashReversely(user)
+ Session:delUserHash(user)
return Session:delKey('user_id')
end;
View
11 src/session.lua
@@ -182,12 +182,19 @@ local Session = Object:extend {
return session_t
end;
- hashReversely = function (self, user, session_id)
+ userHash = function (self, user, session_id)
local user_id = format("%s:%s", user:classname(), user.id)
db:hset('_users_sessions', user_id, session_id)
end;
+
+ getUserHash = function (self, user)
+ local user = user or req.uesr
+ assert(user, '[Error] @Session getUserHash - user is nil.')
+ local user_id = format("%s:%s", user:classname(), user.id)
+ return db:hget('_users_sessions', user_id)
+ end;
- delHashReversely = function (self, user)
+ delUserHash= function (self, user)
local user_id = format("%s:%s", user:classname(), user.id)
db:hdel('_users_sessions', user_id)
end;
Please sign in to comment.
Something went wrong with that request. Please try again.