Esempio n. 1
0
 def clean_password(self):
     pwd = self.cleaned_data['password']
     pwd = encrypt.md5(pwd)
     user = models.UserInfo.objects.get(id=self.request.user.id)
     if pwd != user.password:
         raise ValidationError('原密码错误')
     return encrypt.md5(pwd)
Esempio n. 2
0
    def clean_new_pwd_confirm(self):
        """校验密码"""
        new_pwd = self.cleaned_data['new_pwd']
        new_pwd_confirm = self.cleaned_data['new_pwd_confirm']

        if md5(new_pwd_confirm) != new_pwd:
            raise ValidationError("两次密码不一致")

        return md5(new_pwd_confirm)
Esempio n. 3
0
    def clean_confirmPassWord(self):
        """
        密码确认校验
        """
        password = self.cleaned_data["password"]
        confirmPassWord = encrypt.md5(self.cleaned_data["confirmPassWord"])

        if password != confirmPassWord:
            raise ValidationError("两次密码不一致")
        return encrypt.md5(confirmPassWord)
Esempio n. 4
0
 def clean_confirm_password(self):
     try:
         print(self.cleaned_data)
         password = self.cleaned_data['password']
         confirm_password = encrypt.md5(
             self.cleaned_data['confirm_password'])
         if password != confirm_password:
             raise ValidationError('两次密码不一致')
     except KeyError as e:
         raise ValidationError('密码不符合要求')
     return encrypt.md5(confirm_password)
Esempio n. 5
0
 def __init__(self,
              url,
              charset=None,
              data=None,
              headers=None,
              timeout=3,
              retry_times=30,
              retry_delta=3,
              http_proxy=None,
              force=False):
     '''
         url   目标url
         charset   编码
         data   post的数据,字符串
         headers  自定义请求头,dict
         timeout  超时时间,int,  比如:3
         retry_times 重试次数,int,比如3
         retry_delta   重试间隔,int
         http_proxy         代理ip, 比如 192.168.1.1:3128  ,也可以是一个函数 lambda :"192.168.1.1:3128"
         force         强制爬取,而不管有没有爬取过.
     '''
     self.url = url
     self.data = data
     self.timeout = timeout
     self.retry_times = retry_times
     self.retry_delta = retry_delta
     self.charset = charset
     self.headers = headers
     self.http_proxy = http_proxy
     if not Spider._url_buff:
         Spider._url_buff = [BloomFilter(1000000)]
     global _queue
     if data:
         _hash = md5(url) + md5(data)
     else:
         _hash = md5(url)
     if not force:
         try:
             for bloomfilter in Spider._url_buff:
                 assert _hash not in bloomfilter
         except:
             pass
         else:
             try:
                 Spider._url_buff[-1].add(_hash)
             except:
                 Spider._url_buff.append(
                     BloomFilter(Spider._url_buff[-1].capacity + 1000000))
                 Spider._url_buff[-1].add(_hash)
             _queue.put_priority(self.__dict__, 0)
     else:
         _queue.put_priority(self.__dict__, 0)
Esempio n. 6
0
 def clean_password(self):
     # 密码长度限制
     password = self.cleaned_data['password']
     if len(password.strip()) < 6 or len(password.strip()) > 18:
         raise ValidationError('密码长度要在6~18位之间')
     # 加密,返回
     return encrypt.md5(password)
Esempio n. 7
0
 def add_user(self, name, pwd):
     """添加用户"""
     return self.db_session.insert_one(
         tables.USER, **{
             'company_no': name.upper(),
             'password': md5(pwd)
         })
Esempio n. 8
0
    def post(self, *args, **kwargs):
        user_name = self.get_body_argument('userName')  #彭修改过
        password = self.get_body_argument('userPwd')  #彭修改过

        # 查询数据库
        database_util = Db_Util()
        params = {
            'user_name': user_name,
            'user_pwd': md5(password)
        }  #彭修改过,查询数据库用户信息
        #key的值要和数据库中的字段一样
        result = database_util.find_user(**params)
        if result:  #如果为True执行以下代码
            self.session_obj['is_login'] = 1  # 1登录0未登录
            self.session_obj['user'] = user_name
            # -------------------------------------------------------------------------------------------
            ret = {
                "result": 'ok',
                'user': self.session_obj['user'],
                'status': True,
                'code': 200
            }
        else:
            ret = {"result": 'fail', 'status': True, 'code': 200}

        self.write(json_encode(ret))
        database_util.close_conn()
Esempio n. 9
0
    def clean_confirm_password(self):
        password = self.cleaned_data.get('password')
        confirm_password = encrypt.md5(self.cleaned_data['confirm_password'])
        if password != confirm_password:
            raise ValidationError('两次密码不一致')

        return confirm_password
Esempio n. 10
0
 def clean_re_password(self):
     # 此处获取到的是MD5加密以后的password,使用get获取避免出错
     password = self.cleaned_data.get('password')
     re_password = md5(self.cleaned_data['re_password'])
     if password != re_password:
         raise ValidationError('两次密码不一致')
     return re_password
