views.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:BackendAllStars 作者: belatrix 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号