本文整理汇总了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
示例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]'))
示例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()
)
示例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))
示例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))
示例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('/')
示例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'))
示例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)
示例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))
示例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)
示例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)
示例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)))
示例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)
示例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]'))
示例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)