Esempio n. 11
0
 def clean_pwds(self):
     #判断两次密码是否一致
     pwd = self.cleaned_data.get('pwd')
     pwds = encrypt.md5(self.cleaned_data['pwds'])
     if pwd !=pwds:
         raise ValidationError('两次密码不一致')
     return pwds
Esempio n. 12
0
 def clean_confirm_password(self):
     pwd = self.cleaned_data['password']
     confirm_pwd = self.cleaned_data['confirm_password']
     confirm_pwd = encrypt.md5(confirm_pwd)
     if pwd != confirm_pwd:
         raise ValidationError('密码不相同')
     return confirm_pwd
Esempio n. 13
0
 def __init__(self,
              url,
              charset=None,
              headers=None,
              response_handle=None,
              timeout=3,
              retry_times=30,
              load_wait=None,
              execute_js=None,
              execute_js_wait=None,
              retry_delta=3,
              http_proxy_url=None,
              force=False):
     '''
         url   目标url
         charset   编码
         data   post的数据,字符串
         headers  自定义请求头,dict
         response_handle 采集结果处理函数
         timeout  超时时间,int,  比如:3
         retry_times 重试次数,int,比如3
         load_wait  加载页面后等待时间,秒.
         execute_js  加载页面完成后执行的js
         execute_js_waite 执行js之后等待的时间
         retry_delta   如果出错,重试间隔,秒,int
         http_proxy_url         代理ip,  "http://192.168.1.1:80"
         force         强制爬取,而不管有没有爬取过.
     '''
     if not PhantomjsSpider._url_buff:
         PhantomjsSpider._url_buff = [BloomFilter(1000000)]
     global _queue
     _hash = md5(url)
     self.url = url
     self.timeout = timeout
     self.retry_times = retry_times
     self.retry_delta = retry_delta
     self.response_handle = response_handle
     self.charset = charset
     self.headers = headers
     self.execute_js = execute_js
     self.execute_js_wait = execute_js_wait
     self.load_wait = load_wait
     self.proxy = http_proxy_url
     if not force:
         try:
             for bloomfilter in PhantomjsSpider._url_buff:
                 assert _hash not in bloomfilter
         except:
             pass
         else:
             try:
                 PhantomjsSpider._url_buff[-1].add(_hash)
             except:
                 PhantomjsSpider._url_buff.append(
                     BloomFilter(PhantomjsSpider._url_buff[-1].capacity +
                                 1000000))
                 PhantomjsSpider._url_buff[-1].add(_hash)
             _queue.put(self._go)
     else:
         _queue.put(self._go)
Esempio n. 14
0
 def clean_confirm_password(self):
     """校验两次输入的密码是否一致"""
     pwd = self.cleaned_data['password']  # pwd是已加密的
     re_pwd = encrypt.md5(self.cleaned_data['confirm_password'])
     if pwd != re_pwd:
         raise ValidationError('两次密码不一致')
     return re_pwd
Esempio n. 15
0
 def clean_password_2(self):
     """cleaned_data: 已校验的字段"""
     password = self.cleaned_data["password"]
     password2 = encrypt.md5(self.cleaned_data["password_2"])
     if password != password2:
         raise ValidationError("两次密码不一致")
     return password2
Esempio n. 16
0
    def clean_password(self):
        """
        确认密码并加密
        """
        password = self.cleaned_data["password"]

        return encrypt.md5(password)
Esempio n. 17
0
def register(request):
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, "register2.html", {"form":form})
    # 将数据传给ModelForm做校验
    form = RegisterModelForm(data=request.POST)
    ret = {"status":True,"msg":"注册成功"}
    if form.is_valid():
        # 验证成功  保存用户信息到数据库
        form.instance.password = md5(form.cleaned_data['password'])
        # 在用户表中新建一条数据
        instance = form.save() # 将数据保存到数据库,会自动剔除没用的字段
        # 创建交易记录
        policy_obj = models.PricePolicy.objects.filter(category=1,title="个人免费版").first()
        models.Transaction.objects.create(
            status=2,
            order=str(uuid.uuid4()),
            user=instance,
            price_policy=policy_obj,
            count=0,
            price=0,
            start_datetime=datetime.datetime.now()
        )
        ret["data"] = "/crm/login/sms/"
    else:
        ret["status"] = False
        ret["msg"] = "注册失败"
        ret["error"] = form.errors
    return JsonResponse(ret)
Esempio n. 18
0
 def clean_confirm_password(self):
     pwd=self.cleaned_data.get('password') #因为先校验的password字段,所以这里也是取到的密文
     if not pwd:
         raise ValidationError('密码不合规范')
     confirm_pwd=encrypt.md5(self.cleaned_data['confirm_password']) #所以这里也要将重复密码加密并进行比较
     if pwd != confirm_pwd:
         raise ValidationError('两次密码不一致')
     return confirm_pwd
Esempio n. 19
0
    def clean_confirm_password(self):
        # 在清洗一个字段时,如果要拿另一个字段,使用get避免获取不到这个key的问题
        pwd = self.cleaned_data.get('password')
        confirm_pwd = md5(self.cleaned_data['confirm_password'])
        if pwd != confirm_pwd:
            raise ValidationError("两次密码不一致")

        return confirm_pwd
