mirror of
https://github.com/capricornxl/ad-password-self-service.git
synced 2025-08-10 05:15:12 +08:00
修复一些BUG
将修改密码的代码逻辑做复用处理,简化代码。
This commit is contained in:
@@ -2,11 +2,56 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import json
|
||||
import random
|
||||
import string
|
||||
import json
|
||||
import six
|
||||
|
||||
from dingtalk.core.utils import to_text
|
||||
from utils.storage import BaseStorage
|
||||
|
||||
|
||||
def to_text(value, encoding='utf-8'):
|
||||
"""Convert value to unicode, default encoding is utf-8
|
||||
|
||||
:param value: Value to be converted
|
||||
:param encoding: Desired encoding
|
||||
"""
|
||||
if not value:
|
||||
return ''
|
||||
if isinstance(value, six.text_type):
|
||||
return value
|
||||
if isinstance(value, six.binary_type):
|
||||
return value.decode(encoding)
|
||||
return six.text_type(value)
|
||||
|
||||
|
||||
def to_binary(value, encoding='utf-8'):
|
||||
"""Convert value to binary string, default encoding is utf-8
|
||||
|
||||
:param value: Value to be converted
|
||||
:param encoding: Desired encoding
|
||||
"""
|
||||
if not value:
|
||||
return b''
|
||||
if isinstance(value, six.binary_type):
|
||||
return value
|
||||
if isinstance(value, six.text_type):
|
||||
return value.encode(encoding)
|
||||
return to_text(value).encode(encoding)
|
||||
|
||||
|
||||
def random_string(length=16):
|
||||
rule = string.ascii_letters + string.digits
|
||||
rand_list = random.sample(rule, length)
|
||||
return ''.join(rand_list)
|
||||
|
||||
|
||||
def byte2int(c):
|
||||
if six.PY2:
|
||||
return ord(c)
|
||||
return c
|
||||
|
||||
|
||||
class KvStorage(BaseStorage):
|
||||
|
||||
def __init__(self, kvdb, prefix='wework'):
|
||||
|
Reference in New Issue
Block a user