File size: 2,022 Bytes
98aee8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-


import json
from utils import engine

user_data_filepath = r"/home/yangkelang/program/novalConvertProject/data/userData/userData.json"

def save_dict_to_json_file(user, input_dict, file_path=user_data_filepath, mode='r+'):
    with open(file_path, mode) as file:
        data = json.load(file)
        data[user].append(input_dict[1:])
        file.seek(0)
        json.dump(data, file)

# # 调用函数并传入用户名、字典和文件路径
# user = "2024001"
# input_dict = {"key1": "value1", "key2": "value2"}
# save_dict_to_json_file(user, input_dict)





def initialize_json_file(file_path):
    data = {}
    for i in range(2024001, 2024201):
        data[str(i)] = []

    with open(file_path, 'w') as file:
        json.dump(data, file)




# # # 调用初始化函数并传入文件路径
# file_path = "../data/userData/userData.json"
# initialize_json_file(file_path)




def initialize_credentials_json(file_path):
    data = {}
    for i in range(2024001, 2024201):
        data[str(i)] = "password123"

    with open(file_path, 'w') as file:
        json.dump(data, file)



# # 调用初始化函数并传入文件路径
# file_path = "../data/userData/userLogin.json"
# initialize_credentials_json(file_path)

json_path = r'/home/yangkelang/program/novalConvertProject/data/userData/userLogin.json'

def login(user_id, password, json_path=json_path):
    with open(json_path, 'r') as file:
        data = json.load(file)
        if user_id in data and data[user_id] == password:
            with open(r"C:\Users\Administrator\Desktop\PycharmProject\novalConvertProject\data\userData\usingUser.txt", 'w') as file:
                file.write(user_id)#更新目前使用的id
            return True
        else:
            return False



# 调用函数并输出结果
# file_path = "../data/userData/userLogin.json"
#
# result = login("2024001", "password123", file_path)
# print(result)