예제 #1
0
 def create_oid(self):
     """
         创建oid
     :return:
     """
     oid = create_random_code(length=10, mode=common_constant.MODE5)
     while self.oid_exists(oid):
         oid = create_random_code(length=10, mode=common_constant.MODE5)
     self.oid = oid
     self.save()
     return oid
예제 #2
0
파일: mixin.py 프로젝트: shihbas/blog-yuehu
 def create_open_code(self):
     """
         创建open_code
     :return:
     """
     open_code = create_random_code(length=10, mode=common_constant.MODE5)
     while self.open_code_exists(open_code):
         open_code = create_random_code(length=10,
                                        mode=common_constant.MODE5)
     self.open_code = open_code
     self.save()
     return open_code
예제 #3
0
파일: usual.py 프로젝트: shihbas/blog-yuehu
    def put(self, request):
        """
            发送admin登录验证码
        :param request:
        :return:
        """

        email = request.data.get("email", None)

        ve = ValidateException()

        right, email = email_rightful(email)
        if not right:
            ve.add_message("email", "except")

        if ve.is_error():
            raise ve

        if not User.objects.filter(username=email, is_superuser=True).exists():
            raise LogicException("Em....")

        email_code = create_random_code(mode=common_constant.MODE5)
        if send_email_html_admin_login(email_code, email):
            email_code = email_code.lower()
            cache.set(
                account_constant.CACHE_ADMIN_LOGIN_PWD_EMAIL_CODE(email=email),
                email_code,
                account_constant.EMAIL_CODE_CACHE_MAX
            )
            return Response({"send": "success"})
        else:
            return Response({"send": "failure"})
예제 #4
0
    def post(self, request):
        email = request.data.get("email", None)
        password1 = request.data.get("password1")
        password2 = request.data.get("password2")

        if account_constant.PWD_MIN_LENGTH > len(
                password1) or account_constant.PWD_MAX_LENGTH < len(password1):
            raise LogicException(
                f"密码长度应大于{account_constant.PWD_MIN_LENGTH}位,小于{account_constant.PWD_MAX_LENGTH}"
            )

        right, email = email_rightful(email)
        if not right:
            raise LogicException("邮箱格式不正确")

        if User.objects.filter(username=email).exists():
            raise LogicException("邮箱已经注册了")

        if password1 != password2:
            raise LogicException("两次密码不一致")

        email_code = create_random_code(length=12, mode=common_constant.MODE5)
        if send_email_register(email_code, email):
            cache.set(
                account_constant.CACHE_REGISTER_EMAIL_CODE(
                    email_code=email_code), {
                        "email": email,
                        "password": password1
                    }, account_constant.EMAIL_CODE_CACHE_MAX)
        else:
            raise LogicException("发送失败!请检查邮箱或联系我!")

        return Response({"register": "success"})
예제 #5
0
파일: utils.py 프로젝트: shihbas/blog-yuehu
def random_password(length=16):
    """
        创建随机密码
    :param length: 随机密码长度
    :return:
    """
    return create_random_code(length=length, mode=common_constant.MODE8)
예제 #6
0
파일: user.py 프로젝트: shihbas/blog-yuehu
    def post(self, request):
        user = request.user
        email = request.data.get("email")

        if user.email:
            raise LogicException("绑定失败:用户已经绑定了邮箱")

        right, email = email_rightful(email)
        if not right:
            raise LogicException("绑定失败:邮箱格式不正确")

        if User.objects.filter(email=email).exists():
            raise LogicException("绑定失败:邮箱已经被注册或绑定了")

        email_code = create_random_code(length=12, mode=common_constant.MODE5)

        if send_email_html_bind_email(email_code, user.display_name, email):
            cache.set(
                account_constant.CACHE_BIND_EMAIL_CODE(email_code=email_code),
                {
                    "email": email,
                    "open_id": user.open_id
                }, account_constant.EMAIL_CODE_CACHE_MAX)
        else:
            raise LogicException("发送邮件失败:请检查邮箱或联系我!")

        return Response({"bind": "success"})