def employee_reset_password_confirmation(request, employee_email, employee_uuid):
"""
This endpoint reset employee with random password and send an email to employee with it.
---
responseMessages:
- code: 404
message: Not found
- code: 406
message: Request not acceptable
"""
if request.method == 'GET':
employee = get_object_or_404(Employee, email=employee_email, reset_password_code=employee_uuid)
random_password = Employee.objects.make_random_password(length=4, allowed_chars='beatrx23456789')
employee.set_password(random_password)
employee.is_password_reset_required = True
employee.save()
# Send confirmation email
subject = config.EMPLOYEE_RESET_PASSWORD_SUCCESSFULLY_SUBJECT
message = config.EMPLOYEE_RESET_PASSWORD_SUCCESSFULLY_MESSAGE % (random_password)
try:
send_email = EmailMessage(subject, message, to=[employee.email])
send_email.send()
except Exception as e:
print(e)
data = "<h1>%s</h1>" % config.EMAIL_SERVICE_ERROR
return Response(data)
data = "<h1>%s</h1>" % config.USER_SUCCESSFULLY_RESET_PASSWORD
return Response(data)
评论列表
文章目录