Permalink
Browse files

add API: Session:getUserHash(user)

Signed-off-by: Daogang Tang <daogangtang@gmail.com>
  • Loading branch information...
1 parent 7a22185 commit f6e6f9d73a0c11f9b07cc3c132e3054c84e2b3a8 @daogangtang daogangtang committed May 7, 2012
Showing with 11 additions and 4 deletions.
  1. +2 −2 src/models/user.lua
  2. +9 −2 src/session.lua
View
@@ -74,15 +74,15 @@ 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;
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
@@ -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;

0 comments on commit f6e6f9d

Please sign in to comment.