本文整理汇总了Python中accounts.models.UserProfile.phone方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.phone方法的具体用法?Python UserProfile.phone怎么用?Python UserProfile.phone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.phone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_new_user
# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import phone [as 别名]
def create_new_user(email, name = None):
ups = UserProfile.objects.filter(email = email)
if len(ups) > 0:
print (len(ups))
print ("User(s) with email {} already exists, aborting user creation!".
format(email))
return None
username = new_user_name()
user = User.objects.create_user(username, email = None, password = None)
user.is_active = True
user.is_staff = False
user.is_superuser = False
# The following fields are fields we store in the UserProfile object instead
# user.first_name
# user.last_name
# user.email
user.save()
up = UserProfile()
up.user = user
up.password_is_set = False
up.magic_login_code = random.randint(100000000, 999999999)
# If the user doesn't specify a name, email is used as the default
if name is None:
up.name = email
else:
up.name = name
up.email = email
up.phone = ''
up.verification_code = new_phone_verification_number()
up.is_verified = False
up.state = 'CA'
up.message_frequency = 3
up.forecast_email = False
up.set_equipment([])
up.beta_test = True
# In the future, we should separate phone-number, etc., into a separate model
up.save()
print ("User {} created.".format(email))
return user
示例2: add_customer
# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import phone [as 别名]
def add_customer(request):
form = RegistrationFormAdmin()
if request.method == "POST":
form = RegistrationFormAdmin(request.POST)
if form.is_valid():
username = generate_username(form.cleaned_data['first_name'],
form.cleaned_data['last_name'],
)
random_password = get_pronounceable_password()
user = User.objects.create_user(
username,
form.cleaned_data['email'],
random_password
)
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.is_active = True
user.save()
userprofile = UserProfile()
userprofile.title = form.cleaned_data['title']
userprofile.date_of_birth = form.cleaned_data['date_of_birth']
userprofile.phone = form.cleaned_data['phone']
userprofile.terms = form.cleaned_data['terms']
userprofile.user = user
userprofile.save()
address = Address()
address.line_1 = form.cleaned_data['line_1']
address.line_2 = form.cleaned_data['line_2']
address.city = form.cleaned_data['city']
address.county = form.cleaned_data['county']
address.postcode = form.cleaned_data['postcode']
address.user = user
address.save()
send_admin_welcome_email(user, random_password)
return HttpResponseRedirect('/admin/accounts/userprofile/')
else:
form = RegistrationFormAdmin(request.POST)
return render_to_response('admin/accounts/add_customer.html',
{'form': form}, context_instance=RequestContext(request))
示例3: login_register
# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import phone [as 别名]
def login_register(request, *args):
next_url = '/'
message = None
if request.GET.has_key('next'):
next_url = request.GET.get('next')
if request.method == 'POST':
if "register" in request.POST:
registration_form = RegistrationForm(request.POST)
if registration_form.is_valid():
username = generate_username(
registration_form.cleaned_data['first_name'],
registration_form.cleaned_data['last_name']
)
user = User.objects.create_user(
username,
registration_form.cleaned_data['email'],
registration_form.cleaned_data['password'],
)
user.first_name = registration_form.cleaned_data['first_name']
user.last_name = registration_form.cleaned_data['last_name']
user.is_active = True
user.save()
user_profile = UserProfile()
user_profile.title = registration_form.cleaned_data['title']
user_profile.date_of_birth = registration_form.cleaned_data['date_of_birth']
user_profile.phone = registration_form.cleaned_data['phone']
user_profile.user = user
user_profile.terms = registration_form.cleaned_data['terms']
user_profile.save()
# Billing address
address = Address()
address.line_1 = registration_form.cleaned_data['line_1']
address.line_2 = registration_form.cleaned_data['line_2']
address.city = registration_form.cleaned_data['city']
address.county = registration_form.cleaned_data['county']
address.postcode = registration_form.cleaned_data['postcode']
address.user = user
address.save()
messages.info(request, "Congratulations, you have successfully registered with Pleasures All Mine.")
send_welcome_email(user_profile.user)
user = authenticate(
username=registration_form.cleaned_data['email'],
password=registration_form.cleaned_data['password']
)
login_after_registration(request, user)
return HttpResponseRedirect(next_url)
else:
registration_form = RegistrationForm(data=request.POST)
messages.warning(request, "Sorry, but you missed something, please fill all required fields.")
if 'login' in request.POST:
login_form = LoginForm(data=request.POST)
if login_form.is_valid():
user = authenticate(username=login_form.cleaned_data['username'],
password=login_form.cleaned_data['password'])
if user is not None:
if not request.POST.get('remember_me', None):
request.session.set_expiry(0)
messages.success(request, "Welcome to Pleasures All Mine, you have successfully logged in.")
return login(request, authentication_form=LoginForm,)
else:
login_form = LoginForm()
registration_form = RegistrationForm()
messages.warning(request, "Sorry, but you missed something, please fill all required fields.")
else:
messages.warning(request, "Sorry, but the username or password you have entered is incorrect, please try again.")
login_form = LoginForm()
registration_form = RegistrationForm()
else:
login_form = LoginForm()
else:
registration_form = RegistrationForm()
login_form = LoginForm()
return render_to_response(
'accounts/login_register.html',
{
'registration_form': registration_form,
'login_form': login_form,
'message': message,
'next_url': next_url,
}, RequestContext(request) )