本文整理汇总了Python中models.user.User.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_name方法的具体用法?Python User.get_by_name怎么用?Python User.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.get_by_name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invite_new
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_name [as 别名]
def invite_new(name):
with session_factory() as sess:
if User.get_by_name(name):
return 'User already exists.'
try:
h = hashlib.md5(name + str(time.time())).hexdigest()
Invite(name=name, h=h).save()
except:
return 'Invite already exists.'
return url_for('invite', name=name, h=h, _external=True)
示例2: all
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_name [as 别名]
def all(self):
users = []
key_dir = Path(self.path, 'keydir')
for obj in key_dir.walk():
if obj.isdir():
continue
files = re.compile('(\w+.pub)').findall(str(obj))
if files:
users += files
return [User.get_by_name(user[:-4], self.path, self.git)
for user in set(users)]
示例3: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_name [as 别名]
def login():
error = None
if request.method == 'POST':
user = User.get_by_name(request.form['username'])
if not user and settings.DEBUG == 'debug':
user = User(request.form['username'], request.form['password'])
user.save()
if not user:
error = 'Invalid username'
elif user.password != request.form['password']:
error = 'Invalid password'
else:
session['user_id'] = user.user_id
flash('You were logged in')
return redirect(url_for('home'))
return render_template('login.html', error=error)
示例4: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_name [as 别名]
def login():
if current_user.is_authenticated():
return redirect(url_for('index'))
login = Login(request.form)
if request.method == 'POST' and login.validate():
user = User.get_by_name(login.name.data)
if not user or not bcrypt.check_password_hash(user.h, login.password.data):
login.name.errors.append('Invalid username or password specified.')
return render_template('login.html', title='Log In', form=login)
login_user(user)
flash('You are now logged in as ' + user.username + '.')
return redirect(url_for('index'))
return render_template('login.html', title='Log In', form=login)
示例5: test_if_a_user_can_be_retrieved_by_name
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_name [as 别名]
def test_if_a_user_can_be_retrieved_by_name(self):
mocks = self.set_mocks()
with patch.multiple('models.user', Path=mocks['path'],
ListKeys=mocks['keys']):
user = User(mocks['initial_path'], mocks['git'], 'vtemian', [],
[mocks['first_key']])
test_user = User.get_by_name('vtemian', mocks['initial_path'],
mocks['git'])
eq_(test_user.name, user.name)
eq_(test_user.repos, user.repos)
eq_(test_user.keys, user.keys)
eq_(test_user.path, user.path)
eq_(test_user.git, user.git)
mocks['path'].has_calls([
call('path', 'keydir'),
call('path', 'conf/')
])
eq_(str(test_user), '< vtemian >')
eq_(repr(test_user), '< vtemian >')
示例6: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_name [as 别名]
def get(self, name):
return User.get_by_name(name, self.path, self.git)