本文整理汇总了Python中django.contrib.auth.models.BaseUserManager.make_random_password方法的典型用法代码示例。如果您正苦于以下问题:Python BaseUserManager.make_random_password方法的具体用法?Python BaseUserManager.make_random_password怎么用?Python BaseUserManager.make_random_password使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.models.BaseUserManager
的用法示例。
在下文中一共展示了BaseUserManager.make_random_password方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forgot_password_email
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import make_random_password [as 别名]
def forgot_password_email(request):
if request.method == 'POST':
try:
u = User.objects.get(username=request.POST['username'])
userProfile = UserProfile.objects.get(user = u)
except ObjectDoesNotExist:
u = None
if u is not None:
bum = BaseUserManager()
tempPass = bum.make_random_password()
u.set_password(tempPass)
userProfile.hasTempPassword = True
userProfile.save()
u.save()
subject = 'AC3 Forgotten Password Request'
message = 'User: {0}\n You have requested to reset your password\nYour temporary password is: {1}' \
''.format(u.username, tempPass)
EmailMessage(subject, message, to=[u.email]).send(fail_silently=True)
messages.add_message(request, messages.SUCCESS, 'An email has been sent!')
return HttpResponseRedirect('/ac3app/')
else:
messages.add_message(request, messages.ERROR, 'The user {0} could not be found'
.format(request.POST['username']))
return HttpResponseRedirect('/ac3app/')
示例2: handle
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import make_random_password [as 别名]
def handle(self, *args, **options):
fail_list = []
success_list = []
user_manager = BaseUserManager()
data = pd.read_csv(options['csv'])
for index, line in data.iterrows(): # pylint: disable=no-member,unused-variable
received_offer = line['Invited'] == 'YES'
if line["Research Classification"] == "N/A - I do not do research":
jacs = "Y0"
else:
jacs = line["Research Classification"][1:3]
applicants_dict = {
"application_year": 2018,
"fellow": False,
"received_offer": received_offer,
"forenames": line["First name"],
"surname": line["Surname"],
"affiliation": line["Home Institution"],
"department": line["Department"] if pd.notnull(line["Department"]) else "",
"group": line["Group within Department"] if pd.notnull(line["Group within Department"]) else "",
"career_stage_when_apply": line["Career stage"][6],
"job_title_when_apply": line["Job Title"],
"research_area": line["Area of work"],
"research_area_code": jacs,
"email": line["Email Address"],
"phone": line["Telephone number"],
"gender": line["Gender"][0] if pd.notnull(line["Gender"]) else 'R',
"home_country": "GB",
"home_city": "Unknow",
"funding": line["Which primary funding body/charity/organisation would you normally turn to if seeking financial support for your research/work"],
"funding_notes": line["Which additional funding body/charity/organisation would you probably turn to if seeking financial support for your research/work"] if pd.notnull(line["Which additional funding body/charity/organisation would you probably turn to if seeking financial support for your research/work"]) else "",
"claimantship_grant": 3000 if received_offer else 0,
"institutional_website": line["Please specify your Institutional webpage"] if pd.notnull(line["Please specify your Institutional webpage"]) else "",
"website": line["Please specify your blog"] if pd.notnull(line["Please specify your blog"]) else "",
"orcid": line["Please specify your ORCID"] if pd.notnull(line["Please specify your ORCID"]) else "",
"google_scholar": line["Please specify your Google Scholar"] if pd.notnull(line["Please specify your Google Scholar"]) else "",
"twitter": line["Please specify your Twitter handle"] if pd.notnull(line["Please specify your Twitter handle"]) else "",
"screencast_url": line["Application Screencast URL"] if pd.notnull(line["Application Screencast URL"]) else "",
"example_of_writing_url": line["Example of writing"] if pd.notnull(line["Example of writing"]) else "",
}
try:
applicant = Claimant(**applicants_dict)
applicant.save()
success_list.append(index)
if received_offer:
new_user = User.objects.create_user(
username=applicant.slug,
email=applicant.email,
password=user_manager.make_random_password(),
first_name=line["First name"],
last_name=line["Surname"]
)
applicant.user = new_user
applicant.save()
except IntegrityError as exception:
try:
applicant = Claimant.objects.get(
email=applicants_dict["email"]
)
for key, value in applicants_dict.items():
applicant[key] = value
applicant.save()
success_list.append(index)
if received_offer:
new_user = User.objects.create_user(
username=applicant.slug,
email=applicant.email,
password=user_manager.make_random_password(),
first_name=line["First name"],
last_name=line["Surname"]
)
applicant.user = new_user
applicant.save()
except BaseException as exception:
print("Error: {}\n{}\n{}".format(exception, line, 80 * "-"))
fail_list.append(index)
except BaseException as exception:
print("Error: {}\n{}\n{}".format(exception, line, 80 * "-"))
fail_list.append(index)
print(80 * "-")
print("Success: {}".format(success_list))
print("Fail: {}".format(fail_list))
示例3: handle
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import make_random_password [as 别名]
def handle(self, *args, **options):
fail_list = []
success_list = []
user_manager = BaseUserManager()
data = pd.read_csv(options['csv'])
for index, line in data.iterrows(): # pylint: disable=no-member,unused-variable
try:
received_offer = line['Fellow'] == 'Yes'
jacs = line["Research Classification"][1:3]
applicants_dict = {
"application_year": 2017,
"fellow": False,
"received_offer": received_offer,
"forenames": line["First name"],
"surname": line["Surname"],
"affiliation": line["Home institution"],
"department": line["Department"] if pd.notnull(line["Department"]) else "",
"group": line["Group within Department (if any)"] if pd.notnull(line["Group within Department (if any)"]) else "",
"career_stage_when_apply": line["Career stage"][6],
"job_title_when_apply": line["Job Title"],
"research_area": line["Area of work"],
"research_area_code": jacs,
"email": line["Email Address"],
"phone": line["Telephone number"],
"gender": line["Gender"][0] if pd.notnull(line["Gender"]) else 'R',
"home_country": "GB",
"home_city": "Unknow",
"funding": line["Which primary funding body/charity/organisation would you normally turn to if seeking financial support for your research/work?"],
"funding_notes": line["Any additional funders?"] if pd.notnull(line["Any additional funders?"]) else "",
"claimantship_grant": 3000 if received_offer else 0,
"institutional_website": line["Institutional web page"] if pd.notnull(line["Institutional web page"]) else "",
"website": line["Personal web page"] if pd.notnull(line["Personal web page"]) else "",
"orcid": line["ORCID"] if pd.notnull(line["ORCID"]) else "",
"google_scholar": line["Google Scholar"] if pd.notnull(line["Google Scholar"]) else "",
"github": line["GitHub"] if pd.notnull(line["GitHub"]) else "",
"gitlab": line["GitLab"] if pd.notnull(line["GitLab"]) else "",
"twitter": line["Twitter handle"] if pd.notnull(line["Twitter handle"]) else "",
"is_into_training": line["Have training in plans - added by AN"] == "Yes",
"carpentries_instructor": line["Carpentry instructor - added by AN"] == "Yes",
"research_software_engineer": line["RSE - added by AN"] == "Yes",
"screencast_url": line["Application Screencast URL"] if pd.notnull(line["Application Screencast URL"]) else "",
"example_of_writing_url": line["Example of writing"] if pd.notnull(line["Example of writing"]) else "",
}
applicant = Claimant(**applicants_dict)
applicant.save()
success_list.append(index)
if received_offer:
new_user = User.objects.create_user(
username=applicant.slug,
email=applicant.email,
password=user_manager.make_random_password(),
first_name=line["First name"],
last_name=line["Surname"]
)
applicant.user = new_user
applicant.save()
except BaseException as exception:
print("Error: {}\n{}\n{}".format(exception, line, 80 * "-"))
fail_list.append(index)
print(80 * "-")
print("Success: {}".format(success_list))
print("Fail: {}".format(fail_list))
示例4: _generate_cart_id
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import make_random_password [as 别名]
def _generate_cart_id():
user = BaseUserManager()
cart_id = user.make_random_password(50)
return cart_id