本文整理汇总了Python中model.User.find_one方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_one方法的具体用法?Python User.find_one怎么用?Python User.find_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.find_one方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cmd_stats
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_one [as 别名]
def cmd_stats(self, c, e):
nickname = e.payload or e.nick
user = User.find_one({'nickname': nickname})
if not user or not user.games_played or user.games_played == 0:
self.send_msg(message.general.no_games_played, nick=nickname)
return
self.send_msg(self.bot.channel, message.general.games_played, nick=user.nickname, count=user.games_played)
示例2: do_POST
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_one [as 别名]
def do_POST(self):
data = self.rfile.read(int(self.headers['Content-Length']))
if data:
data = parse_qs(data)
for key, value in data.items():
if len(value) == 1: data[key] = value[0]
print "[do_POST] Received data: %s" % data
if self.path in ["/auth", "/update"]:
self.send_response(200)
self.send_header("Content-Type", "text/json; charset=UTF-8")
self.end_headers()
if self.path == "/auth":
if data['request'] == "check":
pass #if config.
elif data['request'] == "auth":
nickname = data['nickname']
if self.client_address[0] not in self.server.auth_requests:
self.server.auth_requests[self.client_address[0]] = []
failure_count = 0
if len(self.server.auth_requests[self.client_address[0]]) > 1:
for request in self.server.auth_requests[self.client_address[0]]:
if (time.time() - request[1]) < (60 * 60): failure_count += 1
if failure_count >= 2:
self.wfile.write("{'status': 'banned'}")
return
self.server.auth_requests[self.client_address[0]].append((nickname, time.time()))
self.server.status[nickname] = "requesting"
self.wfile.write("{'status': '%s'}" % self.server.status[nickname])
self.server.events.on_auth_request(nickname)
elif data['request'] == "update":
nickname = data['nickname']
if nickname not in self.server.status.keys():
self.wfile.write("{'status': 'error'}")
return
if self.server.status[nickname] == "online":
self.wfile.write("{'status': 'requesting'}")
return
if self.server.status[nickname] == "updated":
user = User.find_one({'nickname': nickname})
if user.last_ip_address == self.client_address[0]:
self.server.status[nickname] = "authorized"
else:
self.server.status[nickname] = "denied"
self.wfile.write("{'status': '%s'}" % self.server.status[nickname])
elif self.path == "/update":
name = data['name']
values = data['values[]']
category = getattr(template, data['category'])
setattr(category, name, values)
# update the file
update_template_attribute(category, name, values)
self.wfile.write(json.dumps(values))
示例3: is_authorized
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_one [as 别名]
def is_authorized(self):
user = User.find_one({'last_ip_address': self.client_address[0]})
if user: return True
return False