本文整理汇总了Python中model.User.password_hash方法的典型用法代码示例。如果您正苦于以下问题:Python User.password_hash方法的具体用法?Python User.password_hash怎么用?Python User.password_hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.password_hash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_fixture_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import password_hash [as 别名]
def _create_fixture_users(self, config):
''' Create user fixtures. '''
session = app.database.get_session(self._db)
hash_algorithm = config.get('password_hash', 'algorithm')
try:
hash_rounds = int(config.get('password_hash', 'rounds'))
except:
raise ValueError('Configuration value password_hash.rounds must' \
' be an integer: %s' % rounds)
admin = User('admin')
admin.agency = 'QuickPin'
admin.name = 'Administrator'
admin.is_admin = True
admin.password_hash = model.user.hash_password(
'MemexPass1',
hash_algorithm,
hash_rounds
)
session.add(admin)
session.commit()
示例2: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import password_hash [as 别名]
def post(self):
'''
Create a new application user.
**Example Request**
.. sourcecode:: json
{
"email": "[email protected]",
"password": "superSECRET123"
}
**Example Response**
.. sourcecode:: json
{
"agency": null,
"created": "2015-05-05T14:30:09.676268",
"email": "[email protected]",
"id": 2029,
"is_admin": false,
"location": null,
"modified": "2015-05-05T14:30:09.676294",
"name": null,
"phone": null,
"thumb": null,
"url": "https://quickpin/api/user/2029"
}
:<header Content-Type: application/json
:<header X-Auth: the client's auth token
:>json str email: e-mail address
:>json str password: new password, must be >=8 characters, mixed case,
:>header Content-Type: application/json
:>json str agency: the name of the organization/agency that this person
is affiliated with (default: null)
:>json str created: record creation timestamp in ISO-8601 format
:>json str email: e-mail address
:>json bool is_admin: true if this user has admin privileges, false
otherwise
:>json str location: location name, e.g. city or state (default: null)
:>json str modified: record modification timestamp in ISO-8601 format
:>json str name: user's full name, optionally including title or other
salutation information (default: null)
:>json str phone: phone number
:>json str phone_e164: phone number in E.164 format
:>json str thumb: PNG thumbnail for this user, base64 encoded
:>json str url: url to view data about this user
:status 200: ok
:status 400: invalid request body
:status 401: authentication required
:status 403: not authorized to create accounts
:status 409: e-mail address already in use
'''
request_json = request.get_json()
if 'email' not in request_json or '@' not in request_json['email']:
raise BadRequest('Invalid or missing email.')
user = User(request_json['email'].strip())
if 'password' not in request_json:
raise BadRequest('Password is required')
password = request_json['password'].strip()
if not valid_password(password):
raise BadRequest('Password does not meet complexity requirements.')
user.password_hash = hash_password(
password,
g.config.get('password_hash', 'algorithm'),
int(g.config.get('password_hash', 'rounds'))
)
try:
g.db.add(user)
g.db.commit()
except IntegrityError:
raise Conflict('This e-mail address is already in use.')
g.db.expire(user)
return jsonify(**self._user_dict(user))