本文整理汇总了Python中user.User.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_user方法的具体用法?Python User.get_user怎么用?Python User.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.User
的用法示例。
在下文中一共展示了User.get_user方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iter_users
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def iter_users(self, page=None, prefix=None, prefix_limit=None):
self._cache_users()
if page is not None:
page_total = self.page_total
page = min(page, page_total)
if page == 0:
page_index_s = 0
else:
page_index_s = int(cache_db.dict_get(self.get_cache_key(
'users_page_index'), str(page)))
if page == page_total:
page_index_e = None
else:
page_index_e = int(cache_db.dict_get(self.get_cache_key(
'users_page_index'), str(page + 1)))
for user_id in cache_db.list_iter_range(
self.get_cache_key('users_sorted'),
page_index_s, page_index_e):
user = User.get_user(self, id=user_id)
if user:
yield user
elif prefix is not None:
users_dict = {}
users_sort = []
prefix_count = 0
users_trie = CacheTrie(self.get_cache_key('users_trie'))
for user_data in users_trie.iter_prefix(prefix):
user_id, user_type, user_name = user_data.split('-', 2)
if user_type == CERT_CLIENT:
prefix_count += 1
name_id = user_name + '_' + user_id
users_dict[name_id] = (user_id, user_type, user_name)
users_sort.append(name_id)
self._last_prefix_count = prefix_count
user_count = 0
search_more = False
for name_id in sorted(users_sort):
user_id, user_type, user_name = users_dict[name_id]
user = User.get_user(self, id=user_id)
if not user:
continue
yield user
if prefix_limit and user_type == CERT_CLIENT:
user_count += 1
if user_count >= prefix_limit:
search_more = True
break
if prefix_limit and not search_more:
yield None
else:
for user_id in cache_db.list_iter(
self.get_cache_key('users_sorted')):
user = User.get_user(self, id=user_id)
if user:
yield user
示例2: test_user
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def test_user(self):
delete_db.delete_data_in_db()
user = User()
user.add_user()
user.add_user()
user.login()
user.update_user()
user.get_user()
user.get_all_users()
user.is_logged_in()
user.delete_user()
示例3: User
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def User(self):
if self.user is None:
uid = self.session.uid
self.user = User.get_user(uid)
return self.user
示例4: code
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def code(email):
"""
Returns the one-time password associated with the given user for the
current time window. Returns empty string if user is not found.
"""
u = User.get_user(email)
if u is None:
return ''
t = pyotp.TOTP(u.key)
return str(t.now())
示例5: _process_choice
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def _process_choice(self, choice, user):
from menus import Actions, Login
user = User.get_user(choice)
if user:
menu = Actions()
menu.go(user)
else:
self.display_message('User does not exist.')
menu = Login()
menu.go()
示例6: sort_users_cache
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def sort_users_cache(self):
user_count = 0
users_dict = {}
users_sort = []
# Create temp uuid key to prevent multiple threads modifying same key
temp_suffix = 'temp_' + uuid.uuid4().hex
temp_users_sorted_key = 'users_sorted_' + temp_suffix
users_page_index_key = 'users_page_index_' + temp_suffix
try:
for user_id in cache_db.set_elements(self.get_cache_key('users')):
user = User.get_user(self, id=user_id)
if not user:
continue
name_id = '%s_%s' % (user.name, user_id)
if user.type == CERT_CLIENT:
user_count += 1
users_dict[name_id] = (user_id, user.type)
users_sort.append(name_id)
cache_db.set(self.get_cache_key('user_count'), str(user_count))
cur_page = 0
user_count = 0
client_count = 0
for name_id in sorted(users_sort):
if users_dict[name_id][1] == CERT_CLIENT:
page = client_count / USER_PAGE_COUNT
if page != cur_page:
cur_page = page
cache_db.dict_set(self.get_cache_key(users_page_index_key),
str(cur_page), str(user_count))
client_count += 1
user_count += 1
cache_db.list_rpush(self.get_cache_key(temp_users_sorted_key),
users_dict[name_id][0])
cache_db.lock_acquire(self.get_cache_key('sort'))
try:
cache_db.rename(self.get_cache_key(users_page_index_key),
self.get_cache_key('users_page_index'))
cache_db.rename(self.get_cache_key(temp_users_sorted_key),
self.get_cache_key('users_sorted'))
cache_db.set(self.get_cache_key('users_page_total'),
str(cur_page))
finally:
cache_db.lock_release(self.get_cache_key('sort'))
except:
cache_db.remove(self.get_cache_key(users_page_index_key))
cache_db.remove(self.get_cache_key(temp_users_sorted_key))
raise
示例7: qr
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def qr(email):
"""
Return a QR code for the secret key associated with the given email
address. The QR code is returned as file with MIME type image/png.
"""
u = User.get_user(email)
if u is None:
return ''
t = pyotp.TOTP(u.key)
q = qrcode.make(t.provisioning_uri(email))
img = StringIO()
q.save(img)
img.seek(0)
return send_file(img, mimetype="image/png")
示例8: _cache_users
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def _cache_users(self):
if cache_db.get(self.get_cache_key('users_cached')) != 't':
cache_db.remove(self.get_cache_key('users'))
certs_path = os.path.join(self.path, CERTS_DIR)
if os.path.isdir(certs_path):
for cert in os.listdir(certs_path):
user_id = cert.replace('.crt', '')
if user_id == CA_CERT_ID:
continue
user = User.get_user(self, id=user_id)
if not user:
continue
user._add_cache_trie_key()
cache_db.set_add(self.get_cache_key('users'), user_id)
self.sort_users_cache()
cache_db.set(self.get_cache_key('users_cached'), 't')
示例9: __init__
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def __init__(self, id=None, name=None):
Config.__init__(self)
self._last_prefix_count = None
if id is None:
self.id = uuid.uuid4().hex
self.name = name
else:
self.id = id
self.path = os.path.join(app_server.data_path, ORGS_DIR, self.id)
self.set_path(os.path.join(self.path, 'ca.conf'))
if id is None:
self._initialize()
self.ca_cert = User.get_user(self, id=CA_CERT_ID)
示例10: login
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def login():
"""Login form."""
if request.method == 'POST':
u = User.get_user(request.form['email'])
if u is None:
flash('Invalid email address.', 'danger')
return render_template('login.html')
else:
otp = request.form['otp']
if u.authenticate(otp):
flash('Authentication successful!', 'success')
return render_template('/view.html', user=u)
else:
flash('Invalid one-time password!', 'danger')
return render_template('login.html')
else:
return render_template('login.html')
示例11: check_session
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def check_session(self, req):
'''Check session cookie.
Check request for a session cookie. If present, check the session
for a valid user id. If the user id is valid, initialize and return
a User object.
'''
self.cookies = req.cookies
if 'session' in self.cookies:
self.session = Session.get_session(self.cookies['session'])
if self.session is not None:
user_id = self.session.uid
self.user = User.get_user(user_id)
return self.user
示例12: get_user
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def get_user(self, id):
return User.get_user(self, id=id)
示例13: user
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def user(email):
"""User view page."""
u = User.get_user(email)
if u is None:
return redirect('/')
return render_template('/view.html', user=u)
示例14: user_register
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user [as 别名]
def user_register(request, user_name):
user = User(user_name)
hometown = user.get_user('yun-user-id')
print hometown
return HttpResponse("User name is %s, hometown is" % user_name)