本文整理汇总了Python中application.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
def register():
form = RegistrationForm(request.form)
if request.method == 'GET':
return render_template('register.html', form=form)
elif request.method == 'POST':
username = form.username.data
password = form.password.data.encode('utf-8')
user = User.query.filter_by(username=username)
if user.count() == 0:
user = User(username=username, password=hashlib.sha512(password + password_salt).hexdigest())
db.session.add(user)
db.session.commit()
flash('Welcome {0}. Thank you for registering'.format(username))
user = User.query.filter_by(username=username).filter_by(password=hashlib.sha512(password + password_salt).hexdigest())
login_user(user.one())
try:
next = request.form['next']
return redirect(next)
except:
return redirect(url_for('index'))
else:
flash('The username {0} is already in use. Please try a new username.'.format(username))
return redirect(url_for('register'))
else:
abort(405)
示例2: test_valid_reset_token
def test_valid_reset_token(self):
u = User(password='cat')
db.session.add(u)
db.session.commit()
token = u.generate_reset_token()
self.assertTrue(u.reset_password(token, 'dog'))
self.assertTrue(u.verify_password('dog'))
示例3: test_expired_confirmation_token
def test_expired_confirmation_token(self):
u = User(password='cat')
db.session.add(u)
db.session.commit()
token = u.generate_confirmation_token(1)
time.sleep(2)
self.assertFalse(u.confirm(token))
示例4: test_user_is_confirmed
def test_user_is_confirmed(self):
u = User(password='cat')
db.session.add(u)
db.session.commit()
token = u.generate_confirmation_token()
self.assertTrue(u.confirm(token))
self.assertTrue(u.confirmed)
示例5: test_invalid_confirmation_token
def test_invalid_confirmation_token(self):
u1 = User(password='cat')
u2 = User(password='dog')
db.session.add(u1)
db.session.add(u2)
db.session.commit()
token = u1.generate_confirmation_token()
self.assertFalse(u2.confirm(token))
示例6: create
def create(self):
data = json.loads(request.data)
if "mail" not in data:
abort(400)
u = users.User(data["mail"])
a = User(role="editor", user=u)
a.save()
return Response(a.as_json(), mimetype="application/json")
示例7: test_invalid_reset_token
def test_invalid_reset_token(self):
u1 = User(password='cat')
u2 = User(password='dog')
db.session.add(u1)
db.session.add(u2)
db.session.commit()
token = u1.generate_reset_token()
self.assertFalse(u2.reset_password(token, 'horse'))
self.assertTrue(u2.verify_password('dog'))
示例8: create
def create(self):
data = json.loads(request.data)
if 'mail' not in data:
abort(400)
u = users.User(data['mail'])
a = User(role='editor',
user=u)
a.save();
return Response(a.as_json(), mimetype='application/json')
示例9: user
def user(db):
password = 'letmein'
user = User(username='tester', password=password)
user.plaintext_password = password
db.session.add(user)
db.session.commit()
return user
示例10: post
def post(self):
args = user_parser.parse_args(strict=True)
if User.query.filter_by(username=args.username).first() is not None:
abort(400, message="User already exists")
# TODO / FIXME: email validation ...
user = User(username=args.username, first_name=args.first_name, last_name=args.last_name, email=args.email)
user.hash_password(args.password)
db.session.add(user)
db.session.commit()
return 201
示例11: _create_user
def _create_user(username, password, is_admin, groups=None):
if not groups:
groups = []
u = User(username=username, email='[email protected]', first_name='first_name', last_name='last_name',
is_admin=is_admin, groups=groups)
u.hash_password(password)
db.session.add(u)
db.session.commit()
return u
示例12: add_user
def add_user(profile, friends):
user = User(
id=profile['id'].decode('utf-8'),
name=profile['name'].decode('utf-8')
)
for friend in friends['data']:
entry = User.get_or_insert(
friend['id'].decode('utf-8'),
name=friend['name'].decode('utf-8')
)
user.friends.append(entry.key)
user.put()
示例13: testAuth
def testAuth(self):
resp = self.app.get('/api/feeds/1')
assert resp.status_code == 401
mock_user_response = json.dumps(self.buildMockUserResponse())
self.set_response("https://alpha-api.app.net/stream/0/token", content=mock_user_response, status_code=200)
resp = self.app.get('/api/feeds', headers=self.authHeaders())
assert resp.status_code == 200
assert User.query().count() == 1
resp = self.app.get('/api/feeds', headers=self.authHeaders())
assert User.query().count() == 1
示例14: setUp
def setUp(self):
self.app = application.app
bcrypt = Bcrypt(self.app)
# forcibly reconnect to testing db
connection.disconnect()
self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
self.connection = connect(
self.app.config['MONGO_CONFIG']['db_name']
, host=self.app.config['MONGO_CONFIG']['host']
, port=int(self.app.config['MONGO_CONFIG']['port'])
)
# drop any lingering test dbs
self.connection.drop_database(
self.app.config['MONGO_CONFIG']['db_name'])
member_user = User(
admin_rights = False
, email = 'member[email protected]'
, email_confirmation_code = 'goodday'
, email_confirmed = True
, last_login_time = datetime.datetime.utcnow()
, password_hash = bcrypt.generate_password_hash('hola!')
, registration_time = datetime.datetime.utcnow()
, verified = True)
member_user.save()
''' create a test org
'''
test_org = Organization(
label = 'best-org'
, name = 'best org')
test_org.save()
# save membership
member_user.update(push__organizations = test_org)
''' create a test project
'''
test_project = Project(
creation_time = datetime.datetime.utcnow()
, label = 'best-project'
, name = 'best project'
, organization = test_org)
test_project.save()
test_org.update(push__projects=test_project)
''' create a data-less upload
'''
'''
示例15: test_get_list
def test_get_list(self):
user_a = User(id='42', name='Foo Bar')
user_b = User.get_or_insert('43', name='Knuth Donald')
user_c = User.get_or_insert('44', name='Lovelace Ada')
user_a.friends.append(user_b.key)
user_a.friends.append(user_c.key)
user_a.put()
rv = self.app.get('/api/friends?profile_id=42')
self.assertEqual(rv.status, '200 OK')
data = json.loads(rv.data)
self.assertEqual(data['count'], 2)
self.assertItemsEqual({'Knuth Donald', 'Lovelace Ada'},
{f['name'] for f in data['friends']})