本文整理汇总了Python中users.models.Profile.userLink方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.userLink方法的具体用法?Python Profile.userLink怎么用?Python Profile.userLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.models.Profile
的用法示例。
在下文中一共展示了Profile.userLink方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import userLink [as 别名]
def register(request):
response = JSONResponse("success")
if request.method != 'POST':
response.add_error('Bad request.')
else:
print request.POST['birthday']
valid = True
match = User.objects.filter(username = request.POST['username'])
if len(match) > 0:
response.add_error('Username is already in use.', 'register_error')
valid = False
match = User.objects.filter(email = request.POST['email'])
if len(match) > 0:
response.add_error('Email address is already registered.', 'register_error')
valid = False
if len(request.POST['password']) < 6:
response.add_error('The entered password is less than 6 characters.', 'register_error')
valid = False
if len(request.POST['username']) < 3:
response.add_error('The requested username is too short.', 'register_error')
valid = False
if len(request.POST['firstname']) == 0 or len(request.POST['lastname']) == 0:
response.add_error('You must provide both first and last name.', 'register_error')
global mail_re
if mail_re == None:
mail_re = re.compile('^[a-zA-Z0-9._%-][email protected][a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$')
if mail_re.match(request.POST['email']) is None:
response.add_error('Invalid email address', 'register_error')
valid = False
if valid == True:
user = User.objects.create_user(request.POST['username'], request.POST['email'], request.POST['password'])
user.save()
profile = Profile()
profile.userLink = user
profile.birthday = datetime.datetime.strptime(request.POST['birthday'], '%Y-%m-%d').date()
profile.firstname = request.POST['firstname']
profile.lastname = request.POST['lastname']
profile.country = request.POST['country']
profile.biography = request.POST['bio']
profile.rights = 0
profile.save()
user = authenticate(username=request.POST['username'], password=request.POST['password'])
login(request, user)
return response.respond()