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


Python model.User方法代码示例

本文整理汇总了Python中model.User方法的典型用法代码示例。如果您正苦于以下问题:Python model.User方法的具体用法?Python model.User怎么用?Python model.User使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model的用法示例。


在下文中一共展示了model.User方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: user_list

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def user_list():
  args = parser.parse({
    'email': wf.Str(missing=None),
    'permissions': wf.DelimitedList(wf.Str(), delimiter=',', missing=[]),
  })
  user_dbs, cursors = model.User.get_dbs(
    email=args['email'], prev_cursor=True,
  )
  permissions = list(UserUpdateForm._permission_choices)
  permissions += args['permissions']
  return flask.render_template(
    'user/user_list.html',
    html_class='user-list',
    title='User List',
    user_dbs=user_dbs,
    next_url=util.generate_next_url(cursors['next']),
    prev_url=util.generate_next_url(cursors['prev']),
    api_url=flask.url_for('api.admin.user.list'),
    permissions=sorted(set(permissions)),
  )


###############################################################################
# User Update
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:27,代码来源:user.py

示例2: run

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def run(self, username, password=None):
        with self.app_context():
            if not password:
                wordfile = xp.locate_wordfile()
                mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8)
                password = xp.generate_xkcdpassword(mywords, acrostic="ambit")
                print("generated password: '%s'" % password)

            assert not User.query.filter_by(username=username).scalar(), "user already exists"

            user = User(username=username)
            user.password = self.app_bcrypt.generate_password_hash(password, 10)

            if user.password is not str:
                user.password = user.password.decode('utf-8')

            user.active = True
            db.session.add(user)
            db.session.commit()

            print("created user '%s' in '%s'" % (user.username, db.engine.url)) 
开发者ID:bwaldvogel,项目名称:openmoves,代码行数:23,代码来源:commands.py

示例3: test_add_user

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def test_add_user(self):
        with app.test_request_context():
            assert User.query.count() == 0

        cmd = AddUser(lambda: app.app_context(), app_bcrypt=openmoves.app_bcrypt)
        cmd.run(username='test_user')

        with app.test_request_context():
            assert User.query.count() == 1
            assert User.query.filter_by(username='test_user').one()

        with pytest.raises(AssertionError) as e:
            cmd.run(username='test_user')
        assert "user already exists" in str(e.value)

        cmd.run(username='test_user2')
        with app.test_request_context():
            assert User.query.count() == 2
            assert User.query.filter_by(username='test_user').one() != User.query.filter_by(username='test_user2').one() 
开发者ID:bwaldvogel,项目名称:openmoves,代码行数:21,代码来源:test_openmoves.py

示例4: test_login_valid

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def test_login_valid(self, tmpdir):

        username = 'test_user'
        password = 'test password'

        with app.test_request_context():
            User.query.delete(synchronize_session=False)

            user = User(username=username, active=True)
            user.password = openmoves.app_bcrypt.generate_password_hash(password, 10)
            db.session.add(user)
            db.session.commit()

        response = self._login()
        response_data = self._validate_response(response, tmpdir)
        assert "<title>OpenMoves – Dashboard</title>" in response_data 
开发者ID:bwaldvogel,项目名称:openmoves,代码行数:18,代码来源:test_openmoves.py

示例5: test_login_logout_other_user

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def test_login_logout_other_user(self, tmpdir):

        username = 'other_user'
        password = 'Paßswörd→✓≈'

        with app.test_request_context():
            user = User(username=username, active=True)
            user.password = openmoves.app_bcrypt.generate_password_hash(password, 10)
            db.session.add(user)
            db.session.commit()

        response = self._login(username=username, password=password)
        response_data = self._validate_response(response, tmpdir)
        assert '<title>OpenMoves – Dashboard</title>' in response_data
        assert username in response_data

        response = self.client.get('/logout', follow_redirects=True)
        response_data = self._validate_response(response, tmpdir)
        assert '<title>OpenMoves</title>' in response_data
        assert username not in response_data 
