本文整理汇总了Python中database.User.select方法的典型用法代码示例。如果您正苦于以下问题:Python User.select方法的具体用法?Python User.select怎么用?Python User.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.User
的用法示例。
在下文中一共展示了User.select方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def prepare(self):
domain_query = DomainLogs.select().where(DomainLogs.domain == self.request.host).first()
if not domain_query:
user = User.select().where(User.domain == self.request.host.split(".")[-3]).first()
if not user:
return
domain_query = DomainLogs()
domain_query.user_id = user.id
domain_query.domain = self.request.host
domain_query.save()
log = DNSLogs()
log.ip = self.request.headers.get('X-Forwarded-For')
log.user_id = user.id
log.domain_id = domain_query.id
log.save()
if not self.request.uri == "/favicon.ico":
log = UrlLogs()
packet = "%s %s %s\n" % (self.request.method, self.request.uri, self.request.version)
for header in self.request.headers:
packet += "%s: %s\n" % (header, self.request.headers.get(header))
packet += "\n%s" % self.request.body
log.url = self.request.uri
log.ip = self.request.headers.get("X-Forwarded-For")
log.domain_id = domain_query.id
log.user_id = domain_query.user_id
log.packet = packet
log.save()
示例2: handleUserJoin
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def handleUserJoin(obj):
if not obj['joined']: return
u = RUser(obj['u'], 0, r)
if u.isOnline() and not u.getCurrentServer()['sid'] == obj['sid']: #If the user is online, kick them from the first server
push(obj['sid'], {"a": "kick", "u": obj['u'], "msg": "User joined another server..."})
u.joinServer(obj['sid'])
u.addServerHistory(obj['sid'])
# Join Message
q = User.select().where(User.username == obj['u'])
if not q.count():
packs = [{"a": "sendto", "user": obj['u'], "msg": i} for i in need_reg_msgs]
push(obj['sid'], packs)
return
resp = [
{"a": "sendto", "user": obj['u'], "msg": "{C_RED}{C_ITALIC}Your user level has been synced."},
{"a": "user_level", "user": obj['u'], "level": q[0].level}]
push(obj['sid'], resp)
msg = [{"a": "sendto", "user": None, "msg": "{C_AQUA}%s {C_GOLD}{C_ITALIC}has joined %s" % (q[0].username, u.getCurrentServer()['name'])}]
for fr in q[0].getFriends():
tmp = RUser(fr.username, fr.id, r)
if tmp.perma['CFG_NOTI_FRIEND_JOIN'] is False: continue
if tmp.isOnline():
msg[0]['user'] = tmp.name
push(tmp.getCurrentServer()['sid'], msg)
示例3: loginRoute
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def loginRoute():
if not 'user' in request.form.keys() or not 'pw' in request.form.keys():
return flashy('/', 'All fields must be filled in!', 'error')
q = [i for i in User.select().where(User.username == request.form.get('user'))]
if not len(q):
return flashy('/', 'No such user with that name!', 'error')
if bcrypt.hashpw(request.form.get('pw'), q[0].password) == q[0].password:
session['logged'] = True
session['uid'] = q[0].id
return flashy('/', 'You have been logged in!', 'success')
return flashy('/', 'Invalid password!', 'error')
示例4: handleUserQuit
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def handleUserQuit(obj):
u = RUser(obj['u'], 0, r)
u.quitServer(obj['sid'])
q = User.select().where(User.username == obj['u'])
if not q.count(): return
msg = [{"a": "sendto", "user": None, "msg": "{C_AQUA}%s {C_GOLD}{C_ITALIC}has left %s" % (q[0].username, u.getServerInfo(u.getLastServer()['sid'])['name'])}]
for fr in q[0].getFriends():
tmp = RUser(fr.username, fr.id, r)
if tmp.perma['CFG_NOTI_FRIEND_QUIT'] is False: continue
if tmp.isOnline():
msg[0]['user'] = tmp.name
push(tmp.getCurrentServer()['sid'], msg)
示例5: beforeRequest
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def beforeRequest():
g.user = None
g.uid = -1
g.state = STATE
if request.path.startswith("/static"):
return
# Normal session
if request.cookies.get("sid"):
s = Session.find(request.cookies.get("sid"))
if s:
# Eventually we should be lazily loading this in, or cacheing it at redis
try:
g.user = User.select().where(User.id == s['user']).get()
g.uid = g.user.id
except User.DoesNotExist:
resp = flashy("Wow! Something really went wrong. Contact support!")
resp.set_cookie('sid', '', expires=0)
return resp
示例6: start_qvq
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def start_qvq(domain, ip):
domain = "%s." % domain
qvqdns = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
qvqdns.bind(('', 53))
try:
print ("QvQDNS is listening on 0.0.0.0:53\n")
while 1:
data, addr = qvqdns.recvfrom(1024)
try:
p = DNSQuery(data)
except:
p = None
pass
if p and p.dominio.endswith(domain):
qvqdns.sendto(p.respuesta(ip), addr)
print("%s------%s" % (p.dominio[:-1], addr[0]))
user = User.select().where(User.domain == p.dominio.split(domain)[0].split(".")[-1]).first()
if user:
domain_query = DomainLogs.select().where(DomainLogs.domain == p.dominio[:-1]).first()
if not domain_query:
domain_query = DomainLogs()
domain_query.user_id = user.id
domain_query.domain = p.dominio[:-1]
domain_query.save()
log = DNSLogs()
log.ip = addr[0]
log.user_id = user.id
log.domain_id = domain_query.id
log.save()
else:
print("%s------%s" % (p.dominio[:-1], addr[0]))
try:
result = domain_to_ip(p.dominio[:-1])
qvqdns.sendto(p.respuesta(result[0]), addr)
except:
pass
del p
except KeyboardInterrupt:
qvqdns.close()
print ("QvQDNS is closed!")
示例7: test
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def test(id):
g.user = User.select().where(User.id == id).get()
g.uid = g.user.id
resp = flashy("Welcome back %s!" % g.user.username, "success")
resp.set_cookie("sid", g.user.login(), expires=time.time() + Session.LIFETIME)
return resp
示例8: get_have_count
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import select [as 别名]
def get_have_count(self):
# TODO: move this to stats/cache
from database import User
return User.select().where(User.badges.contains(self.id)).count()