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


Python models.User类代码示例

本文整理汇总了Python中app.user.models.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_get_by_id

    def test_get_by_id(self):
        """Get user by ID."""
        user = User('foo', '[email protected]')
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
开发者ID:iulian4ik,项目名称:HeroesOfProgramming,代码行数:7,代码来源:test_models.py

示例2: test_sanity

    def test_sanity(self):
        rv = self.app.post('/users', data=dict(email="[email protected]", password="_foobar_"))
        data = json.loads(rv.data)
        token = str(data['session_token'])
        rv = self.app.put(
            self.ENDPOINT + str(data['id']),
            data=dict(email="[email protected]com", password="_foobar_"),
            headers={'X-Session-Token': token}
        )
        self.assertEqual(rv.status, "200 OK")
        user = User.get_by_email('[email protected]')
        self.assertIsNotNone(user)
        self.assertTrue(user.verify_password('_foobar_'))

        rv = self.app.put(
            self.ENDPOINT + str(data['id']),
            data=dict(email="[email protected]", password="_foobar_new_"),
            headers={'X-Session-Token': token}
        )
        self.assertEqual(rv.status, "200 OK")
        user = User.get_by_email('[email protected]')
        self.assertIsNotNone(user)
        self.assertTrue(user.verify_password('_foobar_new_'))
        self.assertFalse(user.verify_password('_foobar_'))
        self.assertIsNone(User.get_by_email('[email protected]'))
开发者ID:patrikpettersson,项目名称:rest-engine,代码行数:25,代码来源:test_resources.py

示例3: list

def list():

    from app.database import DataTable
    datatable = DataTable(
        model=User,
        columns=[User.remote_addr],
        sortable=[User.username, User.email, User.created_ts],
        searchable=[User.username, User.email],
        filterable=[User.active],
        limits=[25, 50, 100],
        request=request
    )

    if g.pjax:
        return render_template(
            'users.html',
            datatable=datatable,
            stats=User.stats()
        )

    return render_template(
        'list.html',
        datatable=datatable,
        stats=User.stats()
    )
开发者ID:5290charlie,项目名称:flask-bones,代码行数:25,代码来源:views.py

示例4: test_verify_password

 def test_verify_password(self):
     pwd1 = "password1"
     pwd2 = "password2"
     user = User(email="[email protected]")
     user.set_password(pwd1)
     self.assertTrue(user.verify_password(pwd1))
     self.assertFalse(user.verify_password(pwd2))
开发者ID:patrikpettersson,项目名称:rest-engine,代码行数:7,代码来源:test_models.py

示例5: single_user

def single_user(email):
    if User.objects(email=email).count() != 1:
        abort(404)
    user = User.objects().get(email=email)
    """
    args = {
        k: v[0] for (k, v) in request.args.items()
    }
    """
    db = client.cloakedhipster
    dbdiff = db.diff
    dbwindow = db.active_window

    query = {
        'user': user['id'],
    }

    if 'after' in request.args or 'before' in request.args:
        query['time'] = {}
        if 'after' in request.args:
            query['time']['$gte'] = long(request.args['after'])
        if 'before' in request.args:
            query['time']['$lte'] = long(request.args['before'])

    derped = list(dbdiff.find(query))
    derped2 = list(dbwindow.find(query))

    commits = get_num_commits()

    return render_template('user.html', commits=commits, userRaw=user.dict(), user=json.dumps(user.dict()), diffs=json.dumps(derped, cls=MongoJsonEncoder), actWindows=json.dumps(derped2, cls=MongoJsonEncoder))
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:30,代码来源:routes.py

示例6: facebook_authorized

def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    session['oauth_token'] = (resp['access_token'], '')
    session['logged_in'] = True
    me = facebook.get('/me')
    user = User.query.filter_by(email=me.data['email']).first()
    if user is None:
        user = User(me.data['email'],'facebook',me.data['id'],resp['access_token'],me.data['name'],me.data['link'])
        db.session.add(user)
        db.session.commit()
        session['id'] = user.id
    else :
        user.access_token = resp['access_token']
        db.session.add(user)
        db.session.commit()

    session['id'] = user.id
    session['name'] = user.name

    """return 'Logged in as id=%s name=%s email=%s redirect=%s' % \
        (me.data['id'], me.data['name'], me.data['email'], request.args.get('next'))"""
    return redirect('/')
