admin
2023-03-07 8b06b1cbf112d55307ea8a6efe711db4e7506d89
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// loginDlg.cpp: 实现文件
//
 
#include "pch.h"
#include "app.h"
#include "loginDlg.h"
#include "appDlg.h"
#include "afxdialogex.h"
#include <fstream>
#ifndef _TOOL_H
#define _TOOL_H 1
#include "tool.h"
#endif // !_TOOL_H
 
#ifndef _COMMON_H
#define _COMMON_H 1
#include "common.h"
#endif // !_TOOL_H
 
#include "JsonUtil.h"
 
 
 
 
// loginDlg 对话框
 
IMPLEMENT_DYNAMIC(loginDlg, CDialogEx)
 
loginDlg::loginDlg(CWnd* pParent)
    : CDialogEx(IDD_LOGIN, pParent)
{
}
 
void loginDlg::setReLogin(bool relogin)
{
    this->reLogin = relogin;
}
 
 
loginDlg::~loginDlg()
{
}
 
void saveUserInfo(string account, string pwd,bool autoLogin) {
    ofstream ofs;
    ofs.open("user.txt", ios::trunc);
    ofs << account << "\n" << pwd<<"\n"<< autoLogin;
    ofs.close();
}
 
list<string> readUserInfo() {
    list<string> mList;
    try {
        ifstream  ifs;
        ifs.open("user.txt", ios::in);
        char buf[1024] = { 0 };
        while (ifs.getline(buf, sizeof(buf))) {
            cout << buf << endl;
            mList.push_back(string(buf));
        }
    }
    catch (...) {
    }
    return mList;
}
 
void loginDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT_HOST, editHost);
    DDX_Control(pDX, IDC_EDIT_ACCOUNT, editAccount);
    DDX_Control(pDX, IDC_EDIT_PWD, editPwd);
    DDX_Control(pDX, IDC_CHECK_AUTO_LOGIN, autoLoginCheck);
 
    editHost.SetWindowTextW(TEXT("192.168.3.252"));
    list<string> resultList = readUserInfo();
    if (resultList.size() >= 2) {
        list<string>::iterator ele = resultList.begin();
        CString account((*ele).c_str());
        editAccount.SetWindowTextW(account);
        ++ele;
        CString pwd((*ele).c_str());
        editPwd.SetWindowTextW(pwd);
 
        if (resultList.size() >= 3) {
            ++ele;
            string autoLogin = (*ele);
            if (autoLogin == "1") {
                autoLoginCheck.SetCheck(TRUE);
            }
            else {
                autoLoginCheck.SetCheck(FALSE);
            }
        }
    }
 
    if (!reLogin && autoLoginCheck.GetCheck()) {
        startLogin();
    }
}
 
 
BEGIN_MESSAGE_MAP(loginDlg, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON_LOGIN, &loginDlg::OnBnClickedButtonLogin)
END_MESSAGE_MAP()
 
 
 
 
// loginDlg 消息处理程序
void loginDlg::OnBnClickedButtonLogin()
{
    startLogin();
}
 
 
void loginDlg::startLogin()
{
    CString host;
    editHost.GetWindowText(host);
    CString account;
    editAccount.GetWindowText(account);
    CString pwd;
    editPwd.GetWindowText(pwd);
 
 
    string host_str = Tool::cstring2String(host);
    string account_str = Tool::cstring2String(account);
    string pwd_str = Tool::cstring2String(pwd);
 
 
 
    SocketManager::ADDR = host_str;
 
    string data = JsonUtil::loadLoginData(account_str, pwd_str);
 
    try {
        string result = SocketManager::sendMsg(data.c_str());
        Json::Value resultJson = JsonUtil::parseJson(result);
        if (resultJson["code"].asInt() != 0) {
            Json::FastWriter fastWriter;
            std::string msg_str = fastWriter.write(resultJson["msg"]);
            cout << msg_str << endl;
            CString msg;
            Tool::UnicodeToChinese(msg_str, msg);
            AfxMessageBox(msg);
            return;
        }
        saveUserInfo(account_str, pwd_str, autoLoginCheck.GetCheck());
        //客户端编号
        CappDlg::clientNum = resultJson["data"]["client"].asInt();
 
        //解析权限参数
        Json::Value authoritys = resultJson["data"]["authoritys"];
        authoritys.size();
        set<Authority> alist;
        for (int i = 0;i < authoritys.size();i++) {
            string authority = authoritys[i].asString();
            if (authority._Equal("l2")) {
                alist.insert(AUTHORITY_L2);
            }
            else if (authority._Equal("limit_up")) {
                alist.insert(AUTHORITY_LIMIT_UP);
            }
            else if (authority._Equal("industry")) {
                alist.insert(AUTHORITY_THS_INDUSTRY);
            }
            else if (authority._Equal("trade_success")) {
                alist.insert(AUTHORITY_TRADE_SUCCESS);
            }
            else if (authority._Equal("trade_delegate")) {
                alist.insert(AUTHORITY_TRADE_DELEGATE);
            }
            else if (authority._Equal("code_upload")) {
                alist.insert(AUTHORITY_UPLOAD_CODE);
            }
            else if (authority._Equal("trade_queue")) {
                alist.insert(AUTHORITY_TRADE_QUEUE);
            }
        }
        //赋值权限
        CappDlg::authoritySet = alist;
        CappDlg dlg(this);
        dlg.DoModal();
    }
    catch (string st) {
        CString msg(st.c_str());
        AfxMessageBox(msg);
        return;
    }
    catch (...) {
        AfxMessageBox(_T("未知错误"));
        return;
    }
 
}