本文整理汇总了Python中model.User.exist方法的典型用法代码示例。如果您正苦于以下问题:Python User.exist方法的具体用法?Python User.exist怎么用?Python User.exist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.exist方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clientRegister
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import exist [as 别名]
def clientRegister(self, data):
try:
rdata = {}
username = data['username']
if not username:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(username, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
if len(username) > 50:
self.sendAPI(1,449,'Value exceeds maximum input length')
return
user = User(username)
if user.exist():
self.sendAPI(1,441,'Credentials already exist')
return
user.token = self.getNewToken()
user.password = self.getNewPassword()
user.save()
rdata['password'] = user.password
self.sendAPI(0,241,'User registered',rdata)
except (KeyError, TypeError):
self.sendAPI(1,401,'Not in reference format')
示例2: clientLastOnline
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import exist [as 别名]
def clientLastOnline(self, data):
try:
rdata = {}
username = data['username']
if not username:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(username, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
contact = User(username)
if contact.exist():
rdata['last_online'] = unicode(contact.lastonline.replace(microsecond=0))
for user in self.factory.clients:
if user.name == contact.name:
rdata['last_online'] = 'now'
self.sendAPI(0,226,'Last online returned',rdata)
else:
self.sendAPI(1,405,'Credentials invalid')
except (KeyError, TypeError):
self.sendAPI(1,401,'Not in reference format')
示例3: clientGetContactList
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import exist [as 别名]
def clientGetContactList(self, data):
try:
rdata = {}
rcontacts = []
if self.authenticated:
self.user.update()
if data:
for contact in data['contacts']:
ccontact = contact['contact']
if not ccontact:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(ccontact, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
contactuser = User(ccontact)
if contactuser.exist():
self.user.addContact(contactuser)
for contact in self.user.getContactList():
rcontacts.append({'contact':contact.name})
if len(rcontacts):
rdata['contacts'] = rcontacts
self.sendAPI(0,211,'Contact list send',rdata)
else:
self.sendAPI(1,410,'User unauthorized')
except (KeyError, TypeError):
self.sendAPI(1,401,'Not in reference format')
示例4: clientDeleteContact
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import exist [as 别名]
def clientDeleteContact(self, data):
try:
if self.authenticated:
self.user.update
for contact in data['contacts']:
ccontact = contact['contact']
if not ccontact:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(ccontact, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
contactuser = User(ccontact)
if contactuser.exist():
self.user.deleteContact(contactuser)
self.sendAPI(0,276,'Contacts deleted')
else:
self.sendAPI(1,410,'User unauthorized')
except (KeyError, TypeError):
self.sendAPI(1,401,'Not in reference format')
示例5: clientMessage
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import exist [as 别名]
def clientMessage(self, data):
try:
rdata = {}
cdata = {}
if self.authenticated:
self.user.update()
cipher = data['cipher']
if not cipher:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(cipher, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
if cipher not in ['AES', 'PLAIN']:
self.sendAPI(1,417,'Cipher not supported')
return
message = data['message']
if not message:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(message, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
timestamp = data['timestamp']
if not timestamp:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(timestamp, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
contact = data['username']
if not contact:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(contact, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
contactuser = User(contact)
if contactuser.exist():
rmessage = Message(uuid.uuid1().time_low)
rmessage.user = self.user
rmessage.contact = contactuser
rmessage.message = message
rmessage.cipher = cipher
rmessage.timestamp = timestamp
self.factory.messages.append(rmessage)
cdata['session'] = rmessage.session
for other in self.factory.clients:
if contactuser.name == other.name:
rdata['username'] = self.user.name
rdata['session'] = rmessage.session
rdata['message'] = rmessage.message
rdata['cipher'] = rmessage.cipher
rdata['timestamp'] = rmessage.timestamp
self.sendAPI(0,191,'Message received',rdata,other.transport)
if rdata:
self.sendAPI(0,193,'Message pushed',cdata)
else:
self.sendAPI(0,192,'Message queued',cdata)
else:
self.sendAPI(1,405,'Credentials invalid')
else:
self.sendAPI(1,410,'User unauthorized')
except (KeyError, TypeError):
self.sendAPI(1,401,'Not in reference format')