Esempio n. 20
0
 def clean_new_confirm_password(self):
     new_password = self.cleaned_data['new_password']
     new_confirm_password = self.cleaned_data['new_confirm_password']
     # 重复密码也需要加密处理
     cpwd = encrypt.md5(new_confirm_password)
     if new_password != cpwd:
         raise ValidationError('两次密码输入不一致')
     return new_confirm_password
Esempio n. 21
0
 def clean_confirm_password(self):
     password = self.cleaned_data['password']
     confirm_password = self.cleaned_data['confirm_password']
     # 重复密码也需要加密处理
     cpwd = encrypt.md5(confirm_password)
     if password != cpwd:
         raise ValidationError('两次密码输入不一致')
     return confirm_password
Esempio n. 22
0
    def clean_confirm_password(self):
        """校验密码"""
        confirm_password = self.cleaned_data['confirm_password']
        password = self.cleaned_data['password']

        if md5(confirm_password) != password:
            raise ValidationError("两次密码不一致")

        return confirm_password
Esempio n. 23
0
 def clean_confirm_password(self):
     pwd = self.cleaned_data['new_password']
     confirm_pwd = self.cleaned_data['confirm_password']
     confirm_pwd = encrypt.md5(confirm_pwd)
     if pwd != confirm_pwd:
         raise ValidationError('新密码不相同')
     user = models.UserInfo.objects.get(id=self.request.user.id)
     if pwd == user.password:
         raise ValidationError('和原密码相同')
     return confirm_pwd
Esempio n. 24
0
    def clean_password(self):
        pwd = self.cleaned_data['password']
        # 密码加密
        pwd = encrypt.md5(pwd)
        user_pwd = self.request.tracer.user.password
        # 验证原密码是否输入正确
        if pwd != user_pwd:
            raise ValidationError('原密码错误!')

        return pwd
Esempio n. 25
0
 def clean_confirm_password(self):
     """
     获取用户输入的两次密码
     :return:
     """
     pwd = self.cleaned_data.get('password')
     confirm_pwd = encrypt.md5(self.cleaned_data['confirm_password'])
     if pwd != confirm_pwd:
         raise ValidationError("两次密码不一致")
     return confirm_pwd
Esempio n. 26
0
 def clean_confirm_password(self):
     """
     confirm_password 的钩子函数
     :return: confirm_password重复密码
     """
     password = self.cleaned_data.get('password')
     confirm_password = self.cleaned_data.get('confirm_password')
     if password != encrypt.md5(confirm_password):
         raise ValidationError('两次输入密码不一致')
     else:
         return confirm_password
Esempio n. 27
0
    def clean_confirm_password(self):
        # 密码钩子
        password = self.cleaned_data['password']
        confirm_password = self.cleaned_data['confirm_password']

        # 重复密码加密用于校验
        confirm_password = encrypt.md5(confirm_password)

        if password != confirm_password:
            raise ValidationError("两次密码不一致")

        return confirm_password
Esempio n. 28
0
 def save_user(self, **kwargs):
     user_id = uuid.uuid1()
     name = kwargs.get('user_name')
     pwd = kwargs.get('user_pwd')
     email = kwargs.get('user_email')
     params = (str(user_id), name, md5(pwd), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), email)
     print(params)
     sql_str = 'insert into ' \
               'user_info(user_id,user_name,user_pwd,user_create_time,user_email) ' \
               'VALUES (%s,%s,%s,%s,%s)'
     result = self.cursor.execute(sql_str, params)
     return result
Esempio n. 29
0
def url_shorten(url, key):
    url = str(url)
    from utils import encrypt
    import random
    random.seed()
    seq = random.randint(0, 3)
    text = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    md5text = encrypt.md5(key + url)
    short_url = md5text[seq * 8:(seq + 1) * 8]
    ret = []
    num_url = int(short_url, 16)
    for i in range(0, 6):
        ret.append(text[num_url & 0x3FFFFFFF & 0x0000003D])
        num_url >>= 5
    return "".join(ret)
Esempio n. 30
0
def url_shorten(url, key):
    url = str(url)
    from utils import encrypt
    import random
    random.seed()
    seq = random.randint(0, 3)
    text = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    md5text = encrypt.md5(key + url)
    short_url = md5text[seq * 8:(seq + 1) * 8]
    ret = []
    num_url = int(short_url, 16)
    for i in range(0, 6):
        ret.append(text[num_url & 0x3FFFFFFF & 0x0000003D])
        num_url >>= 5
    return "".join(ret)
Esempio n. 31
0
def test():
    password = encrypt.md5("123")
    user = models.UserInfo.objects.create(
        username="******",
        password=password,
        mail="*****@*****.**",
        mobilePhone="17371246916",
    )
    policy_obj = models.PricePolicy.objects.filter(
        category=1, title="个人免费版"
    ).first()
    models.Transaction.objects.create(
        status=2,
        order=str(uuid.uuid4()),
        user=user,
        price_policy=policy_obj,
        count=0,
        price=0,
        start_datetime=arrow.now().format(),
    )
    print("初始化测试用户成功")