本文整理汇总了Python中models.Person.password方法的典型用法代码示例。如果您正苦于以下问题:Python Person.password方法的具体用法?Python Person.password怎么用?Python Person.password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Person
的用法示例。
在下文中一共展示了Person.password方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import password [as 别名]
def register(request):
if request.method == 'POST':
body_unicode = request.body.decode('utf-8')
body = json.loads(body_unicode)
email = body['email']
password = body['password']
account_type = body['account_type']
if email is not None and password is not None and account_type is not None:
try:
if not body['password_change']:
obj = Person(email= email, password= make_password(password),role= account_type)
obj.save()
elif body['password_change']:
rs = Person.objects.filter(email = email)
if rs:
obj = Person.objects.get(email = email)
obj.password = make_password(password)
obj.save()
else:
obj = Person(email= email, password= make_password(password),role= account_type)
obj.save()
else:
return json_response({
'error': 'unable to process'
}, status=400)
except IntegrityError:
return json_response({
'error': 'User already exists'
}, status=400)
token = Token.objects.create(user=obj)
if not body['password_change']:
send_activation_link(obj.id, obj.email, 'activate')
return json_response({
'token': token.token,
'useremail': obj.email,
'role': obj.role
})
else:
return json_response({
'error': 'Invalid Data'
}, status=400)
elif request.method == 'OPTIONS':
return json_response({})
else:
return json_response({
'error': 'Invalid Method'
}, status=405)