Exemplo n.º 1
0
    def check_sms(cls, data):
        '''
        check sms code with mobile and code
        '''
        mobile = data.get('mobile', None)
        if not mobile:
            raise ValidationError({'mobile': ['This field is required.']})

        code = data.get('code', None)
        if not code:
            raise ValidationError({'code': ['This field is required.']})

        res = redis_conn.get(cls.gen_sms_code_key(mobile))
        if res:
            send_code = res
            if send_code and code == send_code:
                sms_token = "".join(
                    random.choice(string.ascii_letters + string.digits)
                    for _ in range(24))
                redis_conn.set(cls.gen_sms_token_key(sms_token),
                               mobile,
                               ex=settings.SMS_LIFESPAN.seconds * 10)
                redis_conn.delete(cls.gen_sms_code_key(mobile))
                return sms_token, int(
                    time.time()) + settings.SMS_LIFESPAN.seconds * 10
        raise ValidationError({'code': ['invalid']})
Exemplo n.º 2
0
 def clear_sms_token(cls, sms_token):
     '''
     清除sms_token
     '''
     redis_conn.delete(cls.gen_sms_token_key(sms_token))
Exemplo n.º 3
0
 def clear_email_token(cls, email_token):
     '''
     清除email_token
     '''
     redis_conn.delete(cls.gen_email_token_key(email_token))