// 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;
|
}
|
|
}
|