Exemplo n.º 1
0
    def generate_verify_email_token(self):
        serializer = TJWSerializer(settings.SECRET_KEY, 60 * 60 * 24)

        token = serializer.dumps({'user_id': self.id, 'email': self.email})

        token = token.decode()

        return token
Exemplo n.º 2
0
 def check_set_password_token(access_token):
     """校验重置密码的access_token"""
     serializer = TJWSerializer(settings.SECRET_KEY, 300)
     try:
         data = serializer.loads(access_token)
     except BadData:
         return None
     else:
         return data.get('user_id')
Exemplo n.º 3
0
 def generate_save_qq_token(openid):
     """用于保存qq和美多账号的绑定的access_token"""
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.SAVE_QQ_TOKEN_EXPRIES)
     # serializer.dumps(数据), 返回bytes类型
     token = serializer.dumps({"openid": openid})
     # 生成的token令牌是一个bytes类型的,要进行处理
     token = token.decode()
     return token
Exemplo n.º 4
0
def generate_save_user_token(openid):
    #使用dangerous模块进行签名
    serializer = TJWSerializer(settings.SECRET_KEY, 600)
    print(settings.SECRET_KEY)

    data = {'openid': openid}
    token = serializer.dumps(data)
    token = token.decode()
    return token
Exemplo n.º 5
0
 def generate_verify_email_url(self):
     serializer = TJWSerializer(settings.SECRET_KEY, expires_in=constants.VERIFY_EMAIL_ACTIVE_TIME)
     data = {
         "id": self.id,
         "email": self.email
     }
     token = serializer.dumps(data).decode()
     verify_url = "http://www.meiduo.site:8080/success_verify_email.html?token=" + token
     return verify_url
Exemplo n.º 6
0
 def generate_save_email_url_token(self):
     """生成保存邮箱的验证地址的临时票据[access_token]"""
     # TJWSerializer(秘钥,token有效期[秒])
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.VERIFY_EMAIL_TOKEN_EXPIRES)
     # serializer.dumps(数据), 返回bytes类型
     token = serializer.dumps({'user_id': self.id, "email": self.email})
     # 把bytes转成字符串
     token = token.decode()
     return token
Exemplo n.º 7
0
 def generate_password_token(self):
     """生成重置密码的临时票据[access_token]"""
     # TJWSerializer(秘钥,token有效期[秒])
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.SMS_CODE_TOKEN_EXPIRES)
     # serializer.dumps(数据), 返回bytes类型
     token = serializer.dumps({'user': self.id})
     # 把bytes转成字符串
     token = token.decode()
     return token
Exemplo n.º 8
0
 def generate_sms_code_token(self):
     """生成发送短信的临时票据[access_token]"""
     # TJWSerializer(秘钥,token有效期[秒])
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.SMS_CODE_TOKEN_EXPIRES)
     # serializer.dumps(数据), 返回bytes类型
     token = serializer.dumps({'mobile': self.mobile})
     # 把bytes转成字符串
     token = token.decode()
     return token
Exemplo n.º 9
0
def check_save_user_token(access_token):

    serializer = TJWSerializer(settings.SECRET_KEY, 600)
    try:
        data = serializer.loads(access_token)
    except BadData:
        return None
    else:
        openid = data.get('openid')
        return openid
Exemplo n.º 10
0
 def check_save_qq_token(access_token):
     """检查qq和美多账号的绑定的access_token"""
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.SAVE_QQ_TOKEN_EXPRIES)
     try:
         data = serializer.loads(access_token)
     except BadData:
         return None
     else:
         return data.get('openid')
Exemplo n.º 11
0
 def check_user_token(self, token):
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.LOGIN_QQ_EXPIRY_TIME)
     try:
         data = serializer.loads(token)
     except Exception:
         return None
     else:
         openid = data.get("openid")
         return openid
Exemplo n.º 12
0
 def check_send_sms_code_token(token):
     """
     检验发送短信验证码的token
     :return:
     """
     serializer = TJWSerializer(settings.SECRET_KEY, 300)
     try:
         data = serializer.loads(token)
     except BadData:
         return None
     else:
         return data.get('mobile')
Exemplo n.º 13
0
 def generate_verify_email_url(self):
     """生成邮箱验证的链接"""
     # 获取加密类对象
     serializer = TJWSerializer(settings.SECRET_KEY, expires_in=constants.VERIFY_EMAIL_TOKEN_EXPIRES)
     # 构造需加密的数据
     data = {"user_id": self.id, "email": self.email}
     # 加密数据并赋值保存
     token = serializer.dumps(data).decode()
     # 拼接链接
     verfity_url = 'http://www.meiduo.site:8080/success_verify_email.html?token=' + token
     # 返回链接
     return verfity_url
