当前位置: 首页>>代码示例>>Python>>正文


Python User.get_by_name方法代码示例

本文整理汇总了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)
开发者ID:WildAndrewLee,项目名称:SoMoe,代码行数:14,代码来源:routes.py

示例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)]
开发者ID:bcersows,项目名称:pyolite,代码行数:16,代码来源:user.py

示例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)
开发者ID:hpsoar,项目名称:reader4you,代码行数:20,代码来源:home.py

示例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)
开发者ID:WildAndrewLee,项目名称:SoMoe,代码行数:22,代码来源:routes.py

示例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 >')
开发者ID:bcersows,项目名称:pyolite,代码行数:26,代码来源:test_user.py

示例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)
开发者ID:bcersows,项目名称:pyolite,代码行数:4,代码来源:user.py


注:本文中的models.user.User.get_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。