开发者ID:bwaldvogel,项目名称:openmoves,代码行数:22,代码来源:test_openmoves.py

示例6: create_user_db

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def create_user_db(auth_id, name, username, email='', verified=False, password='', **props):
    """Saves new user into datastore"""
    if password:
        password = util.password_hash(password)

    email = email.lower()
    user_db = model.User(
        name=name,
        email=email,
        username=username,
        auth_ids=[auth_id] if auth_id else [],
        verified=verified,
        token=util.uuid(),
        password_hash=password,
        **props
    )
    user_db.put()
    task.new_user_notification(user_db)
    return user_db 
开发者ID:madvas,项目名称:gae-angular-material-starter,代码行数:21,代码来源:auth.py

示例7: create_or_get_user_db

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def create_or_get_user_db(auth_id, name, username, email='', **kwargs):
    """This function will first lookup if user with given email already exists.
    If yes then it will append auth_id for his record and saves it.
    If not we'll make sure to find unique username for this user (for the case of signing up via social account)
    and then store it into datastore"""
    user_db = model.User.get_by('email', email.lower())
    if user_db:
        user_db.auth_ids.append(auth_id)
        user_db.put()
        return user_db

    if isinstance(username, str):
        username = username.decode('utf-8')
    username = unidecode.unidecode(username.split('@')[0].lower()).strip()
    username = re.sub(r'[\W_]+', '.', username)
    new_username = username
    suffix = 1
    while not model.User.is_username_available(new_username):
        new_username = '%s%d' % (username, suffix)
        suffix += 1

    return create_user_db(auth_id, name, new_username, email=email, **kwargs) 
开发者ID:madvas,项目名称:gae-angular-material-starter,代码行数:24,代码来源:auth.py

示例8: create_users

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def create_users():
    """Creates fake users and loads them into the db"""

    print "====================="
    print "Creating fake users"

    # Instantiate a Faker object
    fake = Faker()
    fake.seed(435)

    # Create N user objects and add them to the db
    for i in range(N_USERS):

        user = User(name=fake.name(),
                    email=fake.email(),
                    password=fake.bs())

        db.session.add(user)

    db.session.commit() 
开发者ID:michberr,项目名称:ProductGenius,代码行数:22,代码来源:seed.py

示例9: create_favorite_products

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def create_favorite_products():
    """Create User favorite products"""

    users = User.query.all()
    products = Product.query.all()

    for user in users:

        # Select a random number of products for the user to have from 0-15
        n_products = randint(0, 15)
        user_products = sample(products, n_products)

        for product in user_products:

            user.favorite_products.append(product)

    db.session.commit()



##################### Run script ################################# 
开发者ID:michberr,项目名称:ProductGenius,代码行数:23,代码来源:seed.py

示例10: user_update

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def user_update(user_id=0):
  if user_id:
    user_db = model.User.get_by_id(user_id)
  else:
    user_db = model.User(name='', username='')
  if not user_db:
    flask.abort(404)

  form = UserUpdateForm(obj=user_db)
  for permission in user_db.permissions:
    form.permissions.choices.append((permission, permission))
  form.permissions.choices = sorted(set(form.permissions.choices))
  if form.validate_on_submit():
    if not util.is_valid_username(form.username.data):
      form.username.errors.append('This username is invalid.')
    elif not model.User.is_username_available(form.username.data, user_db.key):
      form.username.errors.append('This username is already taken.')
    else:
      form.populate_obj(user_db)
      if auth.current_user_key() == user_db.key:
        user_db.admin = True
        user_db.active = True
      user_db.put()
      return flask.redirect(flask.url_for(
        'user_list', order='-modified', active=user_db.active,
      ))

  return flask.render_template(
    'user/user_update.html',
    title=user_db.name or 'New User',
    html_class='user-update',
    form=form,
    user_db=user_db,
    api_url=flask.url_for('api.admin.user', user_key=user_db.key.urlsafe()) if user_db.key else ''
  )


###############################################################################
# User Verify
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:42,代码来源:user.py