Exemplo n.º 14
0
    def generate_verify_email_url(self):
        """
        生成验证邮箱的url
        """

        serializer = TJWSerializer(settings.SECRET_KEY,expires_in=constants.VERIFY_EMAIL_TOKEN_EXPIRES)
        data = {'user_id':self.id,'email':self.email}

        token = serializer.dumps(data).decode()

        verify_url = 'http://www.meiduo.site:8080/success_verify_email.html?token=' + token
        return verify_url
Exemplo n.º 15
0
    def generate_send_sms_code_token(self):
        """
        使用itsdangerous生成 发送验证码需要的assecc—token
        生成发送短信验证码的token
        :return:
        """
        # 创建临时令牌的对象
        serializer = TJWSerializer(settings.SECRET_KEY, 300)

        token = serializer.dumps({'mobile': self.mobile})

        token = token.decode()
        return token
Exemplo n.º 16
0
 def verify_email_user(token):
     serializer = TJWSerializer(settings.SECRET_KEY, expires_in=constants.VERIFY_EMAIL_ACTIVE_TIME)
     try:
         user_data = serializer.loads(token)
     except BadData:
         return None
     user_email = user_data.get("email")
     user_id = user_data.get("id")
     try:
         user = User.objects.get(id=user_id, email=user_email)
     except User.DoesNotExist:
         return None
     return user
Exemplo n.º 17
0
    def generate_set_password_token(self):
        """
        使用itsdangerous生成重置密码需要的access_token
        :return:
        """
        # 创建临时令牌的对象
        serializer = TJWSerializer(settings.SECRET_KEY, 300)

        token = serializer.dumps({'user_id': self.id})

        token = token.decode()

        return token
Exemplo n.º 18
0
 def check_verify_email_token(access_token):
     """校验重置密码的access_token"""
     serializer = TJWSerializer(settings.SECRET_KEY, 300)
     try:
         data = serializer.loads(access_token)
     except BadData:
         return None
     else:
         email = data.get('email')
         user_id = data.get('user_id')
         try:
             user = User.objects.get(id=user_id, email=email)
         except User.DoesNotExist:
             return None
         return user
Exemplo n.º 19
0
 def check_set_password_token(token, user_id):
     """
     检验设置密码的token
     """
     serializer = TJWSerializer(settings.SECRET_KEY,
                                expires_in=constants.SMS_CODE_TOKEN_EXPIRES)
     try:
         data = serializer.loads(token)
     except BadData:
         return False
     else:
         if user_id != str(data.get('user')):
             return False
         else:
             return True
Exemplo n.º 20
0
    def check_email(token):
        """验证邮箱"""

        serializer = TJWSerializer(settings.SECRET_KEY, expires_in=constants.VERIFY_EMAIL_TOKEN_EXPIRES)
        # 验证邮箱数据
        try:
            data = serializer.loads(token)
        except BadData:
            return None
        user_id = data.get('user_id')
        email = data.get('email')
        try:
            user = User.objects.get(id=user_id, email=email)
        except User.DoesNotExist:
            return None
        else:
            return user
Exemplo n.º 21
0
 def check_verify_email_token(token):
     """
     检查验证邮件的token
     """
     serializer = TJWSerializer(
         settings.SECRET_KEY,
         expires_in=constants.VERIFY_EMAIL_TOKEN_EXPIRES)
     try:
         data = serializer.loads(token)
     except BadData:  # token过期,或者token被篡改了,都有可能是BadData
         return None
     else:
         email = data.get('email')
         user_id = data.get('user_id')
         try:
             user = User.objects.get(id=user_id, email=email)
         except User.DoesNotExist:
             return None
         else:
             return user
Exemplo n.º 22
0
 def get_return_token(self, openid):
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.LOGIN_QQ_EXPIRY_TIME)
     token = serializer.dumps({"openid": openid})
     token = token.decode()
     return token
Exemplo n.º 23
0
 def check_sms_code_token(access_token):
     """检验发送短信的临时票据[access_token]"""
     serializer = TJWSerializer(settings.SECRET_KEY,
                                constants.SMS_CODE_TOKEN_EXPIRES)
     data = serializer.loads(access_token)
     return data['mobile']