开发者ID:redwallInteractive,项目名称:neighborfood,代码行数:26,代码来源:views.py

示例7: current_user

def current_user():
    args = token_parser.parse_args()
    token = args['X-Session-Token']
    valid, data = User.verify_session_token(token)
    g.user = None
    if valid:
    	if not data.get('password_reset'):
    		g.user = User.get_by_id(data.get('user_id'))
开发者ID:patrikpettersson,项目名称:rest-engine,代码行数:8,代码来源:__init__.py

示例8: test_get_by_email

 def test_get_by_email(self):
     email = "[email protected]"
     user = User.get_by_email(email)
     self.assertIsNone(user)
     User(email=email).put()
     user = User.get_by_email(email)
     self.assertIsNotNone(user)
     self.assertEqual(user.email, email)
开发者ID:patrikpettersson,项目名称:rest-engine,代码行数:8,代码来源:test_models.py

示例9: test_invalid_confirmation_token

 def test_invalid_confirmation_token(self):
     u1 = User(username='cat', email='[email protected]', password='cat')
     u2 = User(username='dog', email='[email protected]', password='dog')
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     token = u1.generate_confirmation_token()
     self.assertFalse(u2.confirm(token))
开发者ID:polyval,项目名称:HUSTRunner,代码行数:8,代码来源:test_user_model.py

示例10: regist

def regist():
    form = RegistForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        user.generate()
        return redirect(url_for('.login'))
    return render_template('regist.html', form=form)
开发者ID:MOOOWOOO,项目名称:Q400K,代码行数:9,代码来源:views.py

示例11: register

def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    password=form.password.data)

        user.save()
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
开发者ID:XiongZhijun,项目名称:simple-flask,代码行数:9,代码来源:views.py

示例12: test_user_exists

 def test_user_exists(self):
     rv = self.app.post("/users", data=dict(email="[email protected]", password="_foobar_"))
     self.assertEqual(rv.status, "201 CREATED")
     self.assertTrue('session_token' in rv.data)
     self.assertIsNotNone(User.get_by_email("[email protected]"))
     rv = self.app.post("/users", data=dict(email="[email protected]", password="_foobar_"))
     self.assertEqual(rv.status, "400 BAD REQUEST")
     self.assertFalse('session_token' in rv.data)
     self.assertIsNotNone(User.get_by_email("[email protected]"))
     self.assertEqual(1, len(User.query().fetch(2)))
开发者ID:patrikpettersson,项目名称:rest-engine,代码行数:10,代码来源:test_resources.py

示例13: register

def register():
    """Register new user."""
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        User.create(username=form.username.data, email=form.email.data, password=form.password.data, active=True)
        flash('Thank you for registering. You can now log in.', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
开发者ID:iulian4ik,项目名称:HeroesOfProgramming,代码行数:10,代码来源:views.py

示例14: test_unauthenticated

 def test_unauthenticated(self):
     rv = self.app.put(self.ENDPOINT + str(1), data=dict(email="[email protected]", password="_foobar_"))
     self.assertEqual(rv.status, "401 UNAUTHORIZED")
     self.assertIsNone(User.get_by_email('[email protected]'))
     rv = self.app.post('/users', data=dict(email="[email protected]com", password="_foobar_"))
     data = json.loads(rv.data)
     rv = self.app.put(self.ENDPOINT + str(data['id']), data=dict(email="[email protected]", password="_foobar_"))
     self.assertEqual(rv.status, "401 UNAUTHORIZED")
     self.assertIsNotNone(User.get_by_email('[email protected]'))
     self.assertIsNone(User.get_by_email('[email protected]'))
开发者ID:patrikpettersson,项目名称:rest-engine,代码行数:10,代码来源:test_resources.py

示例15: signup

def signup():
    form = SignupForm()
    if form.validate_on_submit():
        new_user = User(form.email.data, form.student_id.data, 'changeme')
        new_user.update_login_info(request.environ['REMOTE_ADDR'])
        db.session.add(new_user)
        db.session.commit()

        login_user(new_user)
        return redirect(request.args.get('next') or url_for('index'))

    return render_template('user/signup.html', form=form)
开发者ID:vigov5,项目名称:oshougatsu2015,代码行数:12,代码来源:views.py


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