示例11: user_verify

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def user_verify(token):
  user_db = auth.current_user_db()
  if user_db.token != token:
    flask.flash('That link is either invalid or expired.', category='danger')
    return flask.redirect(flask.url_for('profile'))
  user_db.verified = True
  user_db.token = util.uuid()
  user_db.put()
  flask.flash('Hooray! Your email is now verified.', category='success')
  return flask.redirect(flask.url_for('profile'))


###############################################################################
# User Forgot
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:17,代码来源:user.py

示例12: user_forgot

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def user_forgot(token=None):
  if not config.CONFIG_DB.has_email_authentication:
    flask.abort(418)

  form = auth.form_with_recaptcha(UserForgotForm(obj=auth.current_user_db()))
  if form.validate_on_submit():
    cache.bump_auth_attempt()
    email = form.email.data
    user_dbs, cursors = util.get_dbs(
      model.User.query(), email=email, active=True, limit=2,
    )
    count = len(user_dbs)
    if count == 1:
      task.reset_password_notification(user_dbs[0])
      return flask.redirect(flask.url_for('welcome'))
    elif count == 0:
      form.email.errors.append('This email was not found')
    elif count == 2:
      task.email_conflict_notification(email)
      form.email.errors.append(
        '''We are sorry but it looks like there is a conflict with your
        account. Our support team is already informed and we will get back to
        you as soon as possible.'''
      )

  if form.errors:
    cache.bump_auth_attempt()

  return flask.render_template(
    'user/user_forgot.html',
    title='Forgot Password?',
    html_class='user-forgot',
    form=form,
  )


###############################################################################
# User Reset
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:41,代码来源:user.py

示例13: user_reset

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def user_reset(token=None):
  user_db = model.User.get_by('token', token)
  if not user_db:
    flask.flash('That link is either invalid or expired.', category='danger')
    return flask.redirect(flask.url_for('welcome'))

  if auth.is_logged_in():
    flask_login.logout_user()
    return flask.redirect(flask.request.path)

  form = UserResetForm()
  if form.validate_on_submit():
    user_db.password_hash = util.password_hash(user_db, form.new_password.data)
    user_db.token = util.uuid()
    user_db.verified = True
    user_db.put()
    flask.flash('Your password was changed succesfully.', category='success')
    return auth.signin_user_db(user_db)

  return flask.render_template(
    'user/user_reset.html',
    title='Reset Password',
    html_class='user-reset',
    form=form,
    user_db=user_db,
  )


###############################################################################
# User Activate
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:33,代码来源:user.py

示例14: signup

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def signup():
  next_url = util.get_next_url()
  form = None
  if config.CONFIG_DB.has_email_authentication:
    form = form_with_recaptcha(SignUpForm())
    save_request_params()
    if form.validate_on_submit():
      user_db = model.User.get_by('email', form.email.data)
      if user_db:
        form.email.errors.append('This email is already taken.')

      if not form.errors:
        user_db = create_user_db(
          None,
          util.create_name_from_email(form.email.data),
          form.email.data,
          form.email.data,
        )
        user_db.put()
        task.activate_user_notification(user_db)
        cache.bump_auth_attempt()
        return flask.redirect(flask.url_for('welcome'))

  if form and form.errors:
    cache.bump_auth_attempt()

  title = 'Sign up' if config.CONFIG_DB.has_email_authentication else 'Sign in'
  return flask.render_template(
    'auth/auth.html',
    title=title,
    html_class='auth',
    next_url=next_url,
    form=form,
    **urls_for_oauth(next_url)
  )


###############################################################################
# Sign out stuff
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:42,代码来源:auth.py

示例15: form_with_recaptcha

# 需要导入模块: import model [as 别名]
# 或者: from model import User [as 别名]
def form_with_recaptcha(form):
  should_have_recaptcha = cache.get_auth_attempt() >= config.RECAPTCHA_LIMIT
  if not (should_have_recaptcha and config.CONFIG_DB.has_recaptcha):
    del form.recaptcha
  return form


###############################################################################
# User related stuff
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:12,代码来源:auth.py


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