本文整理汇总了Python中models.user.User.users方法的典型用法代码示例。如果您正苦于以下问题:Python User.users方法的具体用法?Python User.users怎么用?Python User.users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.users方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deleteToken
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
def deleteToken(self, args):
self._start(args)
print('Delete token: please authenticate...')
while True:
admin_username = raw_input('Enter admin username: ')
admin_password = getpass.getpass('Enter admin password: ')
if not User.users().get(username=admin_username).admin: #Db.instance().is_admin(admin_username):
print('Please sign in using administrator credentials.')
elif not User.users().get(username=admin_username).authenticate(admin_password): #Db.instance().authenticate_user(admin_username, admin_password):
print("Username/password don't match.")
else:
break
username = raw_input('Enter username for token to delete: ')
user = User.users().get(username=username)
if user:
token = Token.tokens().get_token_for_user(user=user)
if token:
token.delete()
print('Deleted token belonging to %s.' % username)
else:
print('%s has no tokens to delete.' % username)
else:
print('%s has no tokens to delete.' % username)
示例2: createToken
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
def createToken(self, args):
self._start(args)
# Do a check to see if any admins exist before proceeding.
print('Create token: please authenticate...')
while True:
admin_username = raw_input('Enter admin username: ')
admin_password = getpass.getpass('Enter admin password: ')
if not User.users().get(username=admin_username).admin:
print('Please sign in using administrator credentials.')
elif not User.users().get(username=admin_username).authenticate(admin_password):
print("Username/password don't match.")
else:
break
username = raw_input('Enter username to create a token for: ')
user = User.users().get(username=username)
if user:
try:
token = Token(user=user)
token.save()
print(str('Token %s created for %s' % (token.token, username)))
except Exception as e:
print("EXCEPTION **** %s" % e)
print('A token already exists for %s. Doing nothing.' % username)
else:
print('A user with username %s does not exist.' % username)
示例3: createUser
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
def createUser(self, args):
self._start(args)
while True:
username = raw_input('Enter email address: ')
if User.users().get(username=username):
print('Username already exists. Please pick another username.')
else:
break
print('username: %s' % username)
while True:
is_admin = raw_input('Admininstrative user? (y/N): ')
if (len(is_admin) == 0) or (is_admin.upper() == 'N'):
admin = False
break
elif is_admin.upper() == 'Y':
admin = True
break
while True:
password_1 = getpass.getpass('Enter password: ')
password_2 = getpass.getpass('Re-enter password: ')
if password_1 != password_2:
print('Passwords do not match.')
else:
break
user = User(username, password_1, admin)
user.save()
# Db.instance().insert_user(username, password_1, admin)
print('Successfully created user %s' % username)
示例4: listUsers
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
def listUsers(self, args):
self._start(args)
print("%s%sCreated" % ("Username".ljust(70), "Admin".ljust(20)))
for user in User.users().all():
if user.admin:
admin_str = 'Y'
else:
admin_str = 'N'
# https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
line = "%s%s%s" % (user.username.ljust(70), admin_str.ljust(20), datetime.fromtimestamp(user.created).strftime('%d-%m-%Y %H:%M:%S'))
print(str(line))
示例5: deleteUser
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
def deleteUser(self, args):
self._start(args)
print('Delete user: please authenticate...')
while True:
admin_username = raw_input('Enter admin username: ')
admin_password = getpass.getpass('Enter admin password: ')
user = User.users().get(username=admin_username)
if not user.admin:
print('Please sign in using administrator credentials.')
elif not user.authenticate(admin_password):
print("Username/password don't match.")
else:
break
username_to_delete = raw_input('Enter username to delete: ')
if User.users().get(username=username_to_delete).delete():
# Db.instance().delete_user(username_to_delete)
print('Deleted user %s.' % username_to_delete)
else:
sys.exit("User doesn't exist. Doing nothing.")
示例6: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
def get(self):
try:
username = self.request.headers.get('username')
password = self.request.headers.get('password')
user = User.users().get(username=username)
if user.authenticate(password):
token = Token.tokens().get_token_for_user(user)
if not token:
token = Token(user=user)
token.save()
data = {'token': token.token}
else:
data = {'error': 'invalid username/password'}
except Exception as e:
data = {'error': str(e)}
self.set_header('Content-Type', 'application/json')
self.write(json.dumps(data))