Пример #1
0
    def update_data():
        if 'whereStr' in req.form:
            str_where = req.form['whereStr']
            if not str_where:
                return make_response('whereStr错误')
        else:
            return make_response('whereStr错误')

        if 'updateJson' in req.form:
            try:
                dict_update = json.loads(req.form['updateJson'])
                if len(dict_update) == 0:
                    return make_response('updateJson错误')
                if 'id' in dict_update or 'username' in dict_update:
                    return make_response('updateJson错误')
            except:
                return make_response('updateJson错误')
        else:
            return make_response('updateJson错误')

        if 'password' in dict_update:
            if len(dict_update['password']) < 6:
                return make_response('密码长度不能小于6')
            else:
                password = "******" + dict_update['password'] + dict_update[
                    'password'][0:3]
                md5 = hashlib.md5()
                md5.update(password.encode(encoding='utf-8'))
                md5_password = md5.hexdigest()
                dict_update['password'] = md5_password
        else:
            pass

        dict_update['update_name'] = dict_login['username']
        dict_update['update_time'] = time.strftime("%Y-%m-%d %H:%M:%S",
                                                   time.localtime())

        result = mysqldb.update_data(table_name, str_where, dict_update)
        # print(result)

        if result:
            # 操作记录
            content = 'whereStr=' + re.sub(
                r'\"', "'", str_where) + '&updateJson=' + re.sub(
                    r'\"', "'", json.dumps(dict_update, ensure_ascii=False))
            dict_record = {
                'username': dict_login['username'],
                'dbName': table_name,
                'action': '修改',
                'content': content,
                'os': dict_login['os'],
                'px': dict_login['px'],
                'ip': req.remote_addr,
                'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            }
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
Пример #2
0
    def update_data():
        if 'whereStr' in req.form:
            str_where = req.form['whereStr']
            if not str_where:
                return make_response('whereStr错误')
        else:
            return make_response('whereStr错误')

        if 'updateJson' in req.form:
            try:
                dict_update = json.loads(req.form['updateJson'])
                if len(dict_update) == 0:
                    return make_response('updateJson错误')
            except:
                return make_response('updateJson错误')
        else:
            return make_response('updateJson错误')

        dict_update['update_name'] = dict_login['username']
        dict_update['update_time'] = time.strftime("%Y-%m-%d %H:%M:%S",
                                                   time.localtime())

        result = mysqldb.update_data(table_name, str_where, dict_update)
        # print(result)

        if result:
            return make_response('操作成功')
        else:
            return make_response('操作失败')
Пример #3
0
    def update_data(self):
        if 'whereStr' in self.req.form:
            str_where = self.req.form['whereStr']
            if not str_where:
                return make_response('whereStr错误')
        else:
            return make_response('whereStr错误')

        if 'updateJson' in self.req.form:
            try:
                dict_update = json.loads(self.req.form['updateJson'])
                if len(dict_update) == 0:
                    return make_response('updateJson错误')
                if 'id' in dict_update:
                    return make_response('updateJson错误')
            except:
                return make_response('updateJson错误')
        else:
            return make_response('updateJson错误')

        dict_update['update_name'] = self.dict_login['username']
        dict_update['update_time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        result = mysqldb.update_data(self.table_name, str_where, dict_update)
        # print(result)

        if result:
            # 操作记录
            content = 'whereStr=' + re.sub(r'\"', "'", str_where) + '&updateJson=' + re.sub(r'\"', "'", json.dumps(dict_update, ensure_ascii=False))
            dict_record = {'username': self.dict_login['username'], 'dbName': self.table_name, 'action': '修改', 'content': content, 'os': self.dict_login['os'], 'px': self.dict_login['px'], 'ip': self.req.remote_addr, 'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
Пример #4
0
    def update_data_fn(self, str_where, dict_update):
        result = mysqldb.update_data(self.table_name, str_where, dict_update)
        # print(result)
        if result:
            # 操作记录
            content = 'whereStr=' + re.sub(r'\"', "'", str_where) + '&updateJson=' + re.sub(r'\"', "'",
                                                                                            json.dumps(dict_update,
                                                                                                       ensure_ascii=False))
            dict_record = {'username': self.dict_login['username'], 'dbName': self.table_name, 'action': '修改', 'content': content,
                           'os': self.dict_login['os'], 'px': self.dict_login['px'], 'ip': self.req.remote_addr,
                           'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')
Пример #5
0
    def update_data(self):
        if 'whereJson' in self.req.form:
            try:
                dict_where = json.loads(self.req.form['whereJson'])
            except:
                return make_response('whereJson错误')
        else:
            return make_response('whereJson错误')

        if 'updateJson' in self.req.form:
            try:
                dict_update = json.loads(self.req.form['updateJson'])
                if len(dict_update) == 0:
                    return make_response('updateJson错误')
            except:
                return make_response('updateJson错误')
        else:
            return make_response('updateJson错误')

        if 'username' not in dict_where:
            return make_response('whereJson错误')
        else:
            pass

        dict_login = json.loads(self.req.cookies['logining'])
        if dict_where['username'] != dict_login['username']:
            return make_response('没有权限')
        else:
            pass

        if len(dict_update['password']) >= 6:
            password = "******" + dict_update['password'] + dict_update[
                'password'][0:3]
            md5 = hashlib.md5()
            md5.update(password.encode(encoding='utf-8'))
            md5_password = md5.hexdigest()
            dict_update['password'] = md5_password
        else:
            return make_response('密码不能为空')

        str_where = 'username="******"'
        dict_update['update_name'] = dict_login['username']
        dict_update['update_time'] = time.strftime("%Y-%m-%d %H:%M:%S",
                                                   time.localtime())

        result = mysqldb.update_data(self.table_name, str_where, dict_update)
        # print(result)

        if result:

            # 操作记录
            content = 'change password'
            dict_record = {
                'username': dict_login['username'],
                'dbName': self.table_name,
                'action': '修改',
                'content': content,
                'os': dict_login['os'],
                'px': dict_login['px'],
                'ip': self.req.remote_addr,
                'time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            }
            mysqldb.set_record(dict_record)

            return make_response('操作成功')
        else:
            return make_response('操作失败')