Esempio n. 1
0
 def get(self):
     user_data = user_db.fetch_user_by_id(self.user_db, self.current_user)
     if user_data:
         self.json_write({
             'success': 1,
             'username': user_data.get('username', '-')
         })
     else:
         self.json_write({'success': 0, 'msg': 'no such user_id'})
Esempio n. 2
0
 def get_current_user(self):
     auth_ = self.get_secure_cookie('auth')
     if not auth_:
         return None
     session_key = str(auth_, 'utf-8')
     if session_key:
         _id = get_redis(session_key, self.redis)
         if not self.allow_plural_login:
             if get_redis(_id, self.redis) != session_key:
                 _id = None
         user_data = user_db.fetch_user_by_id(self.ke_db, _id)
         if user_data:
             return user_data
         else:
             return None
     else:
         return None
Esempio n. 3
0
 def get_current_user(self):
     ip = self.request.remote_ip
     agent = self.request.headers['User-Agent']
     session_key = self.redis.get('{}:{}'.format(ip, agent))
     if session_key:
         username = self.redis.get(session_key)
         if not self.allow_plural_login:
             if self.redis.get(username) != session_key:
                 username = None
         user_data = user_db.fetch_user_by_id(self.user_db, username)
         if user_data:
             self.role = user_data['role']
         else:
             self.role = ''
         return username
     else:
         return None
Esempio n. 4
0
 def get_user_username(self):
     if self.user_name is None:
         user_id = self.get_user_id()
         user_data = user_db.fetch_user_by_id(self.user_db, user_id)
         self.user_username = user_data['username']
     return